diff --git a/Scripts/Attributes/NodeEnum.cs b/Scripts/Attributes/NodeEnum.cs index 9cdaef4..8de61ca 100644 --- a/Scripts/Attributes/NodeEnum.cs +++ b/Scripts/Attributes/NodeEnum.cs @@ -1,5 +1,7 @@ using UnityEngine; -/// Draw enums correctly within nodes. Without it, enums show up at the wrong positions. -/// Enums with this attribute are not detected by EditorGui.ChangeCheck due to waiting before executing -public class NodeEnumAttribute : PropertyAttribute { } \ No newline at end of file +namespace XNode { + /// Draw enums correctly within nodes. Without it, enums show up at the wrong positions. + /// Enums with this attribute are not detected by EditorGui.ChangeCheck due to waiting before executing + public class NodeEnumAttribute : PropertyAttribute { } +} \ No newline at end of file diff --git a/Scripts/Attributes/PortTypeOverrideAttribute.cs b/Scripts/Attributes/PortTypeOverrideAttribute.cs index 316ca2d..1c269ef 100644 --- a/Scripts/Attributes/PortTypeOverrideAttribute.cs +++ b/Scripts/Attributes/PortTypeOverrideAttribute.cs @@ -1,12 +1,17 @@ using System; -/// Overrides the ValueType of the Port, to have a ValueType different from the type of its serializable field -/// Especially useful in Dynamic Port Lists to create Value-Port Pairs with different type. -[AttributeUsage(AttributeTargets.Field)] -public class PortTypeOverrideAttribute : Attribute { - public Type type; - /// Overrides the ValueType of the Port - /// ValueType of the Port - public PortTypeOverrideAttribute(Type type) { - this.type = type; + +namespace XNode { + /// Overrides the ValueType of the Port, to have a ValueType different from the type of its serializable field + /// Especially useful in Dynamic Port Lists to create Value-Port Pairs with different type. + [AttributeUsage(AttributeTargets.Field)] + public class PortTypeOverrideAttribute : Attribute + { + public Type type; + /// Overrides the ValueType of the Port + /// ValueType of the Port + public PortTypeOverrideAttribute(Type type) + { + this.type = type; + } } -} +} \ No newline at end of file diff --git a/Scripts/Node.cs b/Scripts/Node.cs index 62a2f4a..bad468d 100644 --- a/Scripts/Node.cs +++ b/Scripts/Node.cs @@ -250,12 +250,15 @@ namespace XNode { #endregion /// Called after a connection between two s is created - /// Output Input - public virtual void OnCreateConnection(NodePort from, NodePort to) { } + /// Output + /// Input + /// Creating while swapping or not? + public virtual void OnCreateConnection(NodePort from, NodePort to, bool swapping) { } /// Called after a connection is removed from this port /// Output or Input - public virtual void OnRemoveConnection(NodePort port) { } + /// Removing while swapping or not? + public virtual void OnRemoveConnection(NodePort port, bool swapping) { } /// Disconnect everything from this node public void ClearConnections() { diff --git a/Scripts/NodeDataCache.cs b/Scripts/NodeDataCache.cs index 4f4937d..2283fd1 100644 --- a/Scripts/NodeDataCache.cs +++ b/Scripts/NodeDataCache.cs @@ -162,7 +162,15 @@ namespace XNode { case "Microsoft": continue; default: - nodeTypes.AddRange(assembly.GetTypes().Where(t => !t.IsAbstract && baseType.IsAssignableFrom(t)).ToArray()); + try + { + nodeTypes.AddRange(assembly.GetTypes().Where(t => !t.IsAbstract && baseType.IsAssignableFrom(t)).ToArray()); + } + catch (System.Exception ex) + { + Debug.LogError($"Catched exception when building {assemblyName} caches"); + Debug.LogException(ex); + } break; } } diff --git a/Scripts/NodePort.cs b/Scripts/NodePort.cs index 1fbc62f..ea5287f 100644 --- a/Scripts/NodePort.cs +++ b/Scripts/NodePort.cs @@ -207,7 +207,8 @@ namespace XNode { /// Connect this to another /// The to connect to - public void Connect(NodePort port) { + /// Creating while swapping or not? + public void Connect(NodePort port, bool swapping = false) { if (connections == null) connections = new List(); if (port == null) { Debug.LogWarning("Cannot connect to null port"); return; } if (port == this) { Debug.LogWarning("Cannot connect port to self."); return; } @@ -217,13 +218,13 @@ namespace XNode { UnityEditor.Undo.RecordObject(node, "Connect Port"); UnityEditor.Undo.RecordObject(port.node, "Connect Port"); #endif - if (port.connectionType == Node.ConnectionType.Override && port.ConnectionCount != 0) { port.ClearConnections(); } - if (connectionType == Node.ConnectionType.Override && ConnectionCount != 0) { ClearConnections(); } + if (port.connectionType == Node.ConnectionType.Override && port.ConnectionCount != 0) { port.ClearConnections(swapping); } + if (connectionType == Node.ConnectionType.Override && ConnectionCount != 0) { ClearConnections(swapping); } connections.Add(new PortConnection(port)); if (port.connections == null) port.connections = new List(); if (!port.IsConnectedTo(this)) port.connections.Add(new PortConnection(this)); - node.OnCreateConnection(this, port); - port.node.OnCreateConnection(this, port); + node.OnCreateConnection(this, port, swapping); + port.node.OnCreateConnection(this, port, swapping); } public List GetConnections() { @@ -289,7 +290,7 @@ namespace XNode { } /// Disconnect this port from another port - public void Disconnect(NodePort port) { + public void Disconnect(NodePort port, bool swapping = false) { // Remove this ports connection to the other for (int i = connections.Count - 1; i >= 0; i--) { if (connections[i].Port == port) { @@ -302,16 +303,16 @@ namespace XNode { if (port.connections[i].Port == this) { port.connections.RemoveAt(i); // Trigger OnRemoveConnection from this side port - port.node.OnRemoveConnection(port); + port.node.OnRemoveConnection(port, swapping); } } } // Trigger OnRemoveConnection - node.OnRemoveConnection(this); + node.OnRemoveConnection(this, swapping); } /// Disconnect this port from another port - public void Disconnect(int i) { + public void Disconnect(int i, bool swapping = false) { // Remove the other ports connection to this port NodePort otherPort = connections[i].Port; if (otherPort != null) { @@ -321,13 +322,13 @@ namespace XNode { connections.RemoveAt(i); // Trigger OnRemoveConnection - node.OnRemoveConnection(this); - if (otherPort != null) otherPort.node.OnRemoveConnection(otherPort); + node.OnRemoveConnection(this, swapping); + if (otherPort != null) otherPort.node.OnRemoveConnection(otherPort, swapping); } - public void ClearConnections() { + public void ClearConnections(bool swapping = false) { while (connections.Count > 0) { - Disconnect(connections[0].Port); + Disconnect(connections[0].Port, swapping); } } @@ -352,16 +353,16 @@ namespace XNode { for (int i = 0; i < bConnectionCount; i++) targetPortConnections.Add(targetPort.connections[i].Port); - ClearConnections(); - targetPort.ClearConnections(); + ClearConnections(true); + targetPort.ClearConnections(true); // Add port connections to targetPort for (int i = 0; i < portConnections.Count; i++) - targetPort.Connect(portConnections[i]); + targetPort.Connect(portConnections[i], true); // Add target port connections to this one for (int i = 0; i < targetPortConnections.Count; i++) - Connect(targetPortConnections[i]); + Connect(targetPortConnections[i], true); } @@ -385,7 +386,7 @@ namespace XNode { NodePort otherPort = connection.Port; Connect(otherPort); } - ClearConnections(); + ClearConnections(false); } /// Swap connected nodes from the old list with nodes from the new list