diff options
author | chai <chaifix@163.com> | 2022-06-28 09:40:37 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2022-06-28 09:40:37 +0800 |
commit | 49b25e755b70ec412feaaf0b898d6f7e09d2bea6 (patch) | |
tree | 3c5f4260f30d1c2d7196db93153700d7ddec3157 /Other/NodeEditorExamples/Assets/UNEB/NodeConnection.cs | |
parent | c92269331692feca2c276649f6c4ee8911f1f859 (diff) |
+node example
Diffstat (limited to 'Other/NodeEditorExamples/Assets/UNEB/NodeConnection.cs')
-rw-r--r-- | Other/NodeEditorExamples/Assets/UNEB/NodeConnection.cs | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/Other/NodeEditorExamples/Assets/UNEB/NodeConnection.cs b/Other/NodeEditorExamples/Assets/UNEB/NodeConnection.cs new file mode 100644 index 00000000..40f4d6de --- /dev/null +++ b/Other/NodeEditorExamples/Assets/UNEB/NodeConnection.cs @@ -0,0 +1,91 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace UNEB +{ + public abstract class NodeConnection : ScriptableObject + { + public static readonly Vector2 kMinSize = new Vector2(12f, 12f); + public static readonly Vector2 kMinHalfSize = kMinSize / 2f; + + [HideInInspector] + public Rect bodyRect = new Rect(Vector2.zero, kMinSize); + + public System.Func<object> getValue; + + public static System.Action<NodeConnection> OnConnectionCreated; + + [SerializeField, HideInInspector] + protected Node parentNode; + + void OnEnable() + { + hideFlags = HideFlags.HideInHierarchy; + } + + public virtual void Init(Node parent) + { + name = "connection"; + parentNode = parent; + } + + /// <summary> + /// The node associated with this knob. + /// </summary> + public Node ParentNode + { + get { return parentNode; } + } + + public abstract GUIStyle GetStyle(); + + public virtual void OnConnectionGUI(int order) + { + OnNameGUI(); + + // Position the knobs properly for the draw pass of the knobs in the editor. + float yPos = parentNode.HeaderTop + order * GetStyle().fixedHeight + Node.kKnobOffset; + bodyRect.center = new Vector2(GetNodeAnchor(), 0f); + bodyRect.y = yPos; + } + + public virtual void OnNameGUI() + { + GUILayout.Label(Content, GetStyle()); + } + + private GUIContent _content; + private GUIContent Content + { + get + { + if (_content == null) { + _content = new GUIContent(name); + } + + return _content; + } + } + + /// <summary> + /// What side of the node should the knob anchor to. + /// </summary> + /// <returns></returns> + public abstract float GetNodeAnchor(); + + /// <summary> + /// Attempts to get the value of the specified type. + /// </summary> + /// <typeparam name="T"></typeparam> + /// <returns></returns> + public T GetValue<T>() + { + if (getValue != null) { + return (T)getValue(); + } + + return default(T); + } + } +}
\ No newline at end of file |