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/Nodes | |
parent | c92269331692feca2c276649f6c4ee8911f1f859 (diff) |
+node example
Diffstat (limited to 'Other/NodeEditorExamples/Assets/xNode-examples/Examples/LogicToy/Nodes')
10 files changed, 195 insertions, 0 deletions
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: |