mirror of
https://github.com/Siccity/xNode.git
synced 2025-12-21 01:36:03 +08:00
Added LogicToy example
This commit is contained in:
parent
49e29a9f3e
commit
9130237e3a
8
Examples/LogicToy/Editor.meta
Normal file
8
Examples/LogicToy/Editor.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e5de235328e16fc4dbc4dcdd3794863e
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
41
Examples/LogicToy/Editor/LogicGraphEditor.cs
Normal file
41
Examples/LogicToy/Editor/LogicGraphEditor.cs
Normal file
@ -0,0 +1,41 @@
|
||||
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 {
|
||||
private class NoodleTimer {
|
||||
public NodePort output, input;
|
||||
public double lastOnTime;
|
||||
}
|
||||
|
||||
/// <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();
|
||||
}
|
||||
|
||||
public override Color GetNoodleColor(NodePort output, NodePort input) {
|
||||
LogicNode node = output.node as LogicNode;
|
||||
LogicNodeEditor nodeEditor = NodeEditor.GetEditor(node, window) as LogicNodeEditor;
|
||||
Color baseColor = base.GetNoodleColor(output, input);
|
||||
|
||||
float t = (float) (EditorApplication.timeSinceStartup - nodeEditor.lastOnTime);
|
||||
t *= 2f;
|
||||
return Color.Lerp(Color.yellow, baseColor, t);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Examples/LogicToy/Editor/LogicGraphEditor.cs.meta
Normal file
11
Examples/LogicToy/Editor/LogicGraphEditor.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6c9bb5ae9dee9af43a89fa0db3ed8de0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
36
Examples/LogicToy/Editor/LogicNodeEditor.cs
Normal file
36
Examples/LogicToy/Editor/LogicNodeEditor.cs
Normal file
@ -0,0 +1,36 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using XNode.Examples.LogicToy;
|
||||
|
||||
namespace XNodeEditor.Examples.LogicToy {
|
||||
[CustomNodeEditor(typeof(LogicNode))]
|
||||
public class LogicNodeEditor : NodeEditor {
|
||||
private LogicNode node;
|
||||
public double lastOnTime;
|
||||
|
||||
public override void OnHeaderGUI() {
|
||||
// Initialization
|
||||
if (node == null) {
|
||||
node = target as LogicNode;
|
||||
}
|
||||
|
||||
base.OnHeaderGUI();
|
||||
Rect dotRect = GUILayoutUtility.GetLastRect();
|
||||
dotRect.size = new Vector2(16, 16);
|
||||
dotRect.y += 6;
|
||||
|
||||
if (node.on) {
|
||||
GUI.color = Color.green;
|
||||
lastOnTime = EditorApplication.timeSinceStartup;
|
||||
} else {
|
||||
float t = (float) (EditorApplication.timeSinceStartup - lastOnTime);
|
||||
t *= 2f;
|
||||
if (t < 1) {
|
||||
GUI.color = Color.Lerp(Color.green, Color.red, t);
|
||||
} else GUI.color = Color.red;
|
||||
}
|
||||
GUI.DrawTexture(dotRect, NodeEditorResources.dot);
|
||||
GUI.color = Color.white;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Examples/LogicToy/Editor/LogicNodeEditor.cs.meta
Normal file
11
Examples/LogicToy/Editor/LogicNodeEditor.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f1280a9d3431638429b64ea41000b794
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
27
Examples/LogicToy/Editor/PulseNodeEditor.cs
Normal file
27
Examples/LogicToy/Editor/PulseNodeEditor.cs
Normal file
@ -0,0 +1,27 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using XNode.Examples.LogicToy;
|
||||
|
||||
namespace XNodeEditor.Examples.LogicToy {
|
||||
[CustomNodeEditor(typeof(PulseNode))]
|
||||
public class PulseNodeEditor : LogicNodeEditor {
|
||||
private PulseNode node;
|
||||
|
||||
public override void OnBodyGUI() {
|
||||
// Initialization
|
||||
if (node == null) {
|
||||
node = target as PulseNode;
|
||||
lastOnTime = EditorApplication.timeSinceStartup;
|
||||
}
|
||||
|
||||
// Timer
|
||||
if (EditorApplication.timeSinceStartup - lastOnTime > node.interval) {
|
||||
lastOnTime = EditorApplication.timeSinceStartup;
|
||||
node.FirePulse();
|
||||
}
|
||||
|
||||
// Basic GUI
|
||||
base.OnBodyGUI();
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Examples/LogicToy/Editor/PulseNodeEditor.cs.meta
Normal file
11
Examples/LogicToy/Editor/PulseNodeEditor.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 16a713ef662e1bd4086b83032f1d97c9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
223
Examples/LogicToy/Example.asset
Normal file
223
Examples/LogicToy/Example.asset
Normal file
@ -0,0 +1,223 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!114 &11400000
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInternal: {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: 114572916788169214}
|
||||
- {fileID: 114104949491275850}
|
||||
- {fileID: 114524369431968588}
|
||||
--- !u!114 &114046633862954194
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInternal: {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: -248, y: -88}
|
||||
ports:
|
||||
keys:
|
||||
- output
|
||||
values:
|
||||
- _fieldName: output
|
||||
_node: {fileID: 114046633862954194}
|
||||
_typeQualifiedName: XNode.Examples.LogicToy.LogicNode, Assembly-CSharp, Version=0.0.0.0,
|
||||
Culture=neutral, PublicKeyToken=null
|
||||
connections:
|
||||
- fieldName: input
|
||||
node: {fileID: 114880916489599218}
|
||||
reroutePoints: []
|
||||
- fieldName: input
|
||||
node: {fileID: 114524369431968588}
|
||||
reroutePoints: []
|
||||
_direction: 1
|
||||
_connectionType: 0
|
||||
_typeConstraint: 0
|
||||
_dynamic: 0
|
||||
interval: 1
|
||||
output: {fileID: 0}
|
||||
--- !u!114 &114104949491275850
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInternal: {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: 264, y: -40}
|
||||
ports:
|
||||
keys:
|
||||
- input
|
||||
- output
|
||||
values:
|
||||
- _fieldName: input
|
||||
_node: {fileID: 114104949491275850}
|
||||
_typeQualifiedName: XNode.Examples.LogicToy.LogicNode, Assembly-CSharp, Version=0.0.0.0,
|
||||
Culture=neutral, PublicKeyToken=null
|
||||
connections:
|
||||
- fieldName: output
|
||||
node: {fileID: 114572916788169214}
|
||||
reroutePoints: []
|
||||
_direction: 0
|
||||
_connectionType: 0
|
||||
_typeConstraint: 0
|
||||
_dynamic: 0
|
||||
- _fieldName: output
|
||||
_node: {fileID: 114104949491275850}
|
||||
_typeQualifiedName: XNode.Examples.LogicToy.LogicNode, Assembly-CSharp, Version=0.0.0.0,
|
||||
Culture=neutral, PublicKeyToken=null
|
||||
connections: []
|
||||
_direction: 1
|
||||
_connectionType: 0
|
||||
_typeConstraint: 0
|
||||
_dynamic: 0
|
||||
input: {fileID: 0}
|
||||
output: {fileID: 0}
|
||||
--- !u!114 &114524369431968588
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInternal: {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: -56, y: -8}
|
||||
ports:
|
||||
keys:
|
||||
- input
|
||||
- output
|
||||
values:
|
||||
- _fieldName: input
|
||||
_node: {fileID: 114524369431968588}
|
||||
_typeQualifiedName: XNode.Examples.LogicToy.LogicNode, Assembly-CSharp, Version=0.0.0.0,
|
||||
Culture=neutral, PublicKeyToken=null
|
||||
connections:
|
||||
- fieldName: output
|
||||
node: {fileID: 114046633862954194}
|
||||
reroutePoints: []
|
||||
_direction: 0
|
||||
_connectionType: 0
|
||||
_typeConstraint: 0
|
||||
_dynamic: 0
|
||||
- _fieldName: output
|
||||
_node: {fileID: 114524369431968588}
|
||||
_typeQualifiedName: XNode.Examples.LogicToy.LogicNode, Assembly-CSharp, Version=0.0.0.0,
|
||||
Culture=neutral, PublicKeyToken=null
|
||||
connections: []
|
||||
_direction: 1
|
||||
_connectionType: 0
|
||||
_typeConstraint: 0
|
||||
_dynamic: 0
|
||||
input: {fileID: 0}
|
||||
output: {fileID: 0}
|
||||
--- !u!114 &114572916788169214
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInternal: {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: 88, y: -168}
|
||||
ports:
|
||||
keys:
|
||||
- input
|
||||
- output
|
||||
values:
|
||||
- _fieldName: input
|
||||
_node: {fileID: 114572916788169214}
|
||||
_typeQualifiedName: XNode.Examples.LogicToy.LogicNode, Assembly-CSharp, Version=0.0.0.0,
|
||||
Culture=neutral, PublicKeyToken=null
|
||||
connections:
|
||||
- fieldName: output
|
||||
node: {fileID: 114880916489599218}
|
||||
reroutePoints: []
|
||||
_direction: 0
|
||||
_connectionType: 0
|
||||
_typeConstraint: 0
|
||||
_dynamic: 0
|
||||
- _fieldName: output
|
||||
_node: {fileID: 114572916788169214}
|
||||
_typeQualifiedName: XNode.Examples.LogicToy.LogicNode, Assembly-CSharp, Version=0.0.0.0,
|
||||
Culture=neutral, PublicKeyToken=null
|
||||
connections:
|
||||
- fieldName: input
|
||||
node: {fileID: 114104949491275850}
|
||||
reroutePoints: []
|
||||
_direction: 1
|
||||
_connectionType: 0
|
||||
_typeConstraint: 0
|
||||
_dynamic: 0
|
||||
input: {fileID: 0}
|
||||
output: {fileID: 0}
|
||||
--- !u!114 &114880916489599218
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInternal: {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: XNode.Examples.LogicToy.LogicNode, Assembly-CSharp, Version=0.0.0.0,
|
||||
Culture=neutral, PublicKeyToken=null
|
||||
connections:
|
||||
- fieldName: output
|
||||
node: {fileID: 114046633862954194}
|
||||
reroutePoints: []
|
||||
_direction: 0
|
||||
_connectionType: 0
|
||||
_typeConstraint: 0
|
||||
_dynamic: 0
|
||||
- _fieldName: output
|
||||
_node: {fileID: 114880916489599218}
|
||||
_typeQualifiedName: XNode.Examples.LogicToy.LogicNode, Assembly-CSharp, Version=0.0.0.0,
|
||||
Culture=neutral, PublicKeyToken=null
|
||||
connections:
|
||||
- fieldName: input
|
||||
node: {fileID: 114572916788169214}
|
||||
reroutePoints: []
|
||||
_direction: 1
|
||||
_connectionType: 0
|
||||
_typeConstraint: 0
|
||||
_dynamic: 0
|
||||
input: {fileID: 0}
|
||||
output: {fileID: 0}
|
||||
8
Examples/LogicToy/Example.asset.meta
Normal file
8
Examples/LogicToy/Example.asset.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: df29bbd59126610439c3391f59eac02a
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
6
Examples/LogicToy/LogicGraph.cs
Normal file
6
Examples/LogicToy/LogicGraph.cs
Normal file
@ -0,0 +1,6 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace XNode.Examples.LogicToy {
|
||||
[CreateAssetMenu(fileName = "New LogicToy Graph", menuName = "xNode Examples/LogicToy Graph")]
|
||||
public class LogicGraph : NodeGraph { }
|
||||
}
|
||||
11
Examples/LogicToy/LogicGraph.cs.meta
Normal file
11
Examples/LogicToy/LogicGraph.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1577ad53614c9e0498c962eaa9ba304f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Examples/LogicToy/Nodes.meta
Normal file
8
Examples/LogicToy/Nodes.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8852475771ad63a45a0854e9419d4e19
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
22
Examples/LogicToy/Nodes/LogicNode.cs
Normal file
22
Examples/LogicToy/Nodes/LogicNode.cs
Normal file
@ -0,0 +1,22 @@
|
||||
namespace XNode.Examples.LogicToy {
|
||||
/// <summary> Base node for the LogicToy system </summary>
|
||||
public abstract class LogicNode : Node {
|
||||
public abstract bool on { get; }
|
||||
|
||||
protected abstract void OnTrigger();
|
||||
|
||||
public void SendPulse(NodePort port) {
|
||||
// Loop through port connections
|
||||
int connectionCount = port.ConnectionCount;
|
||||
for (int i = 0; i < connectionCount; i++) {
|
||||
NodePort connectedPort = port.GetConnection(i);
|
||||
|
||||
// Get connected ports logic node
|
||||
LogicNode logicNode = connectedPort.node as LogicNode;
|
||||
|
||||
// Trigger it
|
||||
if (logicNode != null) logicNode.OnTrigger();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Examples/LogicToy/Nodes/LogicNode.cs.meta
Normal file
11
Examples/LogicToy/Nodes/LogicNode.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c1731c3983afdaa4e824178fcd76d66e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
16
Examples/LogicToy/Nodes/PulseNode.cs
Normal file
16
Examples/LogicToy/Nodes/PulseNode.cs
Normal file
@ -0,0 +1,16 @@
|
||||
namespace XNode.Examples.LogicToy {
|
||||
[NodeWidth(140)]
|
||||
public class PulseNode : LogicNode {
|
||||
public float interval = 1f;
|
||||
[Output] public LogicNode output;
|
||||
public override bool on { get { return false; } }
|
||||
|
||||
/// <summary> Called from editor </summary>
|
||||
public void FirePulse() {
|
||||
SendPulse(GetPort("output"));
|
||||
}
|
||||
|
||||
/// <summary> This node has no inputs, so this does nothing </summary>
|
||||
protected override void OnTrigger() { }
|
||||
}
|
||||
}
|
||||
11
Examples/LogicToy/Nodes/PulseNode.cs.meta
Normal file
11
Examples/LogicToy/Nodes/PulseNode.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 54822dcd4ea0525409ad71a5fa416755
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
17
Examples/LogicToy/Nodes/ToggleNode.cs
Normal file
17
Examples/LogicToy/Nodes/ToggleNode.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace XNode.Examples.LogicToy {
|
||||
[NodeWidth(140)]
|
||||
public class ToggleNode : LogicNode {
|
||||
private bool _on;
|
||||
[Input] public LogicNode input;
|
||||
[Output] public LogicNode output;
|
||||
public override bool on { get { return _on; } }
|
||||
|
||||
/// <summary> This node has no inputs, so this does nothing </summary>
|
||||
protected override void OnTrigger() {
|
||||
_on = !_on;
|
||||
if (on) SendPulse(GetPort("output"));
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Examples/LogicToy/Nodes/ToggleNode.cs.meta
Normal file
11
Examples/LogicToy/Nodes/ToggleNode.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c7d4066122e5859498bbf1f1db2593cf
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Loading…
x
Reference in New Issue
Block a user