summaryrefslogtreecommitdiff
path: root/Other/NodeEditorExamples/Assets/xNode-examples/Examples/MathGraph/Nodes
diff options
context:
space:
mode:
Diffstat (limited to 'Other/NodeEditorExamples/Assets/xNode-examples/Examples/MathGraph/Nodes')
-rw-r--r--Other/NodeEditorExamples/Assets/xNode-examples/Examples/MathGraph/Nodes/DisplayValue.cs20
-rw-r--r--Other/NodeEditorExamples/Assets/xNode-examples/Examples/MathGraph/Nodes/DisplayValue.cs.meta12
-rw-r--r--Other/NodeEditorExamples/Assets/xNode-examples/Examples/MathGraph/Nodes/Editor.meta10
-rw-r--r--Other/NodeEditorExamples/Assets/xNode-examples/Examples/MathGraph/Nodes/Editor/DisplayValueEditor.cs27
-rw-r--r--Other/NodeEditorExamples/Assets/xNode-examples/Examples/MathGraph/Nodes/Editor/DisplayValueEditor.cs.meta13
-rw-r--r--Other/NodeEditorExamples/Assets/xNode-examples/Examples/MathGraph/Nodes/MathNode.cs33
-rw-r--r--Other/NodeEditorExamples/Assets/xNode-examples/Examples/MathGraph/Nodes/MathNode.cs.meta13
-rw-r--r--Other/NodeEditorExamples/Assets/xNode-examples/Examples/MathGraph/Nodes/Vector.cs15
-rw-r--r--Other/NodeEditorExamples/Assets/xNode-examples/Examples/MathGraph/Nodes/Vector.cs.meta13
9 files changed, 156 insertions, 0 deletions
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: