Fixed Connector
This commit is contained in:
parent
fa5cba5ded
commit
2e32a83484
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -5,5 +5,6 @@ namespace ImageProcessingGraph.Editor
|
||||
{
|
||||
public class IPT_Edge : Edge
|
||||
{
|
||||
|
||||
}
|
||||
}
|
@ -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)
|
||||
{
|
||||
|
@ -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<StyleSheet>("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;
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ namespace ImageProcessingGraph.Editor.Unity_Image_Processing.Scripts.Editor.Wind
|
||||
private BaseImageNode graphNode;
|
||||
public BaseImageNode GraphNode => graphNode;
|
||||
|
||||
public List<Port> AllPorts = new List<Port>();
|
||||
public List<Port> InputPorts { get; }
|
||||
public List<Port> 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;
|
||||
|
@ -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<Port> compatiblePorts = new List<Port>();
|
||||
|
||||
|
||||
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<Port>())
|
||||
|
||||
var ports = node.inputContainer.Children()
|
||||
.Concat(node.outputContainer.Children())
|
||||
.OfType<Port>();
|
||||
|
||||
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)
|
||||
{
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user