Skip to content

Commit b2bb48a

Browse files
committed
Added support for wiring nodes colorisation
1 parent 21268f1 commit b2bb48a

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

Assets/Klak/Wiring/Editor/Patcher/GraphGUI.cs

+17
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,13 @@ void ShowCustomContextMenu()
253253
menu.AddItem(new GUIContent("Duplicate"), false, ContextMenuCallback, "Duplicate");
254254
menu.AddSeparator("");
255255
menu.AddItem(new GUIContent("Delete"), false, ContextMenuCallback, "Delete");
256+
257+
menu.AddSeparator("");
258+
var colors = Enum.GetValues(typeof(Graphs.Styles.Color)).Cast<Graphs.Styles.Color>().Distinct();
259+
foreach (var color in colors)
260+
{
261+
menu.AddItem(new GUIContent("Color/" + color), false, ContextMenuColorCallback, color);
262+
}
256263
}
257264
else if (edgeGUI.edgeSelection.Count != 0)
258265
{
@@ -277,6 +284,16 @@ void ContextMenuCallback(object data)
277284
m_Host.SendEvent(EditorGUIUtility.CommandEvent((string)data));
278285
}
279286

287+
void ContextMenuColorCallback(object data)
288+
{
289+
var newColor = (Graphs.Styles.Color)data;
290+
291+
foreach (Node node in selection)
292+
{
293+
node.SetColor(newColor);
294+
}
295+
}
296+
280297
void CreateMenuItemCallback(object data)
281298
{
282299
var type = data as Type;

Assets/Klak/Wiring/Editor/Patcher/Node.cs

+14
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,17 @@ public bool isValid {
5757
get { return _runtimeInstance != null; }
5858
}
5959

60+
// Set color of node
61+
public void SetColor(Graphs.Styles.Color newColor)
62+
{
63+
if (color == newColor) return;
64+
65+
color = newColor;
66+
_serializedObject.Update();
67+
_serializedColor.intValue = (int)newColor;
68+
_serializedObject.ApplyModifiedProperties();
69+
}
70+
6071
#endregion
6172

6273
#region Overridden virtual methods
@@ -98,6 +109,7 @@ public override void Dirty()
98109
// Serialized property accessor
99110
SerializedObject _serializedObject;
100111
SerializedProperty _serializedPosition;
112+
SerializedProperty _serializedColor;
101113

102114
// Initializer (called from the Create method)
103115
void Initialize(Wiring.NodeBase runtimeInstance)
@@ -108,10 +120,12 @@ void Initialize(Wiring.NodeBase runtimeInstance)
108120
_runtimeInstance = runtimeInstance;
109121
_serializedObject = new UnityEditor.SerializedObject(runtimeInstance);
110122
_serializedPosition = _serializedObject.FindProperty("_wiringNodePosition");
123+
_serializedColor = _serializedObject.FindProperty("_wiringNodeColor");
111124

112125
// Basic information
113126
name = runtimeInstance.GetInstanceID().ToString();
114127
position = new Rect(_serializedPosition.vector2Value, Vector2.zero);
128+
color = (Graphs.Styles.Color)_serializedColor.intValue;
115129

116130
// Slot initialization
117131
PopulateSlots();

Assets/Klak/Wiring/System/NodeBase.cs

+7
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ public class NodeBase : MonoBehaviour
5151
[SerializeField, HideInInspector]
5252
Vector2 _wiringNodePosition = uninitializedNodePosition;
5353

54+
[SerializeField, HideInInspector]
55+
int _wiringNodeColor = uninitializedNodeColor;
56+
5457
[Serializable]
5558
public class VoidEvent : UnityEvent {}
5659

@@ -69,5 +72,9 @@ public class ColorEvent : UnityEvent<Color> {}
6972
static public Vector2 uninitializedNodePosition {
7073
get { return new Vector2(-1000, -1000); }
7174
}
75+
76+
static public int uninitializedNodeColor {
77+
get { return 0; }
78+
}
7279
}
7380
}

0 commit comments

Comments
 (0)