1
0
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:
Thor Brigsted 2017-10-20 23:01:38 +02:00
parent c1b2d2ff87
commit 2dc7450661
8 changed files with 27 additions and 22 deletions

Binary file not shown.

View File

@ -1,6 +1,6 @@
using UnityEngine;
public class DisplayValue : ExampleNodeBase {
[Input(false)] public float value;
[Input] public float value;
}

View File

@ -2,9 +2,9 @@
[System.Serializable]
public class MathNode : ExampleNodeBase {
[Input(true)] public float a;
[Input(true)] public float b;
[Output(false)] public float result;
[Input] public float a;
[Input] public float b;
[Output] public float result;
public enum MathType { Add, Subtract, Multiply, Divide}
public MathType mathType = MathType.Add;

View File

@ -5,14 +5,14 @@ using UnityEngine;
public class TestNode : Node {
public int myInt;
[Input(false)] public float myFloat;
[Input] public float myFloat;
public double myDouble;
public long myLong;
public bool myBool;
[Input(true)] public string myString;
[Input] public string myString;
public Rect myRect;
[Input(true)] public Vector2 myVec2;
[Input(true)] public Vector3 myVec3;
[Input] public Vector2 myVec2;
[Input] public Vector3 myVec3;
public Vector4 myVec4;
public Color myColor;
public AnimationCurve myCurve;

View File

@ -31,7 +31,6 @@ public class NodeEditor {
EditorGUI.BeginChangeCheck();
FieldInfo[] fields = GetInspectorFields(target);
for (int i = 0; i < fields.Length; i++) {
object[] fieldAttribs = fields[i].GetCustomAttributes(false);
if (fields[i].Name == "graph" || fields[i].Name == "position") continue;
NodeEditorGUILayout.PropertyField(target, fields[i], portPositions);
}

View File

@ -108,10 +108,7 @@ public partial class NodeEditorWindow {
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);
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);
GUI.color = prevCol;
}
/// <summary> Draws all connections </summary>

View File

@ -50,12 +50,13 @@ public class NodeEditorGUILayout {
if (NodeEditorUtilities.GetAttrib(fieldAttribs, out inputAttrib)) {
NodePort port = target.GetPortByFieldName(fieldName);
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);
} else if (NodeEditorUtilities.GetAttrib(fieldAttribs, out outputAttrib)) {
NodePort port = target.GetPortByFieldName(fieldName);
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);
} else {
fieldValue = PropertyField(fieldPrettyName, fieldValue, fieldType);

View File

@ -7,7 +7,14 @@ using UnityEngine;
/// <summary> Base class for all nodes </summary>
[Serializable]
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>
[SerializeField] public NodeGraph graph;
@ -21,7 +28,7 @@ public abstract class Node : ScriptableObject {
public int OutputCount { get { return outputs.Count; } }
protected void OnEnable() {
GetPorts();
NodeDataCache.UpdatePorts(this, inputs, outputs);
Init();
}
@ -98,19 +105,20 @@ public abstract class Node : ScriptableObject {
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)]
public class InputAttribute : Attribute {
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; }
}
/// <summary> Mark a serializable field as an output port. You can access this through <see cref="GetOutputByFieldName(string)"/> </summary>
[AttributeUsage(AttributeTargets.Field, AllowMultiple = true)]
public class OutputAttribute : Attribute {
public bool fallback;
public OutputAttribute(bool fallback) { this.fallback = fallback; }
}
private void GetPorts() {
NodeDataCache.UpdatePorts(this, inputs, outputs);
/// <summary> Mark a serializable field as an output port. You can access this through <see cref="GetOutputByFieldName(string)"/> </summary>
public OutputAttribute() { }
}
}