Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Attributes/PortAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ public class PortAttribute : PortBaseAttribute {
/// <summary>
/// Port Attribute, this needs to be added to every SerializeReference field that should show up in the graph as a assignable node.
/// </summary>
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) { }
}
}
7 changes: 5 additions & 2 deletions Attributes/PortBaseAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ namespace NewGraph {
/// You'll mostly want to use the Port attribute instead.
/// </summary>
[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;
Expand All @@ -26,7 +28,7 @@ public class PortBaseAttribute : Attribute {
/// <param name="capacity">How many connections are allowed.</param>
/// <param name="direction">What port direction do we want to display?</param>
/// <param name="connectionPolicy">What connections are allowed only to the matching class or subclasses as well?</param>
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;
}
Expand All @@ -39,6 +41,7 @@ public PortBaseAttribute(string name = null, Capacity capacity = Capacity.Unspec
}

this.name = name;
this.color = color;
isValidConnectionCheck = connectionPolicybehaviors[this.connectionPolicy];
}
}
Expand Down
2 changes: 1 addition & 1 deletion Attributes/PortListAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ namespace NewGraph {
/// </summary>
[AttributeUsage(AttributeTargets.Field)]
public class PortListAttribute : PortAttribute {
public PortListAttribute() : base() { }
public PortListAttribute(string color = null) : base(color) { }
}
}
2 changes: 1 addition & 1 deletion Editor/Serialization/PropertyBag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 4 additions & 1 deletion Editor/Views/NodeView.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using UnityEditor;
using UnityEditor;
using UnityEditor.UIElements;
using UnityEngine;
using UnityEngine.UIElements;
Expand Down Expand Up @@ -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;
}
Expand Down
8 changes: 8 additions & 0 deletions Editor/Views/PortListView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using UnityEditor;
using UnityEditor.UIElements;
using UnityEngine;
using UnityEngine.UIElements;


Expand All @@ -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) {

Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 5 additions & 1 deletion Editor/Views/PortView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

namespace NewGraph {

Expand All @@ -17,6 +18,8 @@ public class PortView : BasePort {
private Func<Type,Type, bool> 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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;

Expand Down