diff options
Diffstat (limited to 'Other/NodeEditorExamples/Assets/xNode-examples/Examples/MathGraph')
17 files changed, 471 insertions, 0 deletions
diff --git a/Other/NodeEditorExamples/Assets/xNode-examples/Examples/MathGraph/Editor.meta b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/MathGraph/Editor.meta new file mode 100644 index 00000000..be3526da --- /dev/null +++ b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/MathGraph/Editor.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: 642e362943557314392fc62290a8e242 +folderAsset: yes +timeCreated: 1516180279 +licenseType: Free +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Other/NodeEditorExamples/Assets/xNode-examples/Examples/MathGraph/Editor/MathGraphEditor.cs b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/MathGraph/Editor/MathGraphEditor.cs new file mode 100644 index 00000000..7a580bfe --- /dev/null +++ b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/MathGraph/Editor/MathGraphEditor.cs @@ -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 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.MathNodes") { + return base.GetNodeMenuName(type).Replace("X Node/Examples/Math Nodes/", ""); + } else return null; + } + } +}
\ No newline at end of file diff --git a/Other/NodeEditorExamples/Assets/xNode-examples/Examples/MathGraph/Editor/MathGraphEditor.cs.meta b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/MathGraph/Editor/MathGraphEditor.cs.meta new file mode 100644 index 00000000..89bd3df7 --- /dev/null +++ b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/MathGraph/Editor/MathGraphEditor.cs.meta @@ -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: diff --git a/Other/NodeEditorExamples/Assets/xNode-examples/Examples/MathGraph/MathGraph.cs b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/MathGraph/MathGraph.cs new file mode 100644 index 00000000..420ce64e --- /dev/null +++ b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/MathGraph/MathGraph.cs @@ -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 { } +}
\ No newline at end of file diff --git a/Other/NodeEditorExamples/Assets/xNode-examples/Examples/MathGraph/MathGraph.cs.meta b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/MathGraph/MathGraph.cs.meta new file mode 100644 index 00000000..43c9d35d --- /dev/null +++ b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/MathGraph/MathGraph.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: a6399826e2c44b447b32a3ed06646162 +timeCreated: 1506460823 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Other/NodeEditorExamples/Assets/xNode-examples/Examples/MathGraph/New Math Graph.asset b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/MathGraph/New Math Graph.asset new file mode 100644 index 00000000..45efea59 --- /dev/null +++ b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/MathGraph/New Math Graph.asset @@ -0,0 +1,233 @@ +%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: a6399826e2c44b447b32a3ed06646162, type: 3} + m_Name: New Math Graph + m_EditorClassIdentifier: + nodes: + - {fileID: 114652361136345764} + - {fileID: 114067149339165002} + - {fileID: 114441428018438906} + - {fileID: 114775482956350040} +--- !u!114 &114067149339165002 +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: 05559f4106850df4ab41776666216480, type: 3} + m_Name: Vector + m_EditorClassIdentifier: + graph: {fileID: 11400000} + position: {x: -24, y: -280} + ports: + keys: + - x + - y + - z + - vector + values: + - _fieldName: x + _node: {fileID: 114067149339165002} + _typeQualifiedName: System.Single, mscorlib, Version=4.0.0.0, Culture=neutral, + PublicKeyToken=b77a5c561934e089 + connections: + - fieldName: result + node: {fileID: 114652361136345764} + reroutePoints: [] + _direction: 0 + _connectionType: 0 + _typeConstraint: 0 + _dynamic: 0 + - _fieldName: y + _node: {fileID: 114067149339165002} + _typeQualifiedName: System.Single, mscorlib, Version=4.0.0.0, Culture=neutral, + PublicKeyToken=b77a5c561934e089 + connections: + - fieldName: result + node: {fileID: 114775482956350040} + reroutePoints: [] + _direction: 0 + _connectionType: 0 + _typeConstraint: 0 + _dynamic: 0 + - _fieldName: z + _node: {fileID: 114067149339165002} + _typeQualifiedName: System.Single, mscorlib, Version=4.0.0.0, Culture=neutral, + PublicKeyToken=b77a5c561934e089 + connections: + - fieldName: result + node: {fileID: 114775482956350040} + reroutePoints: [] + _direction: 0 + _connectionType: 0 + _typeConstraint: 0 + _dynamic: 0 + - _fieldName: vector + _node: {fileID: 114067149339165002} + _typeQualifiedName: UnityEngine.Vector3, UnityEngine.CoreModule, Version=0.0.0.0, + Culture=neutral, PublicKeyToken=null + connections: + - fieldName: input + node: {fileID: 114441428018438906} + reroutePoints: [] + _direction: 1 + _connectionType: 0 + _typeConstraint: 0 + _dynamic: 0 + x: 0 + y: 0 + z: 0 + vector: {x: -0.22000003, y: 2.14, z: 2.14} +--- !u!114 &114441428018438906 +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: 98f6f901f0da53142b79277ea3f42518, type: 3} + m_Name: DisplayValue + m_EditorClassIdentifier: + graph: {fileID: 11400000} + position: {x: 232, y: -312} + ports: + keys: + - input + values: + - _fieldName: input + _node: {fileID: 114441428018438906} + _typeQualifiedName: XNode.Examples.MathNodes.DisplayValue+Anything, Assembly-CSharp, + Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + connections: + - fieldName: vector + node: {fileID: 114067149339165002} + reroutePoints: [] + _direction: 0 + _connectionType: 1 + _typeConstraint: 0 + _dynamic: 0 +--- !u!114 &114652361136345764 +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: 19e541bba2a188f4a84c6f3718ee6d55, type: 3} + m_Name: MathNode + m_EditorClassIdentifier: + graph: {fileID: 11400000} + position: {x: -344, y: -376} + ports: + keys: + - a + - b + - result + values: + - _fieldName: a + _node: {fileID: 114652361136345764} + _typeQualifiedName: System.Single, mscorlib, Version=4.0.0.0, Culture=neutral, + PublicKeyToken=b77a5c561934e089 + connections: [] + _direction: 0 + _connectionType: 0 + _typeConstraint: 0 + _dynamic: 0 + - _fieldName: b + _node: {fileID: 114652361136345764} + _typeQualifiedName: System.Single, mscorlib, Version=4.0.0.0, Culture=neutral, + PublicKeyToken=b77a5c561934e089 + connections: [] + _direction: 0 + _connectionType: 0 + _typeConstraint: 0 + _dynamic: 0 + - _fieldName: result + _node: {fileID: 114652361136345764} + _typeQualifiedName: System.Single, mscorlib, Version=4.0.0.0, Culture=neutral, + PublicKeyToken=b77a5c561934e089 + connections: + - fieldName: x + node: {fileID: 114067149339165002} + reroutePoints: [] + _direction: 1 + _connectionType: 0 + _typeConstraint: 0 + _dynamic: 0 + a: 0.32 + b: 0.54 + result: -0.22000003 + mathType: 1 +--- !u!114 &114775482956350040 +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: 19e541bba2a188f4a84c6f3718ee6d55, type: 3} + m_Name: Math Node + m_EditorClassIdentifier: + graph: {fileID: 11400000} + position: {x: -344, y: -216} + ports: + keys: + - a + - b + - result + values: + - _fieldName: a + _node: {fileID: 114775482956350040} + _typeQualifiedName: System.Single, mscorlib, Version=4.0.0.0, Culture=neutral, + PublicKeyToken=b77a5c561934e089 + connections: [] + _direction: 0 + _connectionType: 0 + _typeConstraint: 0 + _dynamic: 0 + - _fieldName: b + _node: {fileID: 114775482956350040} + _typeQualifiedName: System.Single, mscorlib, Version=4.0.0.0, Culture=neutral, + PublicKeyToken=b77a5c561934e089 + connections: [] + _direction: 0 + _connectionType: 0 + _typeConstraint: 0 + _dynamic: 0 + - _fieldName: result + _node: {fileID: 114775482956350040} + _typeQualifiedName: System.Single, mscorlib, Version=4.0.0.0, Culture=neutral, + PublicKeyToken=b77a5c561934e089 + connections: + - fieldName: z + node: {fileID: 114067149339165002} + reroutePoints: [] + - fieldName: y + node: {fileID: 114067149339165002} + reroutePoints: [] + _direction: 1 + _connectionType: 0 + _typeConstraint: 0 + _dynamic: 0 + a: 0.81 + b: 1.33 + result: 2.14 + mathType: 0 diff --git a/Other/NodeEditorExamples/Assets/xNode-examples/Examples/MathGraph/New Math Graph.asset.meta b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/MathGraph/New Math Graph.asset.meta new file mode 100644 index 00000000..61fd97ef --- /dev/null +++ b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/MathGraph/New Math Graph.asset.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: 97b11561dfa2a2646a1217518e90411b +timeCreated: 1516179614 +licenseType: Free +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Other/NodeEditorExamples/Assets/xNode-examples/Examples/MathGraph/Nodes.meta b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/MathGraph/Nodes.meta new file mode 100644 index 00000000..0d29f0a0 --- /dev/null +++ b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/MathGraph/Nodes.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 31c1681f5df4f764ab4ca7f09cd3be7d +folderAsset: yes +timeCreated: 1505462700 +licenseType: Free +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Other/NodeEditorExamples/Assets/xNode-examples/Examples/MathGraph/Nodes/DisplayValue.cs b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/MathGraph/Nodes/DisplayValue.cs new file mode 100644 index 00000000..422c4c4d --- /dev/null +++ b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/MathGraph/Nodes/DisplayValue.cs @@ -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 {} + } +} diff --git a/Other/NodeEditorExamples/Assets/xNode-examples/Examples/MathGraph/Nodes/DisplayValue.cs.meta b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/MathGraph/Nodes/DisplayValue.cs.meta new file mode 100644 index 00000000..aa380ead --- /dev/null +++ b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/MathGraph/Nodes/DisplayValue.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 98f6f901f0da53142b79277ea3f42518 +timeCreated: 1507499149 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Other/NodeEditorExamples/Assets/xNode-examples/Examples/MathGraph/Nodes/Editor.meta b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/MathGraph/Nodes/Editor.meta new file mode 100644 index 00000000..10088178 --- /dev/null +++ b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/MathGraph/Nodes/Editor.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: 0d2300267781fed46a6d964565309cbf +folderAsset: yes +timeCreated: 1509307735 +licenseType: Free +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Other/NodeEditorExamples/Assets/xNode-examples/Examples/MathGraph/Nodes/Editor/DisplayValueEditor.cs b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/MathGraph/Nodes/Editor/DisplayValueEditor.cs new file mode 100644 index 00000000..706c5dc2 --- /dev/null +++ b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/MathGraph/Nodes/Editor/DisplayValueEditor.cs @@ -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()); + } + } +}
\ No newline at end of file diff --git a/Other/NodeEditorExamples/Assets/xNode-examples/Examples/MathGraph/Nodes/Editor/DisplayValueEditor.cs.meta b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/MathGraph/Nodes/Editor/DisplayValueEditor.cs.meta new file mode 100644 index 00000000..971da18a --- /dev/null +++ b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/MathGraph/Nodes/Editor/DisplayValueEditor.cs.meta @@ -0,0 +1,13 @@ +fileFormatVersion: 2 +guid: 7d7298690665789498dc42a285eb2c28 +timeCreated: 1509305659 +licenseType: Free +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Other/NodeEditorExamples/Assets/xNode-examples/Examples/MathGraph/Nodes/MathNode.cs b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/MathGraph/Nodes/MathNode.cs new file mode 100644 index 00000000..606e038f --- /dev/null +++ b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/MathGraph/Nodes/MathNode.cs @@ -0,0 +1,33 @@ +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 + [Input] public float a; + [Input] public float b; + // The value of an output node field is not used for anything, but could be used for caching output results + [Output] public float result; + + // Will be displayed as an editable field - just like the normal inspector + public MathType mathType = MathType.Add; + public enum MathType { Add, Subtract, Multiply, Divide } + + // GetValue should be overridden to return a value for any specified output port + public override object GetValue(XNode.NodePort port) { + + // Get new a and b values from input connections. Fallback to field values if input is not connected + float a = GetInputValue<float>("a", this.a); + float b = GetInputValue<float>("b", this.b); + + // After you've gotten your input values, you can perform your calculations and return a value + result = 0f; + if (port.fieldName == "result") + switch (mathType) { + case MathType.Add: default: result = a+b; break; + case MathType.Subtract: result = a - b; break; + case MathType.Multiply: result = a * b; break; + case MathType.Divide: result = a / b; break; + } + return result; + } + } +}
\ No newline at end of file diff --git a/Other/NodeEditorExamples/Assets/xNode-examples/Examples/MathGraph/Nodes/MathNode.cs.meta b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/MathGraph/Nodes/MathNode.cs.meta new file mode 100644 index 00000000..bd2894cb --- /dev/null +++ b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/MathGraph/Nodes/MathNode.cs.meta @@ -0,0 +1,13 @@ +fileFormatVersion: 2 +guid: 19e541bba2a188f4a84c6f3718ee6d55 +timeCreated: 1509307779 +licenseType: Free +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Other/NodeEditorExamples/Assets/xNode-examples/Examples/MathGraph/Nodes/Vector.cs b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/MathGraph/Nodes/Vector.cs new file mode 100644 index 00000000..1f43e6ff --- /dev/null +++ b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/MathGraph/Nodes/Vector.cs @@ -0,0 +1,15 @@ +using UnityEngine; + +namespace XNode.Examples.MathNodes { + public class Vector : XNode.Node { + [Input] public float x, y, z; + [Output] public Vector3 vector; + + public override object GetValue(XNode.NodePort port) { + vector.x = GetInputValue<float>("x", this.x); + vector.y = GetInputValue<float>("y", this.y); + vector.z = GetInputValue<float>("z", this.z); + return vector; + } + } +}
\ No newline at end of file diff --git a/Other/NodeEditorExamples/Assets/xNode-examples/Examples/MathGraph/Nodes/Vector.cs.meta b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/MathGraph/Nodes/Vector.cs.meta new file mode 100644 index 00000000..968b1f6c --- /dev/null +++ b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/MathGraph/Nodes/Vector.cs.meta @@ -0,0 +1,13 @@ +fileFormatVersion: 2 +guid: 05559f4106850df4ab41776666216480 +timeCreated: 1509303406 +licenseType: Free +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: |