mirror of
https://github.com/Siccity/xNode.git
synced 2025-12-20 09:16:01 +08:00
Improved userfriendlyness of [Input] and [Output]
This commit is contained in:
parent
c1b2d2ff87
commit
2dc7450661
Binary file not shown.
@ -1,6 +1,6 @@
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
public class DisplayValue : ExampleNodeBase {
|
public class DisplayValue : ExampleNodeBase {
|
||||||
[Input(false)] public float value;
|
[Input] public float value;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
[System.Serializable]
|
[System.Serializable]
|
||||||
public class MathNode : ExampleNodeBase {
|
public class MathNode : ExampleNodeBase {
|
||||||
[Input(true)] public float a;
|
[Input] public float a;
|
||||||
[Input(true)] public float b;
|
[Input] public float b;
|
||||||
[Output(false)] public float result;
|
[Output] public float result;
|
||||||
public enum MathType { Add, Subtract, Multiply, Divide}
|
public enum MathType { Add, Subtract, Multiply, Divide}
|
||||||
public MathType mathType = MathType.Add;
|
public MathType mathType = MathType.Add;
|
||||||
|
|
||||||
|
|||||||
@ -5,14 +5,14 @@ using UnityEngine;
|
|||||||
public class TestNode : Node {
|
public class TestNode : Node {
|
||||||
|
|
||||||
public int myInt;
|
public int myInt;
|
||||||
[Input(false)] public float myFloat;
|
[Input] public float myFloat;
|
||||||
public double myDouble;
|
public double myDouble;
|
||||||
public long myLong;
|
public long myLong;
|
||||||
public bool myBool;
|
public bool myBool;
|
||||||
[Input(true)] public string myString;
|
[Input] public string myString;
|
||||||
public Rect myRect;
|
public Rect myRect;
|
||||||
[Input(true)] public Vector2 myVec2;
|
[Input] public Vector2 myVec2;
|
||||||
[Input(true)] public Vector3 myVec3;
|
[Input] public Vector3 myVec3;
|
||||||
public Vector4 myVec4;
|
public Vector4 myVec4;
|
||||||
public Color myColor;
|
public Color myColor;
|
||||||
public AnimationCurve myCurve;
|
public AnimationCurve myCurve;
|
||||||
|
|||||||
@ -31,7 +31,6 @@ public class NodeEditor {
|
|||||||
EditorGUI.BeginChangeCheck();
|
EditorGUI.BeginChangeCheck();
|
||||||
FieldInfo[] fields = GetInspectorFields(target);
|
FieldInfo[] fields = GetInspectorFields(target);
|
||||||
for (int i = 0; i < fields.Length; i++) {
|
for (int i = 0; i < fields.Length; i++) {
|
||||||
object[] fieldAttribs = fields[i].GetCustomAttributes(false);
|
|
||||||
if (fields[i].Name == "graph" || fields[i].Name == "position") continue;
|
if (fields[i].Name == "graph" || fields[i].Name == "position") continue;
|
||||||
NodeEditorGUILayout.PropertyField(target, fields[i], portPositions);
|
NodeEditorGUILayout.PropertyField(target, fields[i], portPositions);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -108,10 +108,7 @@ public partial class NodeEditorWindow {
|
|||||||
if (startPoint.x > endPoint.x) endTangent.x = Mathf.LerpUnclamped(endPoint.x, startPoint.x, -0.7f);
|
if (startPoint.x > endPoint.x) endTangent.x = Mathf.LerpUnclamped(endPoint.x, startPoint.x, -0.7f);
|
||||||
else endTangent.x = Mathf.LerpUnclamped(endPoint.x, startPoint.x, 0.7f);
|
else endTangent.x = Mathf.LerpUnclamped(endPoint.x, startPoint.x, 0.7f);
|
||||||
|
|
||||||
Color prevCol = GUI.color;
|
|
||||||
Color edgeCol = new Color(0.1f, 0.1f, 0.1f, col.a);
|
|
||||||
Handles.DrawBezier(startPoint, endPoint, startTangent, endTangent, col, null, 4);
|
Handles.DrawBezier(startPoint, endPoint, startTangent, endTangent, col, null, 4);
|
||||||
GUI.color = prevCol;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> Draws all connections </summary>
|
/// <summary> Draws all connections </summary>
|
||||||
|
|||||||
@ -50,12 +50,13 @@ public class NodeEditorGUILayout {
|
|||||||
if (NodeEditorUtilities.GetAttrib(fieldAttribs, out inputAttrib)) {
|
if (NodeEditorUtilities.GetAttrib(fieldAttribs, out inputAttrib)) {
|
||||||
NodePort port = target.GetPortByFieldName(fieldName);
|
NodePort port = target.GetPortByFieldName(fieldName);
|
||||||
Vector2 portPos;
|
Vector2 portPos;
|
||||||
fieldValue = PortField(fieldPrettyName, fieldValue, fieldType, port, inputAttrib.fallback, out portPos);
|
bool fallback = inputAttrib.backingValue == Node.ShowBackingValue.Always || (inputAttrib.backingValue == Node.ShowBackingValue.Unconnected && !port.IsConnected);
|
||||||
|
fieldValue = PortField(fieldPrettyName, fieldValue, fieldType, port, fallback, out portPos);
|
||||||
portPositions.Add(port, portPos);
|
portPositions.Add(port, portPos);
|
||||||
} else if (NodeEditorUtilities.GetAttrib(fieldAttribs, out outputAttrib)) {
|
} else if (NodeEditorUtilities.GetAttrib(fieldAttribs, out outputAttrib)) {
|
||||||
NodePort port = target.GetPortByFieldName(fieldName);
|
NodePort port = target.GetPortByFieldName(fieldName);
|
||||||
Vector2 portPos;
|
Vector2 portPos;
|
||||||
fieldValue = PortField(fieldPrettyName, fieldValue, fieldType, port, outputAttrib.fallback, out portPos);
|
fieldValue = PortField(fieldPrettyName, fieldValue, fieldType, port, false, out portPos);
|
||||||
portPositions.Add(port, portPos);
|
portPositions.Add(port, portPos);
|
||||||
} else {
|
} else {
|
||||||
fieldValue = PropertyField(fieldPrettyName, fieldValue, fieldType);
|
fieldValue = PropertyField(fieldPrettyName, fieldValue, fieldType);
|
||||||
|
|||||||
@ -7,7 +7,14 @@ using UnityEngine;
|
|||||||
/// <summary> Base class for all nodes </summary>
|
/// <summary> Base class for all nodes </summary>
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public abstract class Node : ScriptableObject {
|
public abstract class Node : ScriptableObject {
|
||||||
public enum ShowBackingValue { Never, Unconnected, Always }
|
public enum ShowBackingValue {
|
||||||
|
/// <summary> Never show the backing value </summary>
|
||||||
|
Never,
|
||||||
|
/// <summary> Show the backing value only when the port does not have any active connections </summary>
|
||||||
|
Unconnected,
|
||||||
|
/// <summary> Always show the backing value </summary>
|
||||||
|
Always
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary> Name of the node </summary>
|
/// <summary> Name of the node </summary>
|
||||||
[SerializeField] public NodeGraph graph;
|
[SerializeField] public NodeGraph graph;
|
||||||
@ -21,7 +28,7 @@ public abstract class Node : ScriptableObject {
|
|||||||
public int OutputCount { get { return outputs.Count; } }
|
public int OutputCount { get { return outputs.Count; } }
|
||||||
|
|
||||||
protected void OnEnable() {
|
protected void OnEnable() {
|
||||||
GetPorts();
|
NodeDataCache.UpdatePorts(this, inputs, outputs);
|
||||||
Init();
|
Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,19 +105,20 @@ public abstract class Node : ScriptableObject {
|
|||||||
return JsonUtility.ToJson(this).GetHashCode();
|
return JsonUtility.ToJson(this).GetHashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary> Mark a serializable field as an input port. You can access this through <see cref="GetInputByFieldName(string)"/> </summary>
|
||||||
[AttributeUsage(AttributeTargets.Field, AllowMultiple = true)]
|
[AttributeUsage(AttributeTargets.Field, AllowMultiple = true)]
|
||||||
public class InputAttribute : Attribute {
|
public class InputAttribute : Attribute {
|
||||||
public ShowBackingValue backingValue;
|
public ShowBackingValue backingValue;
|
||||||
|
|
||||||
|
/// <summary> Mark a serializable field as an input port. You can access this through <see cref="GetInputByFieldName(string)"/> </summary>
|
||||||
|
/// <param name="backingValue">Should we display the backing value for this port as an editor field? </param>
|
||||||
public InputAttribute(ShowBackingValue backingValue = ShowBackingValue.Unconnected) { this.backingValue = backingValue; }
|
public InputAttribute(ShowBackingValue backingValue = ShowBackingValue.Unconnected) { this.backingValue = backingValue; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary> Mark a serializable field as an output port. You can access this through <see cref="GetOutputByFieldName(string)"/> </summary>
|
||||||
[AttributeUsage(AttributeTargets.Field, AllowMultiple = true)]
|
[AttributeUsage(AttributeTargets.Field, AllowMultiple = true)]
|
||||||
public class OutputAttribute : Attribute {
|
public class OutputAttribute : Attribute {
|
||||||
public bool fallback;
|
/// <summary> Mark a serializable field as an output port. You can access this through <see cref="GetOutputByFieldName(string)"/> </summary>
|
||||||
public OutputAttribute(bool fallback) { this.fallback = fallback; }
|
public OutputAttribute() { }
|
||||||
}
|
|
||||||
|
|
||||||
private void GetPorts() {
|
|
||||||
NodeDataCache.UpdatePorts(this, inputs, outputs);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user