diff --git a/Scripts/NodePort.cs b/Scripts/NodePort.cs index 4a55fc4..dfebe5c 100644 --- a/Scripts/NodePort.cs +++ b/Scripts/NodePort.cs @@ -19,13 +19,15 @@ public class NodePort { public bool IsOutput { get { return direction == IO.Output; } } public string fieldName { get { return _fieldName; } } + public Node node { get { return _node; } } - [SerializeField] public Node node; + [SerializeField] private Node _node; [SerializeField] private string _fieldName; [SerializeField] public Type type; [SerializeField] private List connections = new List(); [SerializeField] private IO _direction; + /// Construct a static targetless nodeport. Used as a template. public NodePort(FieldInfo fieldInfo) { _fieldName = fieldInfo.Name; type = fieldInfo.FieldType; @@ -37,11 +39,20 @@ public class NodePort { } } + /// Copy a nodePort but assign it to another node. public NodePort(NodePort nodePort, Node node) { _fieldName = nodePort._fieldName; type = nodePort.type; - this.node = node; _direction = nodePort.direction; + _node = node; + } + + /// Construct a dynamic port. Dynamic ports are not forgotten on reimport, and is ideal for runtime-created ports. + public NodePort(string fieldName, Type type, IO direction, Node node) { + _fieldName = fieldName; + this.type = type; + _direction = direction; + _node = node; } /// Checks all connections for invalid references, and removes them. @@ -192,7 +203,7 @@ public class NodePort { } [Serializable] - public class PortConnection { + private class PortConnection { [SerializeField] public string fieldName; [SerializeField] public Node node; public NodePort Port { get { return port != null ? port : port = GetPort(); } } @@ -207,14 +218,7 @@ public class NodePort { /// Returns the port that this points to private NodePort GetPort() { if (node == null || string.IsNullOrEmpty(fieldName)) return null; - - for (int i = 0; i < node.OutputCount; i++) { - if (node.outputs[i].fieldName == fieldName) return node.outputs[i]; - } - for (int i = 0; i < node.InputCount; i++) { - if (node.inputs[i].fieldName == fieldName) return node.inputs[i]; - } - return null; + return node.GetPortByFieldName(fieldName); } } } \ No newline at end of file