mirror of
https://github.com/Siccity/xNode.git
synced 2025-12-21 17:56:06 +08:00
Updated examples
This commit is contained in:
parent
38d45d0486
commit
3e91a30e88
@ -12,9 +12,11 @@ MonoBehaviour:
|
|||||||
m_Name: ExampleNodeGraph
|
m_Name: ExampleNodeGraph
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
nodes:
|
nodes:
|
||||||
- {fileID: 114253037537709940}
|
- {fileID: 114386305456729202}
|
||||||
- {fileID: 114976558807377558}
|
- {fileID: 114862693020615806}
|
||||||
--- !u!114 &114253037537709940
|
- {fileID: 114245132648392102}
|
||||||
|
- {fileID: 114602227203521556}
|
||||||
|
--- !u!114 &114245132648392102
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
m_PrefabParentObject: {fileID: 0}
|
m_PrefabParentObject: {fileID: 0}
|
||||||
@ -23,31 +25,33 @@ MonoBehaviour:
|
|||||||
m_Enabled: 1
|
m_Enabled: 1
|
||||||
m_EditorHideFlags: 0
|
m_EditorHideFlags: 0
|
||||||
m_Script: {fileID: 11500000, guid: 22e05e2a1f5ad7645850d52212143629, type: 3}
|
m_Script: {fileID: 11500000, guid: 22e05e2a1f5ad7645850d52212143629, type: 3}
|
||||||
m_Name: Math
|
m_Name: MathNode
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
graph: {fileID: 11400000}
|
graph: {fileID: 11400000}
|
||||||
position: {x: 0, y: 0}
|
position: {x: -429.5, y: -110.5}
|
||||||
inputs:
|
inputs:
|
||||||
- node: {fileID: 114253037537709940}
|
- node: {fileID: 114245132648392102}
|
||||||
_fieldName: a
|
_fieldName: a
|
||||||
connections: []
|
connections: []
|
||||||
_direction: 0
|
_direction: 0
|
||||||
- node: {fileID: 114253037537709940}
|
- node: {fileID: 114245132648392102}
|
||||||
_fieldName: b
|
_fieldName: b
|
||||||
connections: []
|
connections: []
|
||||||
_direction: 0
|
_direction: 0
|
||||||
outputs:
|
outputs:
|
||||||
- node: {fileID: 114253037537709940}
|
- node: {fileID: 114245132648392102}
|
||||||
_fieldName: result
|
_fieldName: result
|
||||||
connections:
|
connections:
|
||||||
- fieldName: myFloat
|
- fieldName: a
|
||||||
node: {fileID: 114976558807377558}
|
node: {fileID: 114862693020615806}
|
||||||
|
- fieldName: value
|
||||||
|
node: {fileID: 114602227203521556}
|
||||||
_direction: 1
|
_direction: 1
|
||||||
a: 5.1719556
|
a: 4.771955
|
||||||
b: 2.0752559
|
b: 8.313191
|
||||||
result: 0
|
result: 0
|
||||||
mathType: 0
|
mathType: 0
|
||||||
--- !u!114 &114976558807377558
|
--- !u!114 &114386305456729202
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
m_PrefabParentObject: {fileID: 0}
|
m_PrefabParentObject: {fileID: 0}
|
||||||
@ -55,62 +59,74 @@ MonoBehaviour:
|
|||||||
m_GameObject: {fileID: 0}
|
m_GameObject: {fileID: 0}
|
||||||
m_Enabled: 1
|
m_Enabled: 1
|
||||||
m_EditorHideFlags: 0
|
m_EditorHideFlags: 0
|
||||||
m_Script: {fileID: 11500000, guid: 47bfd6281f41a10459bcb45bb4cd03f3, type: 3}
|
m_Script: {fileID: 11500000, guid: 98f6f901f0da53142b79277ea3f42518, type: 3}
|
||||||
m_Name: TestNode
|
m_Name: DisplayValue
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
graph: {fileID: 11400000}
|
graph: {fileID: 11400000}
|
||||||
position: {x: 271, y: -57}
|
position: {x: 23.5, y: -98.5}
|
||||||
inputs:
|
inputs:
|
||||||
- node: {fileID: 114976558807377558}
|
- node: {fileID: 114386305456729202}
|
||||||
_fieldName: myString
|
_fieldName: value
|
||||||
connections: []
|
|
||||||
_direction: 0
|
|
||||||
- node: {fileID: 114976558807377558}
|
|
||||||
_fieldName: myVec2
|
|
||||||
connections: []
|
|
||||||
_direction: 0
|
|
||||||
- node: {fileID: 114976558807377558}
|
|
||||||
_fieldName: myVec3
|
|
||||||
connections: []
|
|
||||||
_direction: 0
|
|
||||||
- node: {fileID: 114976558807377558}
|
|
||||||
_fieldName: myFloat
|
|
||||||
connections:
|
connections:
|
||||||
- fieldName: result
|
- fieldName: result
|
||||||
node: {fileID: 114253037537709940}
|
node: {fileID: 114862693020615806}
|
||||||
|
_direction: 0
|
||||||
|
outputs: []
|
||||||
|
value: 4.01703
|
||||||
|
--- !u!114 &114602227203521556
|
||||||
|
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: -194.5, y: -140.5}
|
||||||
|
inputs:
|
||||||
|
- node: {fileID: 114602227203521556}
|
||||||
|
_fieldName: value
|
||||||
|
connections:
|
||||||
|
- fieldName: result
|
||||||
|
node: {fileID: 114245132648392102}
|
||||||
_direction: 0
|
_direction: 0
|
||||||
outputs: []
|
outputs: []
|
||||||
myInt: 0
|
|
||||||
myFloat: 0
|
|
||||||
myDouble: 0
|
|
||||||
myLong: 0
|
|
||||||
myBool: 0
|
|
||||||
myString:
|
|
||||||
myRect:
|
|
||||||
serializedVersion: 2
|
|
||||||
x: 0
|
|
||||||
y: 0
|
|
||||||
width: 0
|
|
||||||
height: 0
|
|
||||||
myVec2: {x: 0, y: 0}
|
|
||||||
myVec3: {x: 0, y: 0, z: 0}
|
|
||||||
myVec4: {x: 0, y: 0, z: 0, w: 0}
|
|
||||||
myColor: {r: 0.25383312, g: 0.44852942, b: 0.628, a: 0.641}
|
|
||||||
myCurve:
|
|
||||||
serializedVersion: 2
|
|
||||||
m_Curve:
|
|
||||||
- serializedVersion: 2
|
|
||||||
time: 0
|
|
||||||
value: 0
|
value: 0
|
||||||
inSlope: 0
|
--- !u!114 &114862693020615806
|
||||||
outSlope: 0
|
MonoBehaviour:
|
||||||
tangentMode: 0
|
m_ObjectHideFlags: 0
|
||||||
- serializedVersion: 2
|
m_PrefabParentObject: {fileID: 0}
|
||||||
time: 1
|
m_PrefabInternal: {fileID: 0}
|
||||||
value: 1
|
m_GameObject: {fileID: 0}
|
||||||
inSlope: 2
|
m_Enabled: 1
|
||||||
outSlope: 2
|
m_EditorHideFlags: 0
|
||||||
tangentMode: 0
|
m_Script: {fileID: 11500000, guid: 22e05e2a1f5ad7645850d52212143629, type: 3}
|
||||||
m_PreInfinity: 2
|
m_Name: MathNode
|
||||||
m_PostInfinity: 2
|
m_EditorClassIdentifier:
|
||||||
m_RotationOrder: 4
|
graph: {fileID: 11400000}
|
||||||
|
position: {x: -196.5, y: -45.5}
|
||||||
|
inputs:
|
||||||
|
- node: {fileID: 114862693020615806}
|
||||||
|
_fieldName: a
|
||||||
|
connections:
|
||||||
|
- fieldName: result
|
||||||
|
node: {fileID: 114245132648392102}
|
||||||
|
_direction: 0
|
||||||
|
- node: {fileID: 114862693020615806}
|
||||||
|
_fieldName: b
|
||||||
|
connections: []
|
||||||
|
_direction: 0
|
||||||
|
outputs:
|
||||||
|
- node: {fileID: 114862693020615806}
|
||||||
|
_fieldName: result
|
||||||
|
connections:
|
||||||
|
- fieldName: value
|
||||||
|
node: {fileID: 114386305456729202}
|
||||||
|
_direction: 1
|
||||||
|
a: 8.142139
|
||||||
|
b: 3.53361
|
||||||
|
result: 0
|
||||||
|
mathType: 1
|
||||||
|
|||||||
@ -1,6 +1,9 @@
|
|||||||
using UnityEngine;
|
namespace ExampleNodes {
|
||||||
|
public class DisplayValue : Node {
|
||||||
public class DisplayValue : ExampleNodeBase {
|
|
||||||
[Input] public float value;
|
[Input] public float value;
|
||||||
|
|
||||||
|
public float GetValue() {
|
||||||
|
return GetInputByFieldName<float>("value", value);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,16 +3,18 @@ using System.Collections.Generic;
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
|
|
||||||
[CustomNodeEditor(typeof(DisplayValue), "Display Value")]
|
namespace ExampleNodes {
|
||||||
|
[CustomNodeEditor(typeof(ExampleNodes.DisplayValue), "ExampleNodes/Display Value")]
|
||||||
public class DisplayValueEditor : NodeEditor {
|
public class DisplayValueEditor : NodeEditor {
|
||||||
|
|
||||||
protected override void OnBodyGUI(out Dictionary<NodePort, Vector2> portPositions) {
|
protected override void OnBodyGUI(out Dictionary<NodePort, Vector2> portPositions) {
|
||||||
base.OnBodyGUI(out portPositions);
|
base.OnBodyGUI(out portPositions);
|
||||||
EditorGUILayout.LabelField("Value: " + GetResult());
|
EditorGUILayout.LabelField(GetResult().ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public float GetResult() {
|
public float GetResult() {
|
||||||
ExampleNodeBase t = target as ExampleNodeBase;
|
DisplayValue t = target as DisplayValue;
|
||||||
return t.GetInputFloat("value");
|
return t.GetValue();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +0,0 @@
|
|||||||
[CustomNodeEditor(typeof(MathNode), "Math")]
|
|
||||||
public class AddNodeEditor : NodeEditor {
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,12 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: c4cc83d08877562419d86874dd3587e2
|
|
||||||
timeCreated: 1505987983
|
|
||||||
licenseType: Free
|
|
||||||
MonoImporter:
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
||||||
@ -1,22 +0,0 @@
|
|||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
public abstract class ExampleNodeBase : Node {
|
|
||||||
|
|
||||||
public float GetInputFloat(string fieldName) {
|
|
||||||
float result = 0f;
|
|
||||||
NodePort port = GetInputByFieldName(fieldName);
|
|
||||||
if (port == null) return result;
|
|
||||||
int connectionCount = port.ConnectionCount;
|
|
||||||
for (int i = 0; i < connectionCount; i++) {
|
|
||||||
NodePort connection = port.GetConnection(i);
|
|
||||||
if (connection == null) continue;
|
|
||||||
object obj = connection.GetOutputValue();
|
|
||||||
if (obj == null) continue;
|
|
||||||
if (connection.type == typeof(int)) result += (int)obj;
|
|
||||||
else if (connection.type == typeof(float)) result += (float)obj;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,12 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 923bada49e668fd4a98b04fcb49999d7
|
|
||||||
timeCreated: 1507917099
|
|
||||||
licenseType: Free
|
|
||||||
MonoImporter:
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
||||||
@ -1,31 +1,32 @@
|
|||||||
using UnityEngine;
|
namespace ExampleNodes {
|
||||||
|
|
||||||
[System.Serializable]
|
[System.Serializable]
|
||||||
public class MathNode : ExampleNodeBase {
|
public class MathNode : 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 a;
|
||||||
[Input] public float b;
|
[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;
|
[Output] public float result;
|
||||||
public enum MathType { Add, Subtract, Multiply, Divide}
|
|
||||||
|
// UNEC will display this as an editable field - just like the normal inspector would
|
||||||
public MathType mathType = MathType.Add;
|
public MathType mathType = MathType.Add;
|
||||||
|
public enum MathType { Add, Subtract, Multiply, Divide }
|
||||||
|
|
||||||
protected override void Init() {
|
// GetValue should be overridden to return a value for any specified output port
|
||||||
name = "Math";
|
|
||||||
}
|
|
||||||
|
|
||||||
public override object GetValue(NodePort port) {
|
public override object GetValue(NodePort port) {
|
||||||
float a = GetInputFloat("a");
|
|
||||||
float b = GetInputFloat("b");
|
|
||||||
|
|
||||||
switch(port.fieldName) {
|
// Get new a and b values from input connections. Fallback to field values if input is not connected
|
||||||
case "result":
|
float a = GetInputByFieldName<float>("a", this.a);
|
||||||
|
float b = GetInputByFieldName<float>("b", this.b);
|
||||||
|
|
||||||
|
// After you've gotten your input values, you can perform your calculations and return a value
|
||||||
|
if (port.fieldName == "result")
|
||||||
switch (mathType) {
|
switch (mathType) {
|
||||||
case MathType.Add: return a + b;
|
case MathType.Add: default: return a + b;
|
||||||
case MathType.Subtract: return a - b;
|
case MathType.Subtract: return a - b;
|
||||||
case MathType.Multiply: return a * b;
|
case MathType.Multiply: return a * b;
|
||||||
case MathType.Divide: return a / b;
|
case MathType.Divide: return a / b;
|
||||||
}
|
}
|
||||||
break;
|
else return 0f;
|
||||||
}
|
}
|
||||||
return 0f;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,19 +0,0 @@
|
|||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
public class TestNode : Node {
|
|
||||||
|
|
||||||
public int myInt;
|
|
||||||
[Input] public float myFloat;
|
|
||||||
public double myDouble;
|
|
||||||
public long myLong;
|
|
||||||
public bool myBool;
|
|
||||||
[Input] public string myString;
|
|
||||||
public Rect myRect;
|
|
||||||
[Input] public Vector2 myVec2;
|
|
||||||
[Input] public Vector3 myVec3;
|
|
||||||
public Vector4 myVec4;
|
|
||||||
public Color myColor;
|
|
||||||
public AnimationCurve myCurve;
|
|
||||||
}
|
|
||||||
@ -1,12 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 47bfd6281f41a10459bcb45bb4cd03f3
|
|
||||||
timeCreated: 1507990362
|
|
||||||
licenseType: Free
|
|
||||||
MonoImporter:
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
||||||
Loading…
x
Reference in New Issue
Block a user