From 49b25e755b70ec412feaaf0b898d6f7e09d2bea6 Mon Sep 17 00:00:00 2001 From: chai Date: Tue, 28 Jun 2022 09:40:37 +0800 Subject: +node example --- Other/NodeEditorExamples/Assets/UNEB/NodeInput.cs | 114 ++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 Other/NodeEditorExamples/Assets/UNEB/NodeInput.cs (limited to 'Other/NodeEditorExamples/Assets/UNEB/NodeInput.cs') diff --git a/Other/NodeEditorExamples/Assets/UNEB/NodeInput.cs b/Other/NodeEditorExamples/Assets/UNEB/NodeInput.cs new file mode 100644 index 00000000..fab62c10 --- /dev/null +++ b/Other/NodeEditorExamples/Assets/UNEB/NodeInput.cs @@ -0,0 +1,114 @@ + +using System.Collections.Generic; +using System.Linq; +using UnityEngine; + +namespace UNEB +{ + public class NodeInput : NodeConnection + { + [SerializeField] + private bool _bCanHaveMultipleConnections; + + [SerializeField] + private List _outputs = new List(); + + private GUIStyle _style; + + public virtual void Init(Node parent, bool multipleConnections = true) + { + base.Init(parent); + name = "input"; + _bCanHaveMultipleConnections = multipleConnections; + } + + /// + /// Should only be called by NodeOutput + /// + /// + internal void Connect(NodeOutput output) + { + if (!_outputs.Contains(output)) + _outputs.Add(output); + } + + /// + /// Should only be called by NodeOutput. + /// + internal void Disconnect(NodeOutput output) + { + if (_outputs.Contains(output)) + _outputs.Remove(output); + } + + public bool HasOutputConnected() + { + return _outputs.Count > 0; + } + + public void RemoveAll() { + // Cache the outputs since in order to disconnect them, + // they must be removed from _outputs List. + var outputs = new List(_outputs); + + _outputs.Clear(); + + foreach (NodeOutput output in outputs) { + output.Remove(this); + } + } + + public List Outputs + { + get { return _outputs; } + } + + public int OutputCount + { + get { return _outputs.Count; } + } + + public NodeOutput GetOutput(int index) + { + return _outputs[index]; + } + + public override GUIStyle GetStyle() + { + if (_style == null) { + + _style = new GUIStyle(); + + _style.fixedHeight = kMinSize.y + Node.kKnobOffset; + _style.alignment = TextAnchor.MiddleLeft; + _style.normal.textColor = Color.white * 0.9f; + _style.padding.left = (int)kMinHalfSize.x + 5; + } + + return _style; + } + + /// + /// The input is anchored at the left side of the node. + /// + /// + public override float GetNodeAnchor() + { + return parentNode.bodyRect.xMin; + } + + public bool bCanHaveMultipleConnections + { + get { return _bCanHaveMultipleConnections; } + } + + public static NodeInput Create(Node parent, bool multipleConnections = false) + { + var input = ScriptableObject.CreateInstance(); + input.Init(parent, multipleConnections); + + NodeConnection.OnConnectionCreated(input); + return input; + } + } +} \ No newline at end of file -- cgit v1.1-26-g67d0