From a511e4ad41953e4b1fdb2fb9518079e21bcf17e0 Mon Sep 17 00:00:00 2001
From: Greebling <56256331+Greebling@users.noreply.github.com>
Date: Mon, 11 Oct 2021 11:20:54 +0200
Subject: [PATCH 01/25] Update README.md
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 9e9e3556..8d150b55 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-# NodeGraphProcessor
+# NodeGraphProcessor Fork
Node graph editor framework focused on data processing using Unity UIElements, GraphView and C# 4.7
[![Discord](https://img.shields.io/discord/823720615965622323.svg)](https://discord.gg/XuMd3Z5Rym)
From d94beb1dae8305913ac785c82cde43244294840c Mon Sep 17 00:00:00 2001
From: Greebling <56256331+Greebling@users.noreply.github.com>
Date: Tue, 12 Oct 2021 11:48:12 +0200
Subject: [PATCH 02/25] fixed typo in function name
---
Assets/Examples/Editor/GraphAssetCallbacks.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Assets/Examples/Editor/GraphAssetCallbacks.cs b/Assets/Examples/Editor/GraphAssetCallbacks.cs
index dd61c37a..c44904a9 100644
--- a/Assets/Examples/Editor/GraphAssetCallbacks.cs
+++ b/Assets/Examples/Editor/GraphAssetCallbacks.cs
@@ -9,7 +9,7 @@
public class GraphAssetCallbacks
{
[MenuItem("Assets/Create/GraphProcessor", false, 10)]
- public static void CreateGraphPorcessor()
+ public static void CreateGraphProcessor()
{
var graph = ScriptableObject.CreateInstance< BaseGraph >();
ProjectWindowUtil.CreateAsset(graph, "GraphProcessor.asset");
From 43e50877b8f61200116a9c489bd8db104193aac1 Mon Sep 17 00:00:00 2001
From: Greebling <56256331+Greebling@users.noreply.github.com>
Date: Sat, 29 Jan 2022 23:02:53 +0100
Subject: [PATCH 03/25] Implement conversion nodes
---
.../Editor/Logic/EdgeConnectorListener.cs | 2 +-
.../Editor/Utils/NodeProvider.cs | 13 ++++-
.../Editor/Views/BaseGraphView.cs | 54 ++++++++++++++++++-
.../Runtime/Graph/BaseGraph.cs | 21 ++++----
.../Runtime/Processing/TypeAdapter.cs | 23 +++++---
5 files changed, 92 insertions(+), 21 deletions(-)
diff --git a/Assets/com.alelievr.NodeGraphProcessor/Editor/Logic/EdgeConnectorListener.cs b/Assets/com.alelievr.NodeGraphProcessor/Editor/Logic/EdgeConnectorListener.cs
index cef006d2..180df519 100644
--- a/Assets/com.alelievr.NodeGraphProcessor/Editor/Logic/EdgeConnectorListener.cs
+++ b/Assets/com.alelievr.NodeGraphProcessor/Editor/Logic/EdgeConnectorListener.cs
@@ -64,7 +64,7 @@ public virtual void OnDrop(GraphView graphView, Edge edge)
try
{
this.graphView.RegisterCompleteObjectUndo("Connected " + edgeView.input.node.name + " and " + edgeView.output.node.name);
- if (!this.graphView.Connect(edge as EdgeView, autoDisconnectInputs: !wasOnTheSamePort))
+ if (!this.graphView.ConnectConvertable(edge as EdgeView, !wasOnTheSamePort))
this.graphView.Disconnect(edge as EdgeView);
} catch (System.Exception)
{
diff --git a/Assets/com.alelievr.NodeGraphProcessor/Editor/Utils/NodeProvider.cs b/Assets/com.alelievr.NodeGraphProcessor/Editor/Utils/NodeProvider.cs
index da054683..9b525d12 100644
--- a/Assets/com.alelievr.NodeGraphProcessor/Editor/Utils/NodeProvider.cs
+++ b/Assets/com.alelievr.NodeGraphProcessor/Editor/Utils/NodeProvider.cs
@@ -337,9 +337,18 @@ bool IsPortCompatible(PortDescription description)
{
if ((portView.direction == Direction.Input && description.isInput) || (portView.direction == Direction.Output && !description.isInput))
return false;
+
+ if (portView.direction == Direction.Input)
+ {
+ if (!BaseGraph.TypesAreConnectable(description.portType, portView.portType))
+ return false;
+ }
+ else
+ {
+ if (!BaseGraph.TypesAreConnectable( portView.portType, description.portType))
+ return false;
+ }
- if (!BaseGraph.TypesAreConnectable(description.portType, portView.portType))
- return false;
return true;
}
diff --git a/Assets/com.alelievr.NodeGraphProcessor/Editor/Views/BaseGraphView.cs b/Assets/com.alelievr.NodeGraphProcessor/Editor/Views/BaseGraphView.cs
index 7940f6ee..7df76fb3 100644
--- a/Assets/com.alelievr.NodeGraphProcessor/Editor/Views/BaseGraphView.cs
+++ b/Assets/com.alelievr.NodeGraphProcessor/Editor/Views/BaseGraphView.cs
@@ -1192,8 +1192,60 @@ public bool Connect(PortView inputPortView, PortView outputPortView, bool autoDi
edgeView.input = inputPortView;
edgeView.output = outputPortView;
+ if (ConversionNodeAdapter.AreAssignable(outputPort.portData.displayType, inputPort.portData.displayType))
+ {
+ return ConnectConvertable(edgeView, autoDisconnectInputs);
+ } else
+ {
+ return Connect(edgeView);
+ }
+ }
- return Connect(edgeView);
+ ///
+ /// Same as connect, but also adds custom conversion nodes inbetween the edges input/output, if neccessary
+ ///
+ ///
+ ///
+ ///
+ public bool ConnectConvertable(EdgeView e, bool autoDisconnectInputs = true)
+ {
+ if (!CanConnectEdge(e, autoDisconnectInputs))
+ return false;
+
+ var inputPortView = e.input as PortView;
+ var outputPortView = e.output as PortView;
+ var inputNodeView = inputPortView.node as BaseNodeView;
+ var outputNodeView = outputPortView.node as BaseNodeView;
+ var inputPort = inputNodeView.nodeTarget.GetPort(inputPortView.fieldName, inputPortView.portData.identifier);
+ var outputPort = outputNodeView.nodeTarget.GetPort(outputPortView.fieldName, outputPortView.portData.identifier);
+
+ Type conversionNodeType = ConversionNodeAdapter.GetConversionNode(outputPort.portData.displayType, inputPort.portData.displayType);
+ if (conversionNodeType != null)
+ {
+ var nodePosition = (inputPort.owner.position.center + outputPort.owner.position.center) / 2.0f;
+ BaseNode converterNode = BaseNode.CreateFromType(conversionNodeType, nodePosition);
+ IConversionNode conversion = (IConversionNode)converterNode;
+ var converterView = AddNode(converterNode);
+
+ // set nodes center position to be in the middle of the input/output ports
+ converterNode.position.center = nodePosition - new Vector2(converterNode.position.width / 2.0f,0);
+ converterView.SetPosition(converterNode.position);
+
+
+ var conversionInputName = conversion.GetConversionInput();
+ var converterInput = converterView.inputPortViews.Find(view => view.fieldName == conversionInputName);
+ var conversionOutputName = conversion.GetConversionOutput();
+ var converterOutput = converterView.outputPortViews.Find(view => view.fieldName == conversionOutputName);
+
+ Connect(inputPortView, converterOutput, autoDisconnectInputs);
+
+ e.input = converterInput; // change from original input to use the converter node
+ return Connect(e, autoDisconnectInputs);
+ }
+ else
+ {
+ return Connect(e, autoDisconnectInputs);
+ }
}
public bool Connect(EdgeView e, bool autoDisconnectInputs = true)
diff --git a/Assets/com.alelievr.NodeGraphProcessor/Runtime/Graph/BaseGraph.cs b/Assets/com.alelievr.NodeGraphProcessor/Runtime/Graph/BaseGraph.cs
index f7da2f09..46f660f6 100644
--- a/Assets/com.alelievr.NodeGraphProcessor/Runtime/Graph/BaseGraph.cs
+++ b/Assets/com.alelievr.NodeGraphProcessor/Runtime/Graph/BaseGraph.cs
@@ -823,27 +823,30 @@ void DestroyBrokenGraphElements()
///
/// Tell if two types can be connected in the context of a graph
///
- ///
- ///
+ ///
+ ///
///
- public static bool TypesAreConnectable(Type t1, Type t2)
+ public static bool TypesAreConnectable(Type from, Type to) // NOTE: Extend this later for adding conversion nodes
{
- if (t1 == null || t2 == null)
+ if (from == null || to == null)
return false;
- if (TypeAdapter.AreIncompatible(t1, t2))
+ if (TypeAdapter.AreIncompatible(from, to))
return false;
//Check if there is custom adapters for this assignation
- if (CustomPortIO.IsAssignable(t1, t2))
+ if (CustomPortIO.IsAssignable(from, to))
return true;
//Check for type assignability
- if (t2.IsReallyAssignableFrom(t1))
+ if (to.IsReallyAssignableFrom(from))
return true;
- // User defined type convertions
- if (TypeAdapter.AreAssignable(t1, t2))
+ // User defined type conversions
+ if (TypeAdapter.AreAssignable(from, to))
+ return true;
+
+ if (ConversionNodeAdapter.AreAssignable(from, to))
return true;
return false;
diff --git a/Assets/com.alelievr.NodeGraphProcessor/Runtime/Processing/TypeAdapter.cs b/Assets/com.alelievr.NodeGraphProcessor/Runtime/Processing/TypeAdapter.cs
index 33592e6e..7108adce 100644
--- a/Assets/com.alelievr.NodeGraphProcessor/Runtime/Processing/TypeAdapter.cs
+++ b/Assets/com.alelievr.NodeGraphProcessor/Runtime/Processing/TypeAdapter.cs
@@ -22,13 +22,18 @@ public abstract class ITypeAdapter // TODO: turn this back into an interface whe
public virtual IEnumerable<(Type, Type)> GetIncompatibleTypes() { yield break; }
}
+ public class ValueTypeConversion : ITypeAdapter
+ {
+ public static float ConvertIntToFloat(int from) => from;
+ }
+
public static class TypeAdapter
{
static Dictionary< (Type from, Type to), Func