diff --git a/Scripts/Editor/NodeEditorAction.cs b/Scripts/Editor/NodeEditorAction.cs index 804b4c6..f4fcdb7 100644 --- a/Scripts/Editor/NodeEditorAction.cs +++ b/Scripts/Editor/NodeEditorAction.cs @@ -127,7 +127,7 @@ public partial class NodeEditorWindow { if (!_portConnectionPoints.ContainsKey(draggedOutput)) return; Vector2 from = _portConnectionPoints[draggedOutput].center; Vector2 to = draggedOutputTarget != null ? portConnectionPoints[draggedOutputTarget].center : WindowToGridPosition(Event.current.mousePosition); - Color col = NodeEditorPreferences.GetTypeColor(draggedOutput.type); + Color col = NodeEditorPreferences.GetTypeColor(draggedOutput.ValueType); col.a = 0.6f; DrawConnection(from, to, col); } diff --git a/Scripts/Editor/NodeEditorGUI.cs b/Scripts/Editor/NodeEditorGUI.cs index 578eb3e..0ba190d 100644 --- a/Scripts/Editor/NodeEditorGUI.cs +++ b/Scripts/Editor/NodeEditorGUI.cs @@ -129,7 +129,7 @@ public partial class NodeEditorWindow { if (!input.IsConnectedTo(output)) input.Connect(output); if (!_portConnectionPoints.ContainsKey(input)) continue; Vector2 to = _portConnectionPoints[input].center; - DrawConnection(from, to, NodeEditorPreferences.GetTypeColor(output.type)); + DrawConnection(from, to, NodeEditorPreferences.GetTypeColor(output.ValueType)); } } } @@ -235,7 +235,7 @@ public partial class NodeEditorWindow { private void DrawTooltip() { if (hoveredPort != null) { - Type type = hoveredPort.type; + Type type = hoveredPort.ValueType; GUIContent content = new GUIContent(); content.text = TypeToString(type); Vector2 size = NodeEditorResources.styles.tooltip.CalcSize(content); @@ -246,6 +246,7 @@ public partial class NodeEditorWindow { } private string TypeToString(Type type) { + if (type == null) return "null"; if (type == typeof(float)) return "float"; else if (type == typeof(int)) return "int"; else if (type == typeof(long)) return "long"; @@ -276,6 +277,6 @@ public partial class NodeEditorWindow { int i = s.IndexOf('['); return s.Substring(0,i) + "["+rank+"]" + s.Substring(i); } - } else return hoveredPort.type.ToString(); + } else return hoveredPort.ValueType.ToString(); } } \ No newline at end of file diff --git a/Scripts/Editor/NodeEditorGUILayout.cs b/Scripts/Editor/NodeEditorGUILayout.cs index 8ec6fbf..efbd51d 100644 --- a/Scripts/Editor/NodeEditorGUILayout.cs +++ b/Scripts/Editor/NodeEditorGUILayout.cs @@ -7,7 +7,7 @@ using UnityEditor; using UnityEngine; /// UNEC-specific version of -public static class NodeEditorGUILayout { +public static class NodeEditorGUILayout { public static void PropertyField(SerializedProperty property, bool includeChildren = true) { if (property == null) throw new NullReferenceException(); @@ -29,7 +29,7 @@ public static class NodeEditorGUILayout { else EditorGUILayout.PropertyField(property, includeChildren); rect = GUILayoutUtility.GetLastRect(); rect.position = rect.position - new Vector2(16, 0); - // If property is an output, display a text label and put a port handle on the right side + // If property is an output, display a text label and put a port handle on the right side } else if (port.direction == NodePort.IO.Output) { EditorGUILayout.LabelField(property.displayName, NodeEditorResources.styles.outputPort); rect = GUILayoutUtility.GetLastRect(); @@ -38,7 +38,7 @@ public static class NodeEditorGUILayout { rect.size = new Vector2(16, 16); - DrawPortHandle(rect, port.type); + DrawPortHandle(rect, port.ValueType); // Register the handle position Vector2 portPos = rect.center; diff --git a/Scripts/Node.cs b/Scripts/Node.cs index ca21f0f..6df05cd 100644 --- a/Scripts/Node.cs +++ b/Scripts/Node.cs @@ -74,6 +74,7 @@ public abstract class Node : ScriptableObject { public bool RemoveInstancePort(string fieldName) { NodePort port = GetPort(fieldName); if (port == null || port.IsStatic) return false; + port.ClearConnections(); ports.Remove(fieldName); return true; } diff --git a/Scripts/NodeDataCache.cs b/Scripts/NodeDataCache.cs index b542be1..30d98ab 100644 --- a/Scripts/NodeDataCache.cs +++ b/Scripts/NodeDataCache.cs @@ -23,14 +23,12 @@ public static class NodeDataCache { } // Cleanup port dict - Remove nonexisting static ports - update static port types - foreach (NodePort port in ports.Values) { + foreach (NodePort port in ports.Values.ToList()) { if (staticPorts.ContainsKey(port.fieldName)) { NodePort staticPort = staticPorts[port.fieldName]; if (port.IsDynamic || port.direction != staticPort.direction) ports.Remove(port.fieldName); - else port.type = staticPort.type; - } else { - ports.Remove(port.fieldName); - } + else port.ValueType = staticPort.ValueType; + } else if (port.IsStatic) ports.Remove(port.fieldName); } // Add missing ports foreach (NodePort staticPort in staticPorts.Values) { diff --git a/Scripts/NodePort.cs b/Scripts/NodePort.cs index 8fcb958..6a85b78 100644 --- a/Scripts/NodePort.cs +++ b/Scripts/NodePort.cs @@ -103,6 +103,11 @@ public class NodePort { object[] objs = new object[ConnectionCount]; for (int i = 0; i < ConnectionCount; i++) { NodePort connectedPort = connections[i].Port; + if (connectedPort == null) { // if we happen to find a null port, remove it and look again + connections.RemoveAt(i); + i--; + continue; + } objs[i] = connectedPort.GetOutputValue(); } return objs;