mirror of
https://github.com/Siccity/xNode.git
synced 2026-03-26 22:49:02 +08:00
Formatting
This commit is contained in:
parent
43ea56fb29
commit
a6c80aaaab
@ -377,8 +377,7 @@ namespace XNode {
|
|||||||
public void OnAfterDeserialize() {
|
public void OnAfterDeserialize() {
|
||||||
this.Clear();
|
this.Clear();
|
||||||
|
|
||||||
if (keys.Count != values.Count)
|
if (keys.Count != values.Count) {
|
||||||
{
|
|
||||||
var msg = string.Format(
|
var msg = string.Format(
|
||||||
XNodeRuntimeConstants.MISMATCHED_KEYS_TO_VALUES_EXCEPTION_MESSAGE,
|
XNodeRuntimeConstants.MISMATCHED_KEYS_TO_VALUES_EXCEPTION_MESSAGE,
|
||||||
keys.Count,
|
keys.Count,
|
||||||
@ -391,4 +390,4 @@ namespace XNode {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -68,14 +68,14 @@ namespace XNode {
|
|||||||
ports.Add(staticPort.fieldName, port);
|
ports.Add(staticPort.fieldName, port);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finally, make sure dynamic list port settings correspond to the settings of their "backing port"
|
// Finally, make sure dynamic list port settings correspond to the settings of their "backing port"
|
||||||
foreach (NodePort listPort in dynamicListPorts) {
|
foreach (NodePort listPort in dynamicListPorts) {
|
||||||
// At this point we know that ports here are dynamic list ports
|
// At this point we know that ports here are dynamic list ports
|
||||||
// which have passed name/"backing port" checks, ergo we can proceed more safely.
|
// which have passed name/"backing port" checks, ergo we can proceed more safely.
|
||||||
string backingPortName = listPort.fieldName.Split(' ')[0];
|
string backingPortName = listPort.fieldName.Split(' ') [0];
|
||||||
NodePort backingPort = staticPorts[backingPortName];
|
NodePort backingPort = staticPorts[backingPortName];
|
||||||
|
|
||||||
// Update port constraints. Creating a new port instead will break the editor, mandating the need for setters.
|
// Update port constraints. Creating a new port instead will break the editor, mandating the need for setters.
|
||||||
listPort.ValueType = GetBackingValueType(backingPort.ValueType);
|
listPort.ValueType = GetBackingValueType(backingPort.ValueType);
|
||||||
listPort.direction = backingPort.direction;
|
listPort.direction = backingPort.direction;
|
||||||
@ -94,7 +94,7 @@ namespace XNode {
|
|||||||
return portValType.GetElementType();
|
return portValType.GetElementType();
|
||||||
}
|
}
|
||||||
if (portValType.IsGenericType && portValType.GetGenericTypeDefinition() == typeof(List<>)) {
|
if (portValType.IsGenericType && portValType.GetGenericTypeDefinition() == typeof(List<>)) {
|
||||||
return portValType.GetGenericArguments()[0];
|
return portValType.GetGenericArguments() [0];
|
||||||
}
|
}
|
||||||
return portValType;
|
return portValType;
|
||||||
}
|
}
|
||||||
@ -106,19 +106,19 @@ namespace XNode {
|
|||||||
// Thus, we need to check for attributes... (but at least we don't need to look at all fields this time)
|
// Thus, we need to check for attributes... (but at least we don't need to look at all fields this time)
|
||||||
string[] fieldNameParts = port.fieldName.Split(' ');
|
string[] fieldNameParts = port.fieldName.Split(' ');
|
||||||
if (fieldNameParts.Length != 2) return false;
|
if (fieldNameParts.Length != 2) return false;
|
||||||
|
|
||||||
FieldInfo backingPortInfo = port.node.GetType().GetField(fieldNameParts[0]);
|
FieldInfo backingPortInfo = port.node.GetType().GetField(fieldNameParts[0]);
|
||||||
if (backingPortInfo == null) return false;
|
if (backingPortInfo == null) return false;
|
||||||
|
|
||||||
object[] attribs = backingPortInfo.GetCustomAttributes(true);
|
object[] attribs = backingPortInfo.GetCustomAttributes(true);
|
||||||
return attribs.Any(x => {
|
return attribs.Any(x => {
|
||||||
Node.InputAttribute inputAttribute = x as Node.InputAttribute;
|
Node.InputAttribute inputAttribute = x as Node.InputAttribute;
|
||||||
Node.OutputAttribute outputAttribute = x as Node.OutputAttribute;
|
Node.OutputAttribute outputAttribute = x as Node.OutputAttribute;
|
||||||
return inputAttribute != null && inputAttribute.dynamicPortList ||
|
return inputAttribute != null && inputAttribute.dynamicPortList ||
|
||||||
outputAttribute != null && outputAttribute.dynamicPortList;
|
outputAttribute != null && outputAttribute.dynamicPortList;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> Cache node types </summary>
|
/// <summary> Cache node types </summary>
|
||||||
private static void BuildCache() {
|
private static void BuildCache() {
|
||||||
portDataCache = new PortDataCache();
|
portDataCache = new PortDataCache();
|
||||||
@ -127,12 +127,10 @@ namespace XNode {
|
|||||||
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
|
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
|
||||||
|
|
||||||
// Loop through assemblies and add node types to list
|
// Loop through assemblies and add node types to list
|
||||||
foreach (Assembly assembly in assemblies)
|
foreach (Assembly assembly in assemblies) {
|
||||||
{
|
|
||||||
// Skip certain dlls to improve performance
|
// Skip certain dlls to improve performance
|
||||||
string assemblyName = assembly.GetName().Name;
|
string assemblyName = assembly.GetName().Name;
|
||||||
if (!XNodeRuntimeConstants.IGNORE_ASSEMBLY_PREFIXES.Any(x => assemblyName.StartsWith(x)))
|
if (!XNodeRuntimeConstants.IGNORE_ASSEMBLY_PREFIXES.Any(x => assemblyName.StartsWith(x))) {
|
||||||
{
|
|
||||||
IEnumerable<Type> foundNodeTypes = assembly.GetTypes()
|
IEnumerable<Type> foundNodeTypes = assembly.GetTypes()
|
||||||
.Where(t => !t.IsAbstract && baseType.IsAssignableFrom(t));
|
.Where(t => !t.IsAbstract && baseType.IsAssignableFrom(t));
|
||||||
nodeTypes.AddRange(foundNodeTypes);
|
nodeTypes.AddRange(foundNodeTypes);
|
||||||
@ -194,8 +192,7 @@ namespace XNode {
|
|||||||
public void OnAfterDeserialize() {
|
public void OnAfterDeserialize() {
|
||||||
this.Clear();
|
this.Clear();
|
||||||
|
|
||||||
if (keys.Count != values.Count)
|
if (keys.Count != values.Count) {
|
||||||
{
|
|
||||||
var msg = string.Format(
|
var msg = string.Format(
|
||||||
XNodeRuntimeConstants.MISMATCHED_KEYS_TO_VALUES_EXCEPTION_MESSAGE,
|
XNodeRuntimeConstants.MISMATCHED_KEYS_TO_VALUES_EXCEPTION_MESSAGE,
|
||||||
keys.Count,
|
keys.Count,
|
||||||
@ -208,4 +205,4 @@ namespace XNode {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,22 +1,19 @@
|
|||||||
namespace XNode
|
namespace XNode {
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A helper class containing shared constants.
|
/// A helper class containing shared constants.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class XNodeRuntimeConstants
|
public static class XNodeRuntimeConstants {
|
||||||
{
|
|
||||||
// Exceptions
|
// Exceptions
|
||||||
public const string MISMATCHED_KEYS_TO_VALUES_EXCEPTION_MESSAGE =
|
public const string MISMATCHED_KEYS_TO_VALUES_EXCEPTION_MESSAGE =
|
||||||
"There are {0} keys and {1} values after deserialization. " +
|
"There are {0} keys and {1} values after deserialization. " +
|
||||||
"Make sure that both key and value types are serializable.";
|
"Make sure that both key and value types are serializable.";
|
||||||
|
|
||||||
// Reflection
|
// Reflection
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A collection of assembly prefixes that should not be reflected for derived node types.
|
/// A collection of assembly prefixes that should not be reflected for derived node types.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static string[] IGNORE_ASSEMBLY_PREFIXES =
|
public static string[] IGNORE_ASSEMBLY_PREFIXES = {
|
||||||
{
|
|
||||||
"ExCSS",
|
"ExCSS",
|
||||||
"Microsoft",
|
"Microsoft",
|
||||||
"Mono",
|
"Mono",
|
||||||
@ -28,5 +25,5 @@ namespace XNode
|
|||||||
"UnityEditor",
|
"UnityEditor",
|
||||||
"UnityEngine"
|
"UnityEngine"
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user