1
0
mirror of https://github.com/Siccity/xNode.git synced 2025-12-22 02:06:05 +08:00

Updated compatability with newest xNode version

This commit is contained in:
Thor Brigsted 2019-11-14 22:29:18 +01:00
parent 4c824d4b91
commit b4a6c6e733
2 changed files with 31 additions and 6 deletions

View File

@ -50,11 +50,11 @@ namespace XNodeEditor.Examples.LogicToy {
} }
/// <summary> Controls graph noodle colors </summary> /// <summary> Controls graph noodle colors </summary>
public override Color GetNoodleColor(NodePort output, NodePort input) { public override Gradient GetNoodleGradient(NodePort output, NodePort input) {
LogicNode node = output.node as LogicNode; LogicNode node = output.node as LogicNode;
Color baseColor = base.GetNoodleColor(output, input); Gradient baseGradient = base.GetNoodleGradient(output, input);
HighlightGradient(baseGradient, Color.yellow, output, (bool) node.GetValue(output));
return GetLerpColor(baseColor, Color.yellow, output, (bool) node.GetValue(output)); return baseGradient;
} }
/// <summary> Controls graph type colors </summary> /// <summary> Controls graph type colors </summary>
@ -80,11 +80,32 @@ namespace XNodeEditor.Examples.LogicToy {
if (high) return on; if (high) return on;
else { else {
float t = (float) (EditorApplication.timeSinceStartup - lastOnTime); float t = (float) (lastOnTime - EditorApplication.timeSinceStartup);
t *= 8f; t *= 8f;
if (t < 1) return Color.Lerp(on, off, t); if (t > 0) return Color.Lerp(off, on, t);
else return off; else return off;
} }
} }
/// <summary> Returns a color based on if or when an arbitrary object was last 'on' </summary>
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);
}
} }
} }

View File

@ -27,6 +27,10 @@ namespace XNodeEditor.Examples.LogicToy {
} }
public override void OnBodyGUI() { public override void OnBodyGUI() {
if (target == null) {
Debug.LogWarning("Null target node for node editor!");
return;
}
NodePort input = target.GetPort("input"); NodePort input = target.GetPort("input");
NodePort output = target.GetPort("output"); NodePort output = target.GetPort("output");