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/StateMachine | |
parent | c92269331692feca2c276649f6c4ee8911f1f859 (diff) |
+node example
Diffstat (limited to 'Other/NodeEditorExamples/Assets/xNode-examples/Examples/StateMachine')
15 files changed, 449 insertions, 0 deletions
diff --git a/Other/NodeEditorExamples/Assets/xNode-examples/Examples/StateMachine/Editor.meta b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/StateMachine/Editor.meta new file mode 100644 index 00000000..598278ae --- /dev/null +++ b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/StateMachine/Editor.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: 9abb31871fcc4b840baedb640fb6815e +folderAsset: yes +timeCreated: 1516181202 +licenseType: Free +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Other/NodeEditorExamples/Assets/xNode-examples/Examples/StateMachine/Editor/StateGraphEditor.cs b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/StateMachine/Editor/StateGraphEditor.cs new file mode 100644 index 00000000..cbc810a7 --- /dev/null +++ b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/StateMachine/Editor/StateGraphEditor.cs @@ -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 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.StateGraph") { + return base.GetNodeMenuName(type).Replace("X Node/Examples/State Graph/", ""); + } else return null; + } + } +}
\ No newline at end of file diff --git a/Other/NodeEditorExamples/Assets/xNode-examples/Examples/StateMachine/Editor/StateGraphEditor.cs.meta b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/StateMachine/Editor/StateGraphEditor.cs.meta new file mode 100644 index 00000000..5a85ea07 --- /dev/null +++ b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/StateMachine/Editor/StateGraphEditor.cs.meta @@ -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: diff --git a/Other/NodeEditorExamples/Assets/xNode-examples/Examples/StateMachine/New State Graph.asset b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/StateMachine/New State Graph.asset new file mode 100644 index 00000000..00465c33 --- /dev/null +++ b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/StateMachine/New State Graph.asset @@ -0,0 +1,230 @@ +%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: dad9e75908d47ae419dba5bc800df549, type: 3} + m_Name: New State Graph + m_EditorClassIdentifier: + nodes: + - {fileID: 114319284393922042} + - {fileID: 114471802820302434} + - {fileID: 114232340257100334} + - {fileID: 114484137410015790} + - {fileID: 114067607725051884} + current: {fileID: 114471802820302434} +--- !u!114 &114067607725051884 +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: 32ef86e1b73c7d642acaa1b75f66bbbb, type: 3} + m_Name: State + m_EditorClassIdentifier: + graph: {fileID: 11400000} + position: {x: 296, y: -184} + ports: + keys: + - enter + - exit + values: + - _fieldName: enter + _node: {fileID: 114067607725051884} + _typeQualifiedName: XNode.Examples.StateGraph.StateNode+Empty, Assembly-CSharp, + Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + connections: + - fieldName: exit + node: {fileID: 114484137410015790} + reroutePoints: [] + _direction: 0 + _connectionType: 0 + _typeConstraint: 0 + _dynamic: 0 + - _fieldName: exit + _node: {fileID: 114067607725051884} + _typeQualifiedName: XNode.Examples.StateGraph.StateNode+Empty, Assembly-CSharp, + Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + connections: [] + _direction: 1 + _connectionType: 0 + _typeConstraint: 0 + _dynamic: 0 +--- !u!114 &114232340257100334 +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: 32ef86e1b73c7d642acaa1b75f66bbbb, type: 3} + m_Name: State Node + m_EditorClassIdentifier: + graph: {fileID: 11400000} + position: {x: -584, y: -328} + ports: + keys: + - enter + - exit + values: + - _fieldName: enter + _node: {fileID: 114232340257100334} + _typeQualifiedName: XNode.Examples.StateGraph.StateNode+Empty, Assembly-CSharp, + Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + connections: [] + _direction: 0 + _connectionType: 0 + _typeConstraint: 0 + _dynamic: 0 + - _fieldName: exit + _node: {fileID: 114232340257100334} + _typeQualifiedName: XNode.Examples.StateGraph.StateNode+Empty, Assembly-CSharp, + Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + connections: + - fieldName: enter + node: {fileID: 114319284393922042} + reroutePoints: [] + _direction: 1 + _connectionType: 0 + _typeConstraint: 0 + _dynamic: 0 +--- !u!114 &114319284393922042 +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: 32ef86e1b73c7d642acaa1b75f66bbbb, type: 3} + m_Name: State Node + m_EditorClassIdentifier: + graph: {fileID: 11400000} + position: {x: -296, y: -328} + ports: + keys: + - enter + - exit + values: + - _fieldName: enter + _node: {fileID: 114319284393922042} + _typeQualifiedName: XNode.Examples.StateGraph.StateNode+Empty, Assembly-CSharp, + Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + connections: + - fieldName: exit + node: {fileID: 114232340257100334} + reroutePoints: [] + _direction: 0 + _connectionType: 0 + _typeConstraint: 0 + _dynamic: 0 + - _fieldName: exit + _node: {fileID: 114319284393922042} + _typeQualifiedName: XNode.Examples.StateGraph.StateNode+Empty, Assembly-CSharp, + Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + connections: + - fieldName: enter + node: {fileID: 114471802820302434} + reroutePoints: [] + - fieldName: enter + node: {fileID: 114484137410015790} + reroutePoints: [] + _direction: 1 + _connectionType: 0 + _typeConstraint: 0 + _dynamic: 0 +--- !u!114 &114471802820302434 +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: 32ef86e1b73c7d642acaa1b75f66bbbb, type: 3} + m_Name: State Node + m_EditorClassIdentifier: + graph: {fileID: 11400000} + position: {x: 8, y: -424} + ports: + keys: + - enter + - exit + values: + - _fieldName: enter + _node: {fileID: 114471802820302434} + _typeQualifiedName: XNode.Examples.StateGraph.StateNode+Empty, Assembly-CSharp, + Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + connections: + - fieldName: exit + node: {fileID: 114319284393922042} + reroutePoints: [] + _direction: 0 + _connectionType: 0 + _typeConstraint: 0 + _dynamic: 0 + - _fieldName: exit + _node: {fileID: 114471802820302434} + _typeQualifiedName: XNode.Examples.StateGraph.StateNode+Empty, Assembly-CSharp, + Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + connections: [] + _direction: 1 + _connectionType: 0 + _typeConstraint: 0 + _dynamic: 0 +--- !u!114 &114484137410015790 +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: 32ef86e1b73c7d642acaa1b75f66bbbb, type: 3} + m_Name: State + m_EditorClassIdentifier: + graph: {fileID: 11400000} + position: {x: 8, y: -184} + ports: + keys: + - enter + - exit + values: + - _fieldName: enter + _node: {fileID: 114484137410015790} + _typeQualifiedName: XNode.Examples.StateGraph.StateNode+Empty, Assembly-CSharp, + Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + connections: + - fieldName: exit + node: {fileID: 114319284393922042} + reroutePoints: [] + _direction: 0 + _connectionType: 0 + _typeConstraint: 0 + _dynamic: 0 + - _fieldName: exit + _node: {fileID: 114484137410015790} + _typeQualifiedName: XNode.Examples.StateGraph.StateNode+Empty, Assembly-CSharp, + Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + connections: + - fieldName: enter + node: {fileID: 114067607725051884} + reroutePoints: [] + _direction: 1 + _connectionType: 0 + _typeConstraint: 0 + _dynamic: 0 diff --git a/Other/NodeEditorExamples/Assets/xNode-examples/Examples/StateMachine/New State Graph.asset.meta b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/StateMachine/New State Graph.asset.meta new file mode 100644 index 00000000..5513aaca --- /dev/null +++ b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/StateMachine/New State Graph.asset.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: 18b73d7e492ac594886d6afd816395ec +timeCreated: 1516181166 +licenseType: Free +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Other/NodeEditorExamples/Assets/xNode-examples/Examples/StateMachine/Nodes.meta b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/StateMachine/Nodes.meta new file mode 100644 index 00000000..7854c232 --- /dev/null +++ b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/StateMachine/Nodes.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: 1e4f25b00cb54f84c82e84af31c8e056 +folderAsset: yes +timeCreated: 1514505844 +licenseType: Free +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Other/NodeEditorExamples/Assets/xNode-examples/Examples/StateMachine/Nodes/Editor.meta b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/StateMachine/Nodes/Editor.meta new file mode 100644 index 00000000..cb4202f6 --- /dev/null +++ b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/StateMachine/Nodes/Editor.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: 61176f710e9af264db5db0a81711f423 +folderAsset: yes +timeCreated: 1514506327 +licenseType: Free +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Other/NodeEditorExamples/Assets/xNode-examples/Examples/StateMachine/Nodes/Editor/StateNodeEditor.cs b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/StateMachine/Nodes/Editor/StateNodeEditor.cs new file mode 100644 index 00000000..f9d6b9eb --- /dev/null +++ b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/StateMachine/Nodes/Editor/StateNodeEditor.cs @@ -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; + } + } +}
\ No newline at end of file diff --git a/Other/NodeEditorExamples/Assets/xNode-examples/Examples/StateMachine/Nodes/Editor/StateNodeEditor.cs.meta b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/StateMachine/Nodes/Editor/StateNodeEditor.cs.meta new file mode 100644 index 00000000..e5414c99 --- /dev/null +++ b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/StateMachine/Nodes/Editor/StateNodeEditor.cs.meta @@ -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: diff --git a/Other/NodeEditorExamples/Assets/xNode-examples/Examples/StateMachine/Nodes/StateNode.cs b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/StateMachine/Nodes/StateNode.cs new file mode 100644 index 00000000..2bb7dc03 --- /dev/null +++ b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/StateMachine/Nodes/StateNode.cs @@ -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 { } + } +}
\ No newline at end of file diff --git a/Other/NodeEditorExamples/Assets/xNode-examples/Examples/StateMachine/Nodes/StateNode.cs.meta b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/StateMachine/Nodes/StateNode.cs.meta new file mode 100644 index 00000000..04432757 --- /dev/null +++ b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/StateMachine/Nodes/StateNode.cs.meta @@ -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: diff --git a/Other/NodeEditorExamples/Assets/xNode-examples/Examples/StateMachine/README.md b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/StateMachine/README.md new file mode 100644 index 00000000..8e7aa3e0 --- /dev/null +++ b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/StateMachine/README.md @@ -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. diff --git a/Other/NodeEditorExamples/Assets/xNode-examples/Examples/StateMachine/README.md.meta b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/StateMachine/README.md.meta new file mode 100644 index 00000000..255080c3 --- /dev/null +++ b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/StateMachine/README.md.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 942cd94b8baa8d4419d3d7da96deb5fa +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Other/NodeEditorExamples/Assets/xNode-examples/Examples/StateMachine/StateGraph.cs b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/StateMachine/StateGraph.cs new file mode 100644 index 00000000..8a136c27 --- /dev/null +++ b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/StateMachine/StateGraph.cs @@ -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(); + } + } +}
\ No newline at end of file diff --git a/Other/NodeEditorExamples/Assets/xNode-examples/Examples/StateMachine/StateGraph.cs.meta b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/StateMachine/StateGraph.cs.meta new file mode 100644 index 00000000..8e83d937 --- /dev/null +++ b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/StateMachine/StateGraph.cs.meta @@ -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: |