diff --git a/Attributes/PortAttribute.cs b/Attributes/PortAttribute.cs
index 41667bf..aa3cd45 100644
--- a/Attributes/PortAttribute.cs
+++ b/Attributes/PortAttribute.cs
@@ -9,6 +9,6 @@ public class PortAttribute : PortBaseAttribute {
///
/// Port Attribute, this needs to be added to every SerializeReference field that should show up in the graph as a assignable node.
///
- public PortAttribute(string name=null) : base(name, Capacity.Single, PortDirection.Output) { }
+ public PortAttribute(string name=null, string color = null) : base(name, color, Capacity.Single, PortDirection.Output) { }
}
}
diff --git a/Attributes/PortBaseAttribute.cs b/Attributes/PortBaseAttribute.cs
index e51949b..a4a7dc2 100644
--- a/Attributes/PortBaseAttribute.cs
+++ b/Attributes/PortBaseAttribute.cs
@@ -7,7 +7,9 @@ namespace NewGraph {
/// You'll mostly want to use the Port attribute instead.
///
[AttributeUsage(AttributeTargets.Field)]
- public class PortBaseAttribute : Attribute {
+ public class PortBaseAttribute : Attribute
+ {
+ public string color = null;
public string name = null;
public Capacity capacity = Capacity.Single;
public PortDirection direction = PortDirection.Input;
@@ -26,7 +28,7 @@ public class PortBaseAttribute : Attribute {
/// How many connections are allowed.
/// What port direction do we want to display?
/// What connections are allowed only to the matching class or subclasses as well?
- public PortBaseAttribute(string name = null, Capacity capacity = Capacity.Unspecified, PortDirection direction = PortDirection.Unspecified, ConnectionPolicy connectionPolicy = ConnectionPolicy.Unspecified) {
+ public PortBaseAttribute(string name = null, string color = null, Capacity capacity = Capacity.Unspecified, PortDirection direction = PortDirection.Unspecified, ConnectionPolicy connectionPolicy = ConnectionPolicy.Unspecified) {
if (capacity != Capacity.Unspecified) {
this.capacity = capacity;
}
@@ -39,6 +41,7 @@ public PortBaseAttribute(string name = null, Capacity capacity = Capacity.Unspec
}
this.name = name;
+ this.color = color;
isValidConnectionCheck = connectionPolicybehaviors[this.connectionPolicy];
}
}
diff --git a/Attributes/PortListAttribute.cs b/Attributes/PortListAttribute.cs
index 63f08d5..ab35e4d 100644
--- a/Attributes/PortListAttribute.cs
+++ b/Attributes/PortListAttribute.cs
@@ -6,6 +6,6 @@ namespace NewGraph {
///
[AttributeUsage(AttributeTargets.Field)]
public class PortListAttribute : PortAttribute {
- public PortListAttribute() : base() { }
+ public PortListAttribute(string color = null) : base(color) { }
}
}
\ No newline at end of file
diff --git a/Editor/Serialization/PropertyBag.cs b/Editor/Serialization/PropertyBag.cs
index c5b9c73..062118b 100644
--- a/Editor/Serialization/PropertyBag.cs
+++ b/Editor/Serialization/PropertyBag.cs
@@ -37,7 +37,7 @@ private PropertyBag(NodeAttribute nodeAttribute, Type nodeType, SerializedProper
this.nodeType = nodeType;
if (nodeAttribute.createInputPort) {
- inputPort = new PortInfo(nodeProperty.propertyPath, nodeType, new PortBaseAttribute(nodeAttribute.inputPortName, nodeAttribute.inputPortCapacity, PortDirection.Input), Settings.defaultInputName);
+ inputPort = new PortInfo(nodeProperty.propertyPath, nodeType, new PortBaseAttribute(null, nodeAttribute.inputPortName, nodeAttribute.inputPortCapacity, PortDirection.Input), Settings.defaultInputName);
}
InitializeAttributebehaviors();
RetrieveAll(nodeProperty);
diff --git a/Editor/Views/NodeView.cs b/Editor/Views/NodeView.cs
index cb46074..4c9be7e 100644
--- a/Editor/Views/NodeView.cs
+++ b/Editor/Views/NodeView.cs
@@ -1,4 +1,4 @@
-using UnityEditor;
+using UnityEditor;
using UnityEditor.UIElements;
using UnityEngine;
using UnityEngine.UIElements;
@@ -140,6 +140,9 @@ public PortView CreatePortUI(PortInfo info, SerializedProperty property) {
}
}
+ if (ColorUtility.TryParseHtmlString(info.portDisplay.color, out var color))
+ port.EdgeColor = color;
+
AddPort(port);
return port;
}
diff --git a/Editor/Views/PortListView.cs b/Editor/Views/PortListView.cs
index 84ec374..45aa983 100644
--- a/Editor/Views/PortListView.cs
+++ b/Editor/Views/PortListView.cs
@@ -3,6 +3,7 @@
using System.Linq;
using UnityEditor;
using UnityEditor.UIElements;
+using UnityEngine;
using UnityEngine.UIElements;
@@ -16,6 +17,7 @@ public class PortListView : ListView {
private NodeView nodeView;
public PortInfo portInfo;
private VisualElement container;
+ private Color color = default;
public PortListView(SerializedProperty listProperty, PortInfo portListInfo, NodeView nodeView, VisualElement container, int index=-1) {
@@ -24,6 +26,8 @@ public PortListView(SerializedProperty listProperty, PortInfo portListInfo, Node
this.container = container;
this.portInfo= portListInfo;
+ ColorUtility.TryParseHtmlString(portInfo.portDisplay.color, out color);
+
Label staticHeader = new Label(portListInfo.fieldName);
staticHeader.AddToClassList(nameof(staticHeader));
hierarchy.Add(staticHeader);
@@ -166,6 +170,10 @@ private VisualElement MakeItem() {
itemRow.Add(fieldLabel);
PortView port = new PortView(portInfo, null);
+
+ if(portInfo.portDisplay.color != null)
+ port.EdgeColor = color;
+
ports.Add(port);
port.SetParent(nodeView);
itemRow.Add(port);
diff --git a/Editor/Views/PortView.cs b/Editor/Views/PortView.cs
index e800c73..4e87305 100644
--- a/Editor/Views/PortView.cs
+++ b/Editor/Views/PortView.cs
@@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using UnityEditor;
+using UnityEngine;
namespace NewGraph {
@@ -17,6 +18,8 @@ public class PortView : BasePort {
private Func isValidConnectionCheck;
private UnityEngine.Color targetColor;
+ public Color EdgeColor { get; set; }
+
public PortView(PortInfo info, SerializedProperty boundProperty, Action connectionChangedCallback=null) : base(Orientation.Horizontal, (Direction)(int)info.portDisplay.direction, (PortCapacity)(int)info.portDisplay.capacity) {
this.type = info.fieldType;
this.isValidConnectionCheck = info.portDisplay.isValidConnectionCheck;
@@ -25,6 +28,7 @@ public PortView(PortInfo info, SerializedProperty boundProperty, Action connecti
this.connectionChangedCallback = connectionChangedCallback;
PortColor = DefaultPortColor;
+ EdgeColor = default;
}
public override UnityEngine.Color DefaultPortColor => Settings.portColor;
@@ -85,7 +89,7 @@ public override bool CanConnectTo(BasePort other, bool ignoreCandidateEdges = tr
private void ColorizeEdgeAndPort(EdgeView edge) {
Type nodeType = (edge.Input as PortView).type;
- targetColor = NodeModel.GetNodeAttribute(nodeType).color;
+ targetColor = EdgeColor == default ? NodeModel.GetNodeAttribute(nodeType).color : EdgeColor;
edge.currentUnselectedColor = (targetColor == default) ? Settings.colorUnselected : targetColor;
edge.InputColor = edge.OutputColor = edge.currentUnselectedColor;