mirror of
https://github.com/Siccity/xNode.git
synced 2025-12-21 01:36:03 +08:00
Added state machine example
This commit is contained in:
parent
290aa040fa
commit
22e537be4a
@ -1,8 +0,0 @@
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using XNode;
|
||||
|
||||
/// <summary> Defines an example nodegraph. </summary>
|
||||
[Serializable, CreateAssetMenu(fileName = "ExampleNodeGraph", menuName = "Node Graph/Example")]
|
||||
public class ExampleNodeGraph : XNode.NodeGraph {
|
||||
}
|
||||
@ -1,14 +0,0 @@
|
||||
using XNode;
|
||||
|
||||
namespace BasicNodes {
|
||||
public class DisplayValue : XNode.Node {
|
||||
protected override void Init() {
|
||||
base.Init();
|
||||
if (!HasPort("input")) AddInstanceInput(typeof(object), ConnectionType.Override ,"input");
|
||||
}
|
||||
|
||||
public override object GetValue(XNode.NodePort port) {
|
||||
return GetInputValue<object>("input");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,15 +0,0 @@
|
||||
using UnityEditor;
|
||||
using XNodeEditor;
|
||||
|
||||
namespace BasicNodes {
|
||||
[CustomNodeEditor(typeof(DisplayValue))]
|
||||
public class DisplayValueEditor : NodeEditor {
|
||||
|
||||
public override void OnBodyGUI() {
|
||||
base.OnBodyGUI();
|
||||
NodeEditorGUILayout.PortField(target.GetInputPort("input"));
|
||||
object obj = target.GetValue(null);
|
||||
if (obj != null) EditorGUILayout.LabelField(obj.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
10
Examples/MathGraph.meta
Normal file
10
Examples/MathGraph.meta
Normal file
@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 852631db1e0f047478da88918f49e4a3
|
||||
folderAsset: yes
|
||||
timeCreated: 1516177447
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
10
Examples/MathGraph/Editor.meta
Normal file
10
Examples/MathGraph/Editor.meta
Normal file
@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 642e362943557314392fc62290a8e242
|
||||
folderAsset: yes
|
||||
timeCreated: 1516180279
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
20
Examples/MathGraph/Editor/MathGraphEditor.cs
Normal file
20
Examples/MathGraph/Editor/MathGraphEditor.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using XNode.Examples;
|
||||
|
||||
namespace XNodeEditor.Examples {
|
||||
[CustomNodeGraphEditor(typeof(MathGraph))]
|
||||
public class MathGraphEditor : NodeGraphEditor {
|
||||
|
||||
/// <summary>
|
||||
/// Overriding GetNodePath 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 GetNodePath(System.Type type) {
|
||||
if (type.Namespace == "XNode.Examples.MathNodes") {
|
||||
return base.GetNodePath(type).Replace("X Node/Examples/Math Nodes/", "");
|
||||
} else return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
13
Examples/MathGraph/Editor/MathGraphEditor.cs.meta
Normal file
13
Examples/MathGraph/Editor/MathGraphEditor.cs.meta
Normal file
@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3f6ed0407f1f4ad45bf697d7798ddf0d
|
||||
timeCreated: 1516180270
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Examples/MathGraph/MathGraph.cs
Normal file
8
Examples/MathGraph/MathGraph.cs
Normal file
@ -0,0 +1,8 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace XNode.Examples {
|
||||
/// <summary> Defines an example nodegraph that can be created as an asset in the Project window. </summary>
|
||||
[Serializable, CreateAssetMenu(fileName = "New Math Graph", menuName = "xNode Examples/Math Graph")]
|
||||
public class MathGraph : XNode.NodeGraph { }
|
||||
}
|
||||
@ -9,119 +9,14 @@ MonoBehaviour:
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: a6399826e2c44b447b32a3ed06646162, type: 3}
|
||||
m_Name: ExampleNodeGraph
|
||||
m_Name: New Math Graph
|
||||
m_EditorClassIdentifier:
|
||||
nodes:
|
||||
- {fileID: 114708853913061688}
|
||||
- {fileID: 114511978881715272}
|
||||
- {fileID: 114509033286994848}
|
||||
- {fileID: 114245496101350052}
|
||||
--- !u!114 &114245496101350052
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_PrefabParentObject: {fileID: 0}
|
||||
m_PrefabInternal: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 98f6f901f0da53142b79277ea3f42518, type: 3}
|
||||
m_Name: DisplayValue
|
||||
m_EditorClassIdentifier:
|
||||
graph: {fileID: 11400000}
|
||||
position: {x: -168, y: 8}
|
||||
ports:
|
||||
keys:
|
||||
- input
|
||||
values:
|
||||
- _fieldName: input
|
||||
_node: {fileID: 114245496101350052}
|
||||
_typeQualifiedName: System.Object, mscorlib, Version=2.0.0.0, Culture=neutral,
|
||||
PublicKeyToken=b77a5c561934e089
|
||||
connections:
|
||||
- fieldName: result
|
||||
node: {fileID: 114511978881715272}
|
||||
_direction: 0
|
||||
_connectionType: 1
|
||||
_dynamic: 1
|
||||
--- !u!114 &114509033286994848
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_PrefabParentObject: {fileID: 0}
|
||||
m_PrefabInternal: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 98f6f901f0da53142b79277ea3f42518, type: 3}
|
||||
m_Name: DisplayValue
|
||||
m_EditorClassIdentifier:
|
||||
graph: {fileID: 11400000}
|
||||
position: {x: 72, y: -72}
|
||||
ports:
|
||||
keys:
|
||||
- input
|
||||
values:
|
||||
- _fieldName: input
|
||||
_node: {fileID: 114509033286994848}
|
||||
_typeQualifiedName: System.Object, mscorlib, Version=2.0.0.0, Culture=neutral,
|
||||
PublicKeyToken=b77a5c561934e089
|
||||
connections:
|
||||
- fieldName: vector
|
||||
node: {fileID: 114708853913061688}
|
||||
_direction: 0
|
||||
_connectionType: 1
|
||||
_dynamic: 1
|
||||
--- !u!114 &114511978881715272
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_PrefabParentObject: {fileID: 0}
|
||||
m_PrefabInternal: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 19e541bba2a188f4a84c6f3718ee6d55, type: 3}
|
||||
m_Name: MathNode
|
||||
m_EditorClassIdentifier:
|
||||
graph: {fileID: 11400000}
|
||||
position: {x: -472, y: -120}
|
||||
ports:
|
||||
keys:
|
||||
- a
|
||||
- b
|
||||
- result
|
||||
values:
|
||||
- _fieldName: a
|
||||
_node: {fileID: 114511978881715272}
|
||||
_typeQualifiedName: System.Single, mscorlib, Version=2.0.0.0, Culture=neutral,
|
||||
PublicKeyToken=b77a5c561934e089
|
||||
connections: []
|
||||
_direction: 0
|
||||
_connectionType: 0
|
||||
_dynamic: 0
|
||||
- _fieldName: b
|
||||
_node: {fileID: 114511978881715272}
|
||||
_typeQualifiedName: System.Single, mscorlib, Version=2.0.0.0, Culture=neutral,
|
||||
PublicKeyToken=b77a5c561934e089
|
||||
connections: []
|
||||
_direction: 0
|
||||
_connectionType: 0
|
||||
_dynamic: 0
|
||||
- _fieldName: result
|
||||
_node: {fileID: 114511978881715272}
|
||||
_typeQualifiedName: System.Single, mscorlib, Version=2.0.0.0, Culture=neutral,
|
||||
PublicKeyToken=b77a5c561934e089
|
||||
connections:
|
||||
- fieldName: x
|
||||
node: {fileID: 114708853913061688}
|
||||
- fieldName: input
|
||||
node: {fileID: 114245496101350052}
|
||||
_direction: 1
|
||||
_connectionType: 0
|
||||
_dynamic: 0
|
||||
a: 6.48
|
||||
b: 7.59
|
||||
result: 14.07
|
||||
mathType: 0
|
||||
--- !u!114 &114708853913061688
|
||||
- {fileID: 114652361136345764}
|
||||
- {fileID: 114067149339165002}
|
||||
- {fileID: 114441428018438906}
|
||||
- {fileID: 114775482956350040}
|
||||
--- !u!114 &114067149339165002
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_PrefabParentObject: {fileID: 0}
|
||||
@ -133,7 +28,7 @@ MonoBehaviour:
|
||||
m_Name: Vector
|
||||
m_EditorClassIdentifier:
|
||||
graph: {fileID: 11400000}
|
||||
position: {x: -168, y: -120}
|
||||
position: {x: -136, y: -136}
|
||||
ports:
|
||||
keys:
|
||||
- x
|
||||
@ -142,25 +37,27 @@ MonoBehaviour:
|
||||
- vector
|
||||
values:
|
||||
- _fieldName: x
|
||||
_node: {fileID: 114708853913061688}
|
||||
_node: {fileID: 114067149339165002}
|
||||
_typeQualifiedName: System.Single, mscorlib, Version=2.0.0.0, Culture=neutral,
|
||||
PublicKeyToken=b77a5c561934e089
|
||||
connections:
|
||||
- fieldName: result
|
||||
node: {fileID: 114511978881715272}
|
||||
node: {fileID: 114652361136345764}
|
||||
_direction: 0
|
||||
_connectionType: 0
|
||||
_dynamic: 0
|
||||
- _fieldName: y
|
||||
_node: {fileID: 114708853913061688}
|
||||
_node: {fileID: 114067149339165002}
|
||||
_typeQualifiedName: System.Single, mscorlib, Version=2.0.0.0, Culture=neutral,
|
||||
PublicKeyToken=b77a5c561934e089
|
||||
connections: []
|
||||
connections:
|
||||
- fieldName: result
|
||||
node: {fileID: 114775482956350040}
|
||||
_direction: 0
|
||||
_connectionType: 0
|
||||
_dynamic: 0
|
||||
- _fieldName: z
|
||||
_node: {fileID: 114708853913061688}
|
||||
_node: {fileID: 114067149339165002}
|
||||
_typeQualifiedName: System.Single, mscorlib, Version=2.0.0.0, Culture=neutral,
|
||||
PublicKeyToken=b77a5c561934e089
|
||||
connections: []
|
||||
@ -168,16 +65,141 @@ MonoBehaviour:
|
||||
_connectionType: 0
|
||||
_dynamic: 0
|
||||
- _fieldName: vector
|
||||
_node: {fileID: 114708853913061688}
|
||||
_node: {fileID: 114067149339165002}
|
||||
_typeQualifiedName: UnityEngine.Vector3, UnityEngine.CoreModule, Version=0.0.0.0,
|
||||
Culture=neutral, PublicKeyToken=null
|
||||
connections:
|
||||
- fieldName: input
|
||||
node: {fileID: 114509033286994848}
|
||||
node: {fileID: 114441428018438906}
|
||||
_direction: 1
|
||||
_connectionType: 0
|
||||
_dynamic: 0
|
||||
x: 0
|
||||
y: 2.6412349
|
||||
z: 14.33477
|
||||
vector: {x: 14.07, y: 2.6412349, z: 14.33477}
|
||||
y: 0
|
||||
z: 0
|
||||
vector: {x: -0.22000003, y: 2.14, z: 0}
|
||||
--- !u!114 &114441428018438906
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_PrefabParentObject: {fileID: 0}
|
||||
m_PrefabInternal: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 98f6f901f0da53142b79277ea3f42518, type: 3}
|
||||
m_Name: DisplayValue
|
||||
m_EditorClassIdentifier:
|
||||
graph: {fileID: 11400000}
|
||||
position: {x: 120, y: -88}
|
||||
ports:
|
||||
keys:
|
||||
- input
|
||||
values:
|
||||
- _fieldName: input
|
||||
_node: {fileID: 114441428018438906}
|
||||
_typeQualifiedName: XNode.Examples.MathNodes.DisplayValue+Anything, Assembly-CSharp,
|
||||
Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
|
||||
connections:
|
||||
- fieldName: vector
|
||||
node: {fileID: 114067149339165002}
|
||||
_direction: 0
|
||||
_connectionType: 1
|
||||
_dynamic: 0
|
||||
--- !u!114 &114652361136345764
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_PrefabParentObject: {fileID: 0}
|
||||
m_PrefabInternal: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 19e541bba2a188f4a84c6f3718ee6d55, type: 3}
|
||||
m_Name: MathNode
|
||||
m_EditorClassIdentifier:
|
||||
graph: {fileID: 11400000}
|
||||
position: {x: -392, y: -232}
|
||||
ports:
|
||||
keys:
|
||||
- a
|
||||
- b
|
||||
- result
|
||||
values:
|
||||
- _fieldName: a
|
||||
_node: {fileID: 114652361136345764}
|
||||
_typeQualifiedName: System.Single, mscorlib, Version=2.0.0.0, Culture=neutral,
|
||||
PublicKeyToken=b77a5c561934e089
|
||||
connections: []
|
||||
_direction: 0
|
||||
_connectionType: 0
|
||||
_dynamic: 0
|
||||
- _fieldName: b
|
||||
_node: {fileID: 114652361136345764}
|
||||
_typeQualifiedName: System.Single, mscorlib, Version=2.0.0.0, Culture=neutral,
|
||||
PublicKeyToken=b77a5c561934e089
|
||||
connections: []
|
||||
_direction: 0
|
||||
_connectionType: 0
|
||||
_dynamic: 0
|
||||
- _fieldName: result
|
||||
_node: {fileID: 114652361136345764}
|
||||
_typeQualifiedName: System.Single, mscorlib, Version=2.0.0.0, Culture=neutral,
|
||||
PublicKeyToken=b77a5c561934e089
|
||||
connections:
|
||||
- fieldName: x
|
||||
node: {fileID: 114067149339165002}
|
||||
_direction: 1
|
||||
_connectionType: 0
|
||||
_dynamic: 0
|
||||
a: 0.32
|
||||
b: 0.54
|
||||
result: -0.22000003
|
||||
mathType: 1
|
||||
--- !u!114 &114775482956350040
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_PrefabParentObject: {fileID: 0}
|
||||
m_PrefabInternal: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 19e541bba2a188f4a84c6f3718ee6d55, type: 3}
|
||||
m_Name: Math Node
|
||||
m_EditorClassIdentifier:
|
||||
graph: {fileID: 11400000}
|
||||
position: {x: -392, y: -72}
|
||||
ports:
|
||||
keys:
|
||||
- a
|
||||
- b
|
||||
- result
|
||||
values:
|
||||
- _fieldName: a
|
||||
_node: {fileID: 114775482956350040}
|
||||
_typeQualifiedName: System.Single, mscorlib, Version=2.0.0.0, Culture=neutral,
|
||||
PublicKeyToken=b77a5c561934e089
|
||||
connections: []
|
||||
_direction: 0
|
||||
_connectionType: 0
|
||||
_dynamic: 0
|
||||
- _fieldName: b
|
||||
_node: {fileID: 114775482956350040}
|
||||
_typeQualifiedName: System.Single, mscorlib, Version=2.0.0.0, Culture=neutral,
|
||||
PublicKeyToken=b77a5c561934e089
|
||||
connections: []
|
||||
_direction: 0
|
||||
_connectionType: 0
|
||||
_dynamic: 0
|
||||
- _fieldName: result
|
||||
_node: {fileID: 114775482956350040}
|
||||
_typeQualifiedName: System.Single, mscorlib, Version=2.0.0.0, Culture=neutral,
|
||||
PublicKeyToken=b77a5c561934e089
|
||||
connections:
|
||||
- fieldName: y
|
||||
node: {fileID: 114067149339165002}
|
||||
_direction: 1
|
||||
_connectionType: 0
|
||||
_dynamic: 0
|
||||
a: 0.81
|
||||
b: 1.33
|
||||
result: 2.14
|
||||
mathType: 0
|
||||
@ -1,6 +1,6 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cee47fa32ae90bb4f8f0bec6f186cb3b
|
||||
timeCreated: 1509308927
|
||||
guid: 97b11561dfa2a2646a1217518e90411b
|
||||
timeCreated: 1516179614
|
||||
licenseType: Free
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
20
Examples/MathGraph/Nodes/DisplayValue.cs
Normal file
20
Examples/MathGraph/Nodes/DisplayValue.cs
Normal file
@ -0,0 +1,20 @@
|
||||
namespace XNode.Examples.MathNodes {
|
||||
|
||||
public class DisplayValue : XNode.Node {
|
||||
|
||||
/// <summary>
|
||||
/// Create an input port that only allows a single connection.
|
||||
/// The backing value is not important, as we are only interested in the input value.
|
||||
/// We are also acceptable of all input types, so any type will do, as long as it is serializable.
|
||||
/// </summary>
|
||||
[Input(ShowBackingValue.Never, ConnectionType.Override)] public Anything input;
|
||||
|
||||
/// <summary> Get the value currently plugged in to this node </summary>
|
||||
public object GetValue() {
|
||||
return GetInputValue<object>("input");
|
||||
}
|
||||
|
||||
/// <summary> This class is defined for the sole purpose of being serializable </summary>
|
||||
[System.Serializable] public class Anything {}
|
||||
}
|
||||
}
|
||||
27
Examples/MathGraph/Nodes/Editor/DisplayValueEditor.cs
Normal file
27
Examples/MathGraph/Nodes/Editor/DisplayValueEditor.cs
Normal file
@ -0,0 +1,27 @@
|
||||
using UnityEditor;
|
||||
using XNode.Examples.MathNodes;
|
||||
|
||||
namespace XNodeEditor.Examples {
|
||||
|
||||
/// <summary>
|
||||
/// NodeEditor functions similarly to the Editor class, only it is xNode specific.
|
||||
/// Custom node editors should have the CustomNodeEditor attribute that defines which node type it is an editor for.
|
||||
/// </summary>
|
||||
[CustomNodeEditor(typeof(DisplayValue))]
|
||||
public class DisplayValueEditor : NodeEditor {
|
||||
|
||||
/// <summary> Called whenever the xNode editor window is updated </summary>
|
||||
public override void OnBodyGUI() {
|
||||
|
||||
// Draw the default GUI first, so we don't have to do all of that manually.
|
||||
base.OnBodyGUI();
|
||||
|
||||
// `target` points to the node, but it is of type `Node`, so cast it.
|
||||
DisplayValue displayValueNode = target as DisplayValue;
|
||||
|
||||
// Get the value from the node, and display it
|
||||
object obj = displayValueNode.GetValue();
|
||||
if (obj != null) EditorGUILayout.LabelField(obj.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,4 @@
|
||||
using XNode;
|
||||
|
||||
namespace BasicNodes {
|
||||
namespace XNode.Examples.MathNodes {
|
||||
[System.Serializable]
|
||||
public class MathNode : XNode.Node {
|
||||
// Adding [Input] or [Output] is all you need to do to register a field as a valid port on your node
|
||||
@ -1,7 +1,6 @@
|
||||
using UnityEngine;
|
||||
using XNode;
|
||||
|
||||
namespace BasicNodes {
|
||||
namespace XNode.Examples.MathNodes {
|
||||
public class Vector : XNode.Node {
|
||||
[Input] public float x, y, z;
|
||||
[Output] public Vector3 vector;
|
||||
10
Examples/StateMachine.meta
Normal file
10
Examples/StateMachine.meta
Normal file
@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e8aa31d972c52204dbdcf109681928c8
|
||||
folderAsset: yes
|
||||
timeCreated: 1516177052
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
10
Examples/StateMachine/Editor.meta
Normal file
10
Examples/StateMachine/Editor.meta
Normal file
@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9abb31871fcc4b840baedb640fb6815e
|
||||
folderAsset: yes
|
||||
timeCreated: 1516181202
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
21
Examples/StateMachine/Editor/StateGraphEditor.cs
Normal file
21
Examples/StateMachine/Editor/StateGraphEditor.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using XNode.Examples.StateGraph;
|
||||
using XNodeEditor;
|
||||
|
||||
namespace XNodeEditor.Examples {
|
||||
[CustomNodeGraphEditor(typeof(StateGraph))]
|
||||
public class StateGraphEditor : NodeGraphEditor {
|
||||
|
||||
/// <summary>
|
||||
/// Overriding GetNodePath 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 GetNodePath(System.Type type) {
|
||||
if (type.Namespace == "XNode.Examples.StateGraph") {
|
||||
return base.GetNodePath(type).Replace("X Node/Examples/State Graph/", "");
|
||||
} else return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
13
Examples/StateMachine/Editor/StateGraphEditor.cs.meta
Normal file
13
Examples/StateMachine/Editor/StateGraphEditor.cs.meta
Normal file
@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c46ac2790aeee7341998d217311ba8d3
|
||||
timeCreated: 1516181207
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
128
Examples/StateMachine/New State Graph.asset
Normal file
128
Examples/StateMachine/New State Graph.asset
Normal file
@ -0,0 +1,128 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!114 &11400000
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_PrefabParentObject: {fileID: 0}
|
||||
m_PrefabInternal: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: dad9e75908d47ae419dba5bc800df549, type: 3}
|
||||
m_Name: New State Graph
|
||||
m_EditorClassIdentifier:
|
||||
nodes:
|
||||
- {fileID: 114319284393922042}
|
||||
- {fileID: 114471802820302434}
|
||||
- {fileID: 114232340257100334}
|
||||
current: {fileID: 114232340257100334}
|
||||
--- !u!114 &114232340257100334
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_PrefabParentObject: {fileID: 0}
|
||||
m_PrefabInternal: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 32ef86e1b73c7d642acaa1b75f66bbbb, type: 3}
|
||||
m_Name: State Node
|
||||
m_EditorClassIdentifier:
|
||||
graph: {fileID: 11400000}
|
||||
position: {x: -248, y: -392}
|
||||
ports:
|
||||
keys:
|
||||
- enter
|
||||
- exit
|
||||
values:
|
||||
- _fieldName: enter
|
||||
_node: {fileID: 114232340257100334}
|
||||
_typeQualifiedName: XNode.Examples.StateGraph.StateNode+Empty, Assembly-CSharp,
|
||||
Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
|
||||
connections: []
|
||||
_direction: 0
|
||||
_connectionType: 0
|
||||
_dynamic: 0
|
||||
- _fieldName: exit
|
||||
_node: {fileID: 114232340257100334}
|
||||
_typeQualifiedName: XNode.Examples.StateGraph.StateNode+Empty, Assembly-CSharp,
|
||||
Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
|
||||
connections:
|
||||
- fieldName: enter
|
||||
node: {fileID: 114319284393922042}
|
||||
_direction: 1
|
||||
_connectionType: 0
|
||||
_dynamic: 0
|
||||
--- !u!114 &114319284393922042
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_PrefabParentObject: {fileID: 0}
|
||||
m_PrefabInternal: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 32ef86e1b73c7d642acaa1b75f66bbbb, type: 3}
|
||||
m_Name: State Node
|
||||
m_EditorClassIdentifier:
|
||||
graph: {fileID: 11400000}
|
||||
position: {x: -392, y: -168}
|
||||
ports:
|
||||
keys:
|
||||
- enter
|
||||
- exit
|
||||
values:
|
||||
- _fieldName: enter
|
||||
_node: {fileID: 114319284393922042}
|
||||
_typeQualifiedName: XNode.Examples.StateGraph.StateNode+Empty, Assembly-CSharp,
|
||||
Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
|
||||
connections:
|
||||
- fieldName: exit
|
||||
node: {fileID: 114232340257100334}
|
||||
_direction: 0
|
||||
_connectionType: 0
|
||||
_dynamic: 0
|
||||
- _fieldName: exit
|
||||
_node: {fileID: 114319284393922042}
|
||||
_typeQualifiedName: XNode.Examples.StateGraph.StateNode+Empty, Assembly-CSharp,
|
||||
Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
|
||||
connections:
|
||||
- fieldName: enter
|
||||
node: {fileID: 114471802820302434}
|
||||
_direction: 1
|
||||
_connectionType: 0
|
||||
_dynamic: 0
|
||||
--- !u!114 &114471802820302434
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_PrefabParentObject: {fileID: 0}
|
||||
m_PrefabInternal: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 32ef86e1b73c7d642acaa1b75f66bbbb, type: 3}
|
||||
m_Name: State Node
|
||||
m_EditorClassIdentifier:
|
||||
graph: {fileID: 11400000}
|
||||
position: {x: -56, y: -168}
|
||||
ports:
|
||||
keys:
|
||||
- enter
|
||||
- exit
|
||||
values:
|
||||
- _fieldName: enter
|
||||
_node: {fileID: 114471802820302434}
|
||||
_typeQualifiedName: XNode.Examples.StateGraph.StateNode+Empty, Assembly-CSharp,
|
||||
Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
|
||||
connections:
|
||||
- fieldName: exit
|
||||
node: {fileID: 114319284393922042}
|
||||
_direction: 0
|
||||
_connectionType: 0
|
||||
_dynamic: 0
|
||||
- _fieldName: exit
|
||||
_node: {fileID: 114471802820302434}
|
||||
_typeQualifiedName: XNode.Examples.StateGraph.StateNode+Empty, Assembly-CSharp,
|
||||
Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
|
||||
connections: []
|
||||
_direction: 1
|
||||
_connectionType: 0
|
||||
_dynamic: 0
|
||||
10
Examples/StateMachine/New State Graph.asset.meta
Normal file
10
Examples/StateMachine/New State Graph.asset.meta
Normal file
@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 18b73d7e492ac594886d6afd816395ec
|
||||
timeCreated: 1516181166
|
||||
licenseType: Free
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
10
Examples/StateMachine/Nodes.meta
Normal file
10
Examples/StateMachine/Nodes.meta
Normal file
@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1e4f25b00cb54f84c82e84af31c8e056
|
||||
folderAsset: yes
|
||||
timeCreated: 1514505844
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
10
Examples/StateMachine/Nodes/Editor.meta
Normal file
10
Examples/StateMachine/Nodes/Editor.meta
Normal file
@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 61176f710e9af264db5db0a81711f423
|
||||
folderAsset: yes
|
||||
timeCreated: 1514506327
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
30
Examples/StateMachine/Nodes/Editor/StateNodeEditor.cs
Normal file
30
Examples/StateMachine/Nodes/Editor/StateNodeEditor.cs
Normal file
@ -0,0 +1,30 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using XNode.Examples.StateGraph;
|
||||
|
||||
namespace XNodeEditor.Examples {
|
||||
[CustomNodeEditor(typeof(StateNode))]
|
||||
public class StateNodeEditor : NodeEditor {
|
||||
|
||||
public override void OnHeaderGUI() {
|
||||
GUI.color = Color.white;
|
||||
StateNode node = target as StateNode;
|
||||
StateGraph graph = node.graph as StateGraph;
|
||||
if (graph.current == node) GUI.color = Color.blue;
|
||||
string title = target.name;
|
||||
GUILayout.Label(title, NodeEditorResources.styles.nodeHeader, GUILayout.Height(30));
|
||||
GUI.color = Color.white;
|
||||
}
|
||||
|
||||
public override void OnBodyGUI() {
|
||||
base.OnBodyGUI();
|
||||
StateNode node = target as StateNode;
|
||||
StateGraph graph = node.graph as StateGraph;
|
||||
if (GUILayout.Button("MoveNext Node")) node.MoveNext();
|
||||
if (GUILayout.Button("Continue Graph")) graph.Continue();
|
||||
if (GUILayout.Button("Set as current")) graph.current = node;
|
||||
}
|
||||
}
|
||||
}
|
||||
13
Examples/StateMachine/Nodes/Editor/StateNodeEditor.cs.meta
Normal file
13
Examples/StateMachine/Nodes/Editor/StateNodeEditor.cs.meta
Normal file
@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f59d4dfd6e73e6b4d9d14256bc7a20f3
|
||||
timeCreated: 1514506333
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
39
Examples/StateMachine/Nodes/StateNode.cs
Normal file
39
Examples/StateMachine/Nodes/StateNode.cs
Normal file
@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace XNode.Examples.StateGraph {
|
||||
public class StateNode : Node {
|
||||
|
||||
[Input] public Empty enter;
|
||||
[Output] public Empty exit;
|
||||
|
||||
public void MoveNext() {
|
||||
StateGraph fmGraph = graph as StateGraph;
|
||||
|
||||
if (fmGraph.current != this) {
|
||||
Debug.LogWarning("Node isn't active");
|
||||
return;
|
||||
}
|
||||
|
||||
NodePort exitPort = GetOutputPort("exit");
|
||||
|
||||
if (!exitPort.IsConnected) {
|
||||
Debug.LogWarning("Node isn't connected");
|
||||
return;
|
||||
}
|
||||
|
||||
StateNode node = exitPort.Connection.node as StateNode;
|
||||
node.OnEnter();
|
||||
}
|
||||
|
||||
public void OnEnter() {
|
||||
StateGraph fmGraph = graph as StateGraph;
|
||||
fmGraph.current = this;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class Empty { }
|
||||
}
|
||||
}
|
||||
13
Examples/StateMachine/Nodes/StateNode.cs.meta
Normal file
13
Examples/StateMachine/Nodes/StateNode.cs.meta
Normal file
@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 32ef86e1b73c7d642acaa1b75f66bbbb
|
||||
timeCreated: 1514505861
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
14
Examples/StateMachine/README.md
Normal file
14
Examples/StateMachine/README.md
Normal file
@ -0,0 +1,14 @@
|
||||
[](https://discord.gg/qgPrHv4)
|
||||
[](https://github.com/Siccity/xNode/issues)
|
||||
[](https://raw.githubusercontent.com/Siccity/xNode/master/LICENSE.md)
|
||||
[](https://github.com/Siccity/xNode/wiki)
|
||||
|
||||
[Go to Downloads](https://github.com/Siccity/xNode/releases)
|
||||
|
||||
### xNode State Machine (Example)
|
||||
This example project should give you an understanding of how to handle traversing through nodes, one by one.
|
||||
The same principle can be applied to dialogue graphs, and other simple decision makers.
|
||||
|
||||
|
||||
Join the [Discord](https://discord.gg/qgPrHv4 "Join Discord server") server to leave feedback or get support.
|
||||
Feel free to also leave suggestions/requests in the [issues](https://github.com/Siccity/xNode/issues "Go to Issues") page.
|
||||
16
Examples/StateMachine/StateGraph.cs
Normal file
16
Examples/StateMachine/StateGraph.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace XNode.Examples.StateGraph {
|
||||
[CreateAssetMenu(fileName = "New State Graph", menuName = "xNode Examples/State Graph")]
|
||||
public class StateGraph : NodeGraph {
|
||||
|
||||
// The current "active" node
|
||||
public StateNode current;
|
||||
|
||||
public void Continue() {
|
||||
current.MoveNext();
|
||||
}
|
||||
}
|
||||
}
|
||||
13
Examples/StateMachine/StateGraph.cs.meta
Normal file
13
Examples/StateMachine/StateGraph.cs.meta
Normal file
@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dad9e75908d47ae419dba5bc800df549
|
||||
timeCreated: 1514505839
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Loading…
x
Reference in New Issue
Block a user