diff --git a/Examples/LogicToy/Editor/LogicGraphEditor.cs b/Examples/LogicToy/Editor/LogicGraphEditor.cs index ec451f8..ca09ea6 100644 --- a/Examples/LogicToy/Editor/LogicGraphEditor.cs +++ b/Examples/LogicToy/Editor/LogicGraphEditor.cs @@ -50,11 +50,11 @@ namespace XNodeEditor.Examples.LogicToy { } /// Controls graph noodle colors - public override Color GetNoodleColor(NodePort output, NodePort input) { + public override Gradient GetNoodleGradient(NodePort output, NodePort input) { LogicNode node = output.node as LogicNode; - Color baseColor = base.GetNoodleColor(output, input); - - return GetLerpColor(baseColor, Color.yellow, output, (bool) node.GetValue(output)); + Gradient baseGradient = base.GetNoodleGradient(output, input); + HighlightGradient(baseGradient, Color.yellow, output, (bool) node.GetValue(output)); + return baseGradient; } /// Controls graph type colors @@ -80,11 +80,32 @@ namespace XNodeEditor.Examples.LogicToy { if (high) return on; else { - float t = (float) (EditorApplication.timeSinceStartup - lastOnTime); + float t = (float) (lastOnTime - EditorApplication.timeSinceStartup); t *= 8f; - if (t < 1) return Color.Lerp(on, off, t); + if (t > 0) return Color.Lerp(off, on, t); else return off; } } + + /// Returns a color based on if or when an arbitrary object was last 'on' + public void HighlightGradient(Gradient gradient, Color highlightColor, object obj, bool high) { + double lastOnTime = GetLastOnTime(obj, high); + float t; + + if (high) t = 1f; + else { + t = (float) (lastOnTime - EditorApplication.timeSinceStartup); + t *= 8f; + t += 1; + } + t = Mathf.Clamp01(t); + GradientColorKey[] colorKeys = gradient.colorKeys; + for (int i = 0; i < colorKeys.Length; i++) { + GradientColorKey colorKey = colorKeys[i]; + colorKey.color = Color.Lerp(colorKeys[i].color, highlightColor, t); + colorKeys[i] = colorKey; + } + gradient.SetKeys(colorKeys, gradient.alphaKeys); + } } } \ No newline at end of file diff --git a/Examples/LogicToy/Editor/LogicNodeEditor.cs b/Examples/LogicToy/Editor/LogicNodeEditor.cs index 7426771..24a8d60 100644 --- a/Examples/LogicToy/Editor/LogicNodeEditor.cs +++ b/Examples/LogicToy/Editor/LogicNodeEditor.cs @@ -27,6 +27,10 @@ namespace XNodeEditor.Examples.LogicToy { } public override void OnBodyGUI() { + if (target == null) { + Debug.LogWarning("Null target node for node editor!"); + return; + } NodePort input = target.GetPort("input"); NodePort output = target.GetPort("output");