From 2e32a8348429cd0a208cebf582037a6271b42088 Mon Sep 17 00:00:00 2001 From: Chromium <62724067+Chromum@users.noreply.github.com> Date: Tue, 6 May 2025 10:10:15 +0100 Subject: [PATCH] Fixed Connector --- Editor/Scripts/Editor/Data Types/IPTPort.cs | 43 +++++++++++ Editor/Scripts/Editor/Data Types/IPT_Edge.cs | 1 + .../Editor/ImageProcessingGraphAsset.cs | 3 - .../Utils/Connector/GenericConnection.cs | 13 ++-- .../Windows/ImageProcessingGraphNodeVisual.cs | 3 + .../Windows/ImageProcessingGraphViewWindow.cs | 74 ++++++++++++++----- 6 files changed, 109 insertions(+), 28 deletions(-) diff --git a/Editor/Scripts/Editor/Data Types/IPTPort.cs b/Editor/Scripts/Editor/Data Types/IPTPort.cs index 4c9681b..40da3d7 100644 --- a/Editor/Scripts/Editor/Data Types/IPTPort.cs +++ b/Editor/Scripts/Editor/Data Types/IPTPort.cs @@ -1,5 +1,8 @@ using System; +using System.Linq; using System.Reflection; +using ImageProcessingGraph.Editor.Nodes.Types.Utils.Connector; +using ImageProcessingGraph.Editor.Unity_Image_Processing.Scripts.Editor.Windows; using UnityEditor.Experimental.GraphView; using UnityEngine; using UnityEngine.UIElements; @@ -36,12 +39,51 @@ namespace ImageProcessingGraph.Editor public override void Connect(Edge edge) { + ImageProcessingGraphNodeVisual IPTVis = this.node as ImageProcessingGraphNodeVisual; + + IPTPort extenalPort = null; + + if (IPTVis.GraphNode is GenericConnection bleh) + { + foreach (var port in IPTVis.AllPorts) + { + port.portType = edge.output.portType; + } + } + base.Connect(edge); OnPortConnected?.Invoke(); } public override void Disconnect(Edge edge) { + ImageProcessingGraphNodeVisual IPTVis = this.node as ImageProcessingGraphNodeVisual; + + if (IPTVis.GraphNode is GenericConnection bleh) + { + bool allPortsDisconnected = true; + + foreach (var port in IPTVis.AllPorts) + { + if (port.connections != null && port.connections.Count() > 0) + { + allPortsDisconnected = false; + break; + } + } + + if (allPortsDisconnected) + { + foreach (var port in IPTVis.AllPorts) + { + port.portType = typeof(object); + } + + bleh.InternalType = null; + } + } + + base.Disconnect(edge); OnPortDisconnected?.Invoke(); } @@ -62,5 +104,6 @@ namespace ImageProcessingGraph.Editor port.AddManipulator(port.m_EdgeConnector); return port; } + } } \ No newline at end of file diff --git a/Editor/Scripts/Editor/Data Types/IPT_Edge.cs b/Editor/Scripts/Editor/Data Types/IPT_Edge.cs index 677a72e..282515f 100644 --- a/Editor/Scripts/Editor/Data Types/IPT_Edge.cs +++ b/Editor/Scripts/Editor/Data Types/IPT_Edge.cs @@ -5,5 +5,6 @@ namespace ImageProcessingGraph.Editor { public class IPT_Edge : Edge { + } } \ No newline at end of file diff --git a/Editor/Scripts/Editor/ImageProcessingGraphAsset.cs b/Editor/Scripts/Editor/ImageProcessingGraphAsset.cs index 1588224..5e49131 100644 --- a/Editor/Scripts/Editor/ImageProcessingGraphAsset.cs +++ b/Editor/Scripts/Editor/ImageProcessingGraphAsset.cs @@ -48,7 +48,6 @@ namespace ImageProcessingGraph.Editor public void RunGraph() { - var bleh = GetAllVariableNodesWithTypes(); OnRun?.Invoke(); @@ -57,8 +56,6 @@ namespace ImageProcessingGraph.Editor stopwatch.Start(); runOrder = GetExecutionOrder(this.nodes, this.connections); - - foreach (var VARIABLE in runOrder) { diff --git a/Editor/Scripts/Editor/Nodes/Types/Utils/Connector/GenericConnection.cs b/Editor/Scripts/Editor/Nodes/Types/Utils/Connector/GenericConnection.cs index 80fca64..f35fe54 100644 --- a/Editor/Scripts/Editor/Nodes/Types/Utils/Connector/GenericConnection.cs +++ b/Editor/Scripts/Editor/Nodes/Types/Utils/Connector/GenericConnection.cs @@ -1,13 +1,17 @@ using ImageProcessingGraph.Editor.Nodes.NodeAttributes; using ImageProcessingGraph.Editor.Unity_Image_Processing.Scripts.Editor.Windows; using UnityEditor; +using UnityEngine; using UnityEngine.UIElements; namespace ImageProcessingGraph.Editor.Nodes.Types.Utils.Connector { [NodeInfo("", "Utility/Connection", false, null , editorType: typeof(GenericConnectionEditor))] public class GenericConnection : BaseImageNode - { + { + private System.Type internalType; + public System.Type InternalType { get { return internalType; } set { internalType = value; } } + [NodeAttributes.Input(" ")] public object input; [NodeAttributes.Output(" ")] public object output; @@ -21,13 +25,6 @@ namespace ImageProcessingGraph.Editor.Nodes.Types.Utils.Connector { public GenericConnectionEditor(BaseImageNode node, ImageProcessingGraphViewWindow window) : base(node, window) { - // StyleSheet styleSheet = AssetDatabase.LoadAssetAtPath("Assets/Unity Image Processing/GenericNode.uss"); - // if (styleSheet == null) - // { - // styleSheet = EditorGUIUtility.Load("Packages/com.chromium.imageprocessingrah/GenericNode.uss") as StyleSheet; - // } - // styleSheets.Add(styleSheet); - this.Q("title").style.display = DisplayStyle.None; } } diff --git a/Editor/Scripts/Editor/Windows/ImageProcessingGraphNodeVisual.cs b/Editor/Scripts/Editor/Windows/ImageProcessingGraphNodeVisual.cs index 0cf70fd..a920794 100644 --- a/Editor/Scripts/Editor/Windows/ImageProcessingGraphNodeVisual.cs +++ b/Editor/Scripts/Editor/Windows/ImageProcessingGraphNodeVisual.cs @@ -17,6 +17,7 @@ namespace ImageProcessingGraph.Editor.Unity_Image_Processing.Scripts.Editor.Wind private BaseImageNode graphNode; public BaseImageNode GraphNode => graphNode; + public List AllPorts = new List(); public List InputPorts { get; } public List OutputPorts { get; } @@ -107,6 +108,7 @@ namespace ImageProcessingGraph.Editor.Unity_Image_Processing.Scripts.Editor.Wind if (label != "") port.portName = label; InputPorts.Add(port); + AllPorts.Add(port); inputContainer.Add(port); @@ -127,6 +129,7 @@ namespace ImageProcessingGraph.Editor.Unity_Image_Processing.Scripts.Editor.Wind if (label != "") port.portName = label; OutputPorts.Add(port); + AllPorts.Add(port); outputContainer.Add(port); port.fieldInfo = field; diff --git a/Editor/Scripts/Editor/Windows/ImageProcessingGraphViewWindow.cs b/Editor/Scripts/Editor/Windows/ImageProcessingGraphViewWindow.cs index 56499c1..d24e7a2 100644 --- a/Editor/Scripts/Editor/Windows/ImageProcessingGraphViewWindow.cs +++ b/Editor/Scripts/Editor/Windows/ImageProcessingGraphViewWindow.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; using ImageProcessingGraph.Editor.Nodes.NodeAttributes; +using ImageProcessingGraph.Editor.Nodes.Types.Utils.Connector; using ImageProcessingGraph.Editor.Unity_Image_Processing.Scripts.Editor.Windows; using ImageProcessingGraph.Editor.Windows; using UnityEditor; @@ -233,43 +234,82 @@ namespace ImageProcessingGraph.Editor { List compatiblePorts = new List(); - foreach (var node in graphNodes) { - // Prevent connections to self if (node == startPort.node) continue; - - foreach (var port in node.inputContainer.Children().Concat(node.outputContainer.Children()).OfType()) + + var ports = node.inputContainer.Children() + .Concat(node.outputContainer.Children()) + .OfType(); + + foreach (var port in ports) { - // Prevent connecting input to input or output to output - if (port.direction == startPort.direction) + if (startPort.direction == port.direction) continue; - if (!port.portType.IsAssignableFrom(startPort.portType) || startPort.portType.IsAssignableFrom(port.portType)) - { - if (DoesConversionNodeExist()) - { + Type typeA = GetPortEffectiveType(startPort); + Type typeB = GetPortEffectiveType(port); - } - else - continue; - } + + // if (typeA == typeof(object)) + // { + // var BaseGenPort = startPort.node as ImageProcessingGraphNodeVisual; + // var GenPort = BaseGenPort.GraphNode as GenericConnection; + // + // if (GenPort.InternalType != null) + // { + // if(!GenPort.InternalType.IsAssignableFrom(typeB)) + // continue; + // } + // } + // + // if (typeB == typeof(object)) + // { + // var BaseGenPort = port.node as ImageProcessingGraphNodeVisual; + // var GenPort = BaseGenPort.GraphNode as GenericConnection; + // + // if (GenPort.InternalType != null) + // { + // if(!GenPort.InternalType.IsAssignableFrom(typeA)) + // continue; + // } + // } - // Prevent connection if it creates a cycle + if (!typeA.IsAssignableFrom(typeB) && !typeB.IsAssignableFrom(typeA)) + continue; + if (startPort.direction == Direction.Output && CreatesCycle(startPort, port)) continue; - if (startPort.direction == Direction.Input && CreatesCycle(port, startPort)) continue; compatiblePorts.Add(port); - } + } } return compatiblePorts; } + + private Type GetPortEffectiveType(Port port) + { + if (port is IPTPort iptPort) + { + if (iptPort.node is ImageProcessingGraphNodeVisual vis && + vis.GraphNode is GenericConnection conn && + conn.InternalType != null) + { + return conn.InternalType; + } + return port.portType ?? typeof(object); + } + + return port.portType ?? typeof(object); + } + + + private GraphViewChange OnGraphViewChanged(GraphViewChange graphviewchange) {