diff options
author | chai <chaifix@163.com> | 2022-06-28 09:40:37 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2022-06-28 09:40:37 +0800 |
commit | 49b25e755b70ec412feaaf0b898d6f7e09d2bea6 (patch) | |
tree | 3c5f4260f30d1c2d7196db93153700d7ddec3157 /Other/NodeEditorExamples/Assets/xNode-examples/Examples/LogicToy | |
parent | c92269331692feca2c276649f6c4ee8911f1f859 (diff) |
+node example
Diffstat (limited to 'Other/NodeEditorExamples/Assets/xNode-examples/Examples/LogicToy')
22 files changed, 777 insertions, 0 deletions
diff --git a/Other/NodeEditorExamples/Assets/xNode-examples/Examples/LogicToy/Editor.meta b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/LogicToy/Editor.meta new file mode 100644 index 00000000..d198e91f --- /dev/null +++ b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/LogicToy/Editor.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: e5de235328e16fc4dbc4dcdd3794863e +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Other/NodeEditorExamples/Assets/xNode-examples/Examples/LogicToy/Editor/LogicGraphEditor.cs b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/LogicToy/Editor/LogicGraphEditor.cs new file mode 100644 index 00000000..1ba88780 --- /dev/null +++ b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/LogicToy/Editor/LogicGraphEditor.cs @@ -0,0 +1,111 @@ +using System.Collections.Generic; +using System.Linq; +using UnityEditor; +using UnityEngine; +using XNode; +using XNode.Examples.LogicToy; + +namespace XNodeEditor.Examples.LogicToy { + [CustomNodeGraphEditor(typeof(LogicGraph))] + public class LogicGraphEditor : NodeGraphEditor { + readonly Color boolColor = new Color(0.1f, 0.6f, 0.6f); + private List<ObjectLastOnTimer> lastOnTimers = new List<ObjectLastOnTimer>(); + private double lastFrame; + + /// <summary> Used for tracking when an arbitrary object was last 'on' for fading effects </summary> + private class ObjectLastOnTimer { + public object obj; + public double lastOnTime; + + public ObjectLastOnTimer(object obj, bool on) { + this.obj = obj; + } + } + + /// <summary> + /// Overriding GetNodeMenuName lets you control if and how nodes are categorized. + /// In this example we are sorting out all node types that are not in the XNode.Examples namespace. + /// </summary> + public override string GetNodeMenuName(System.Type type) { + if (type.Namespace == "XNode.Examples.LogicToy") { + return base.GetNodeMenuName(type).Replace("X Node/Examples/Logic Toy/", ""); + } else return null; + } + + public override void OnGUI() { + // Repaint each frame + window.Repaint(); + + // Timer + if (Event.current.type == EventType.Repaint) { + for (int i = 0; i < target.nodes.Count; i++) { + ITimerTick timerTick = target.nodes[i] as ITimerTick; + if (timerTick != null) { + float deltaTime = (float) (EditorApplication.timeSinceStartup - lastFrame); + timerTick.Tick(deltaTime); + } + } + } + lastFrame = EditorApplication.timeSinceStartup; + } + + /// <summary> Controls graph noodle colors </summary> + public override Gradient GetNoodleGradient(NodePort output, NodePort input) { + LogicNode node = output.node as LogicNode; + Gradient baseGradient = base.GetNoodleGradient(output, input); + HighlightGradient(baseGradient, Color.yellow, output, (bool) node.GetValue(output)); + return baseGradient; + } + + /// <summary> Controls graph type colors </summary> + public override Color GetTypeColor(System.Type type) { + if (type == typeof(bool)) return boolColor; + else return base.GetTypeColor(type); + } + + /// <summary> Returns the time at which an arbitrary object was last 'on' </summary> + public double GetLastOnTime(object obj, bool high) { + ObjectLastOnTimer timer = lastOnTimers.FirstOrDefault(x => x.obj == obj); + if (timer == null) { + timer = new ObjectLastOnTimer(obj, high); + lastOnTimers.Add(timer); + } + if (high) timer.lastOnTime = EditorApplication.timeSinceStartup; + return timer.lastOnTime; + } + + /// <summary> Returns a color based on if or when an arbitrary object was last 'on' </summary> + public Color GetLerpColor(Color off, Color on, object obj, bool high) { + double lastOnTime = GetLastOnTime(obj, high); + + if (high) return on; + else { + float t = (float) (lastOnTime - EditorApplication.timeSinceStartup); + t *= 8f; + if (t > 0) return Color.Lerp(off, on, t); + 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); + } + } +} diff --git a/Other/NodeEditorExamples/Assets/xNode-examples/Examples/LogicToy/Editor/LogicGraphEditor.cs.meta b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/LogicToy/Editor/LogicGraphEditor.cs.meta new file mode 100644 index 00000000..662c8e67 --- /dev/null +++ b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/LogicToy/Editor/LogicGraphEditor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 6c9bb5ae9dee9af43a89fa0db3ed8de0 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Other/NodeEditorExamples/Assets/xNode-examples/Examples/LogicToy/Editor/LogicNodeEditor.cs b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/LogicToy/Editor/LogicNodeEditor.cs new file mode 100644 index 00000000..24a8d603 --- /dev/null +++ b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/LogicToy/Editor/LogicNodeEditor.cs @@ -0,0 +1,45 @@ +using UnityEditor; +using UnityEngine; +using XNode; +using XNode.Examples.LogicToy; + +namespace XNodeEditor.Examples.LogicToy { + [CustomNodeEditor(typeof(LogicNode))] + public class LogicNodeEditor : NodeEditor { + private LogicNode node; + private LogicGraphEditor graphEditor; + + public override void OnHeaderGUI() { + // Initialization + if (node == null) { + node = target as LogicNode; + graphEditor = NodeGraphEditor.GetEditor(target.graph, window) as LogicGraphEditor; + } + + base.OnHeaderGUI(); + Rect dotRect = GUILayoutUtility.GetLastRect(); + dotRect.size = new Vector2(16, 16); + dotRect.y += 6; + + GUI.color = graphEditor.GetLerpColor(Color.red, Color.green, node, node.led); + GUI.DrawTexture(dotRect, NodeEditorResources.dot); + GUI.color = Color.white; + } + + 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"); + + GUILayout.BeginHorizontal(); + if (input != null) NodeEditorGUILayout.PortField(GUIContent.none, input, GUILayout.MinWidth(0)); + if (output != null) NodeEditorGUILayout.PortField(GUIContent.none, output, GUILayout.MinWidth(0)); + GUILayout.EndHorizontal(); + EditorGUIUtility.labelWidth = 60; + base.OnBodyGUI(); + } + } +}
\ No newline at end of file diff --git a/Other/NodeEditorExamples/Assets/xNode-examples/Examples/LogicToy/Editor/LogicNodeEditor.cs.meta b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/LogicToy/Editor/LogicNodeEditor.cs.meta new file mode 100644 index 00000000..24a3edfa --- /dev/null +++ b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/LogicToy/Editor/LogicNodeEditor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f1280a9d3431638429b64ea41000b794 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Other/NodeEditorExamples/Assets/xNode-examples/Examples/LogicToy/Example.asset b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/LogicToy/Example.asset new file mode 100644 index 00000000..44386d23 --- /dev/null +++ b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/LogicToy/Example.asset @@ -0,0 +1,347 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 1577ad53614c9e0498c962eaa9ba304f, type: 3} + m_Name: Example + m_EditorClassIdentifier: + nodes: + - {fileID: 114046633862954194} + - {fileID: 114880916489599218} + - {fileID: 114945579453429622} + - {fileID: 114944478030018250} + - {fileID: 114194736576219100} + - {fileID: 114558631167130670} + - {fileID: 114481634605117190} + - {fileID: 114463302483022418} +--- !u!114 &114046633862954194 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 54822dcd4ea0525409ad71a5fa416755, type: 3} + m_Name: Pulse + m_EditorClassIdentifier: + graph: {fileID: 11400000} + position: {x: -264, y: -248} + ports: + keys: + - output + values: + - _fieldName: output + _node: {fileID: 114046633862954194} + _typeQualifiedName: System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, + PublicKeyToken=b77a5c561934e089 + connections: + - fieldName: input + node: {fileID: 114880916489599218} + reroutePoints: [] + _direction: 1 + _connectionType: 0 + _typeConstraint: 0 + _dynamic: 0 + interval: 1 + output: 0 +--- !u!114 &114194736576219100 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: c7d4066122e5859498bbf1f1db2593cf, type: 3} + m_Name: Toggle + m_EditorClassIdentifier: + graph: {fileID: 11400000} + position: {x: -72, y: -8} + ports: + keys: + - input + - output + values: + - _fieldName: input + _node: {fileID: 114194736576219100} + _typeQualifiedName: System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, + PublicKeyToken=b77a5c561934e089 + connections: + - fieldName: output + node: {fileID: 114944478030018250} + reroutePoints: [] + - fieldName: output + node: {fileID: 114481634605117190} + reroutePoints: [] + _direction: 0 + _connectionType: 0 + _typeConstraint: 0 + _dynamic: 0 + - _fieldName: output + _node: {fileID: 114194736576219100} + _typeQualifiedName: System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, + PublicKeyToken=b77a5c561934e089 + connections: + - fieldName: input + node: {fileID: 114945579453429622} + reroutePoints: [] + _direction: 1 + _connectionType: 0 + _typeConstraint: 0 + _dynamic: 0 + input: 0 + output: 1 +--- !u!114 &114463302483022418 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: c4bb0f0e96df60a4690ca03082a93b44, type: 3} + m_Name: Not + m_EditorClassIdentifier: + graph: {fileID: 11400000} + position: {x: 88, y: -248} + ports: + keys: + - input + - output + values: + - _fieldName: input + _node: {fileID: 114463302483022418} + _typeQualifiedName: System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, + PublicKeyToken=b77a5c561934e089 + connections: + - fieldName: output + node: {fileID: 114880916489599218} + reroutePoints: [] + _direction: 0 + _connectionType: 0 + _typeConstraint: 0 + _dynamic: 0 + - _fieldName: output + _node: {fileID: 114463302483022418} + _typeQualifiedName: System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, + PublicKeyToken=b77a5c561934e089 + connections: [] + _direction: 1 + _connectionType: 0 + _typeConstraint: 0 + _dynamic: 0 + input: 1 + output: 0 +--- !u!114 &114481634605117190 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 54822dcd4ea0525409ad71a5fa416755, type: 3} + m_Name: Pulse + m_EditorClassIdentifier: + graph: {fileID: 11400000} + position: {x: -264, y: 72} + ports: + keys: + - output + values: + - _fieldName: output + _node: {fileID: 114481634605117190} + _typeQualifiedName: System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, + PublicKeyToken=b77a5c561934e089 + connections: + - fieldName: input + node: {fileID: 114194736576219100} + reroutePoints: [] + _direction: 1 + _connectionType: 0 + _typeConstraint: 0 + _dynamic: 0 + interval: 1 + output: 0 +--- !u!114 &114558631167130670 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: c7d4066122e5859498bbf1f1db2593cf, type: 3} + m_Name: Toggle + m_EditorClassIdentifier: + graph: {fileID: 11400000} + position: {x: 360, y: -72} + ports: + keys: + - input + - output + values: + - _fieldName: input + _node: {fileID: 114558631167130670} + _typeQualifiedName: System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, + PublicKeyToken=b77a5c561934e089 + connections: + - fieldName: output + node: {fileID: 114945579453429622} + reroutePoints: [] + _direction: 0 + _connectionType: 0 + _typeConstraint: 0 + _dynamic: 0 + - _fieldName: output + _node: {fileID: 114558631167130670} + _typeQualifiedName: System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, + PublicKeyToken=b77a5c561934e089 + connections: [] + _direction: 1 + _connectionType: 0 + _typeConstraint: 0 + _dynamic: 0 + input: 1 + output: 1 +--- !u!114 &114880916489599218 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: c7d4066122e5859498bbf1f1db2593cf, type: 3} + m_Name: Toggle + m_EditorClassIdentifier: + graph: {fileID: 11400000} + position: {x: -72, y: -168} + ports: + keys: + - input + - output + values: + - _fieldName: input + _node: {fileID: 114880916489599218} + _typeQualifiedName: System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, + PublicKeyToken=b77a5c561934e089 + connections: + - fieldName: output + node: {fileID: 114046633862954194} + reroutePoints: [] + _direction: 0 + _connectionType: 0 + _typeConstraint: 0 + _dynamic: 0 + - _fieldName: output + _node: {fileID: 114880916489599218} + _typeQualifiedName: System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, + PublicKeyToken=b77a5c561934e089 + connections: + - fieldName: input + node: {fileID: 114945579453429622} + reroutePoints: [] + - fieldName: input + node: {fileID: 114463302483022418} + reroutePoints: [] + _direction: 1 + _connectionType: 0 + _typeConstraint: 0 + _dynamic: 0 + input: 0 + output: 1 +--- !u!114 &114944478030018250 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 54822dcd4ea0525409ad71a5fa416755, type: 3} + m_Name: Pulse + m_EditorClassIdentifier: + graph: {fileID: 11400000} + position: {x: -264, y: -88} + ports: + keys: + - output + values: + - _fieldName: output + _node: {fileID: 114944478030018250} + _typeQualifiedName: System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, + PublicKeyToken=b77a5c561934e089 + connections: + - fieldName: input + node: {fileID: 114194736576219100} + reroutePoints: [] + _direction: 1 + _connectionType: 0 + _typeConstraint: 0 + _dynamic: 0 + interval: 1.06 + output: 0 +--- !u!114 &114945579453429622 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: c88b3b7abe7eb324baec5d03dfa998ab, type: 3} + m_Name: And + m_EditorClassIdentifier: + graph: {fileID: 11400000} + position: {x: 152, y: -72} + ports: + keys: + - input + - output + values: + - _fieldName: input + _node: {fileID: 114945579453429622} + _typeQualifiedName: System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, + PublicKeyToken=b77a5c561934e089 + connections: + - fieldName: output + node: {fileID: 114194736576219100} + reroutePoints: [] + - fieldName: output + node: {fileID: 114880916489599218} + reroutePoints: [] + _direction: 0 + _connectionType: 0 + _typeConstraint: 0 + _dynamic: 0 + - _fieldName: output + _node: {fileID: 114945579453429622} + _typeQualifiedName: System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, + PublicKeyToken=b77a5c561934e089 + connections: + - fieldName: input + node: {fileID: 114558631167130670} + reroutePoints: [] + _direction: 1 + _connectionType: 0 + _typeConstraint: 0 + _dynamic: 0 + input: 1 + output: 1 diff --git a/Other/NodeEditorExamples/Assets/xNode-examples/Examples/LogicToy/Example.asset.meta b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/LogicToy/Example.asset.meta new file mode 100644 index 00000000..188868d7 --- /dev/null +++ b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/LogicToy/Example.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: df29bbd59126610439c3391f59eac02a +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Other/NodeEditorExamples/Assets/xNode-examples/Examples/LogicToy/ITimerTick.cs b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/LogicToy/ITimerTick.cs new file mode 100644 index 00000000..4507b180 --- /dev/null +++ b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/LogicToy/ITimerTick.cs @@ -0,0 +1,5 @@ +namespace XNode.Examples.LogicToy { + public interface ITimerTick { + void Tick(float timeDelta); + } +}
\ No newline at end of file diff --git a/Other/NodeEditorExamples/Assets/xNode-examples/Examples/LogicToy/ITimerTick.cs.meta b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/LogicToy/ITimerTick.cs.meta new file mode 100644 index 00000000..511a5b19 --- /dev/null +++ b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/LogicToy/ITimerTick.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 46533d584cdbed04db785406b8361397 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Other/NodeEditorExamples/Assets/xNode-examples/Examples/LogicToy/LogicGraph.cs b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/LogicToy/LogicGraph.cs new file mode 100644 index 00000000..873d277d --- /dev/null +++ b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/LogicToy/LogicGraph.cs @@ -0,0 +1,6 @@ +using UnityEngine; + +namespace XNode.Examples.LogicToy { + [CreateAssetMenu(fileName = "New LogicToy Graph", menuName = "xNode Examples/LogicToy Graph")] + public class LogicGraph : NodeGraph { } +}
\ No newline at end of file diff --git a/Other/NodeEditorExamples/Assets/xNode-examples/Examples/LogicToy/LogicGraph.cs.meta b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/LogicToy/LogicGraph.cs.meta new file mode 100644 index 00000000..c0f0d7ff --- /dev/null +++ b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/LogicToy/LogicGraph.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 1577ad53614c9e0498c962eaa9ba304f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Other/NodeEditorExamples/Assets/xNode-examples/Examples/LogicToy/Nodes.meta b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/LogicToy/Nodes.meta new file mode 100644 index 00000000..3cc6de98 --- /dev/null +++ b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/LogicToy/Nodes.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 8852475771ad63a45a0854e9419d4e19 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Other/NodeEditorExamples/Assets/xNode-examples/Examples/LogicToy/Nodes/AndNode.cs b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/LogicToy/Nodes/AndNode.cs new file mode 100644 index 00000000..04fcbe6f --- /dev/null +++ b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/LogicToy/Nodes/AndNode.cs @@ -0,0 +1,25 @@ +using System.Linq; +using UnityEngine; + +namespace XNode.Examples.LogicToy { + [NodeWidth(140), NodeTint(100, 70, 70)] + public class AndNode : LogicNode { + [Input, HideInInspector] public bool input; + [Output, HideInInspector] public bool output; + public override bool led { get { return output; } } + + protected override void OnInputChanged() { + bool newInput = GetPort("input").GetInputValues<bool>().All(x => x); + + if (input != newInput) { + input = newInput; + output = newInput; + SendSignal(GetPort("output")); + } + } + + public override object GetValue(NodePort port) { + return output; + } + } +}
\ No newline at end of file diff --git a/Other/NodeEditorExamples/Assets/xNode-examples/Examples/LogicToy/Nodes/AndNode.cs.meta b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/LogicToy/Nodes/AndNode.cs.meta new file mode 100644 index 00000000..2b60e986 --- /dev/null +++ b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/LogicToy/Nodes/AndNode.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c88b3b7abe7eb324baec5d03dfa998ab +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Other/NodeEditorExamples/Assets/xNode-examples/Examples/LogicToy/Nodes/LogicNode.cs b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/LogicToy/Nodes/LogicNode.cs new file mode 100644 index 00000000..df34f94f --- /dev/null +++ b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/LogicToy/Nodes/LogicNode.cs @@ -0,0 +1,31 @@ +using System; +using UnityEngine; + +namespace XNode.Examples.LogicToy { + /// <summary> Base node for the LogicToy system </summary> + public abstract class LogicNode : Node { + public Action onStateChange; + public abstract bool led { get; } + + public void SendSignal(NodePort output) { + // Loop through port connections + int connectionCount = output.ConnectionCount; + for (int i = 0; i < connectionCount; i++) { + NodePort connectedPort = output.GetConnection(i); + + // Get connected ports logic node + LogicNode connectedNode = connectedPort.node as LogicNode; + + // Trigger it + if (connectedNode != null) connectedNode.OnInputChanged(); + } + if (onStateChange != null) onStateChange(); + } + + protected abstract void OnInputChanged(); + + public override void OnCreateConnection(NodePort from, NodePort to) { + OnInputChanged(); + } + } +}
\ No newline at end of file diff --git a/Other/NodeEditorExamples/Assets/xNode-examples/Examples/LogicToy/Nodes/LogicNode.cs.meta b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/LogicToy/Nodes/LogicNode.cs.meta new file mode 100644 index 00000000..435ffe0e --- /dev/null +++ b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/LogicToy/Nodes/LogicNode.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c1731c3983afdaa4e824178fcd76d66e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Other/NodeEditorExamples/Assets/xNode-examples/Examples/LogicToy/Nodes/NotNode.cs b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/LogicToy/Nodes/NotNode.cs new file mode 100644 index 00000000..1170757d --- /dev/null +++ b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/LogicToy/Nodes/NotNode.cs @@ -0,0 +1,25 @@ +using System.Linq; +using UnityEngine; + +namespace XNode.Examples.LogicToy { + [NodeWidth(140), NodeTint(100, 100, 50)] + public class NotNode : LogicNode { + [Input, HideInInspector] public bool input; + [Output, HideInInspector] public bool output = true; + public override bool led { get { return output; } } + + protected override void OnInputChanged() { + bool newInput = GetPort("input").GetInputValues<bool>().Any(x => x); + + if (input != newInput) { + input = newInput; + output = !newInput; + SendSignal(GetPort("output")); + } + } + + public override object GetValue(NodePort port) { + return output; + } + } +}
\ No newline at end of file diff --git a/Other/NodeEditorExamples/Assets/xNode-examples/Examples/LogicToy/Nodes/NotNode.cs.meta b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/LogicToy/Nodes/NotNode.cs.meta new file mode 100644 index 00000000..75461b4f --- /dev/null +++ b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/LogicToy/Nodes/NotNode.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c4bb0f0e96df60a4690ca03082a93b44 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Other/NodeEditorExamples/Assets/xNode-examples/Examples/LogicToy/Nodes/PulseNode.cs b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/LogicToy/Nodes/PulseNode.cs new file mode 100644 index 00000000..44c0dcb8 --- /dev/null +++ b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/LogicToy/Nodes/PulseNode.cs @@ -0,0 +1,32 @@ +using UnityEngine; + +namespace XNode.Examples.LogicToy { + [NodeWidth(140), NodeTint(70,100,70)] + public class PulseNode : LogicNode, ITimerTick { + [Space(-18)] + public float interval = 1f; + [Output, HideInInspector] public bool output; + public override bool led { get { return output; } } + + private float timer; + + public void Tick(float deltaTime) { + timer += deltaTime; + if (!output && timer > interval) { + timer -= interval; + output = true; + SendSignal(GetPort("output")); + } else if (output) { + output = false; + SendSignal(GetPort("output")); + } + } + + /// <summary> This node can not receive signals, so this is not used </summary> + protected override void OnInputChanged() { } + + public override object GetValue(NodePort port) { + return output; + } + } +}
\ No newline at end of file diff --git a/Other/NodeEditorExamples/Assets/xNode-examples/Examples/LogicToy/Nodes/PulseNode.cs.meta b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/LogicToy/Nodes/PulseNode.cs.meta new file mode 100644 index 00000000..268ec7d0 --- /dev/null +++ b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/LogicToy/Nodes/PulseNode.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 54822dcd4ea0525409ad71a5fa416755 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Other/NodeEditorExamples/Assets/xNode-examples/Examples/LogicToy/Nodes/ToggleNode.cs b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/LogicToy/Nodes/ToggleNode.cs new file mode 100644 index 00000000..ba71fa0d --- /dev/null +++ b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/LogicToy/Nodes/ToggleNode.cs @@ -0,0 +1,27 @@ +using System.Linq; +using UnityEngine; + +namespace XNode.Examples.LogicToy { + [NodeWidth(140), NodeTint(70,70,100)] + public class ToggleNode : LogicNode { + [Input, HideInInspector] public bool input; + [Output, HideInInspector] public bool output; + public override bool led { get { return output; } } + + protected override void OnInputChanged() { + bool newInput = GetPort("input").GetInputValues<bool>().Any(x => x); + + if (!input && newInput) { + input = newInput; + output = !output; + SendSignal(GetPort("output")); + } else if (input && !newInput) { + input = newInput; + } + } + + public override object GetValue(NodePort port) { + return output; + } + } +}
\ No newline at end of file diff --git a/Other/NodeEditorExamples/Assets/xNode-examples/Examples/LogicToy/Nodes/ToggleNode.cs.meta b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/LogicToy/Nodes/ToggleNode.cs.meta new file mode 100644 index 00000000..4b19b679 --- /dev/null +++ b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/LogicToy/Nodes/ToggleNode.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c7d4066122e5859498bbf1f1db2593cf +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: |