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 getValue; public static System.Action OnConnectionCreated; [SerializeField, HideInInspector] protected Node parentNode; void OnEnable() { hideFlags = HideFlags.HideInHierarchy; } public virtual void Init(Node parent) { name = "connection"; parentNode = parent; } /// /// The node associated with this knob. /// 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; } } /// /// What side of the node should the knob anchor to. /// /// public abstract float GetNodeAnchor(); /// /// Attempts to get the value of the specified type. /// /// /// public T GetValue() { if (getValue != null) { return (T)getValue(); } return default(T); } } }