summaryrefslogtreecommitdiff
path: root/Other/NodeEditorExamples/Assets/UNEB/NodeInput.cs
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2022-06-28 09:40:37 +0800
committerchai <chaifix@163.com>2022-06-28 09:40:37 +0800
commit49b25e755b70ec412feaaf0b898d6f7e09d2bea6 (patch)
tree3c5f4260f30d1c2d7196db93153700d7ddec3157 /Other/NodeEditorExamples/Assets/UNEB/NodeInput.cs
parentc92269331692feca2c276649f6c4ee8911f1f859 (diff)
+node example
Diffstat (limited to 'Other/NodeEditorExamples/Assets/UNEB/NodeInput.cs')
-rw-r--r--Other/NodeEditorExamples/Assets/UNEB/NodeInput.cs114
1 files changed, 114 insertions, 0 deletions
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<NodeOutput> _outputs = new List<NodeOutput>();
+
+ private GUIStyle _style;
+
+ public virtual void Init(Node parent, bool multipleConnections = true)
+ {
+ base.Init(parent);
+ name = "input";
+ _bCanHaveMultipleConnections = multipleConnections;
+ }
+
+ /// <summary>
+ /// Should only be called by NodeOutput
+ /// </summary>
+ /// <param name="output"></param>
+ internal void Connect(NodeOutput output)
+ {
+ if (!_outputs.Contains(output))
+ _outputs.Add(output);
+ }
+
+ /// <summary>
+ /// Should only be called by NodeOutput.
+ /// </summary>
+ 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<NodeOutput>(_outputs);
+
+ _outputs.Clear();
+
+ foreach (NodeOutput output in outputs) {
+ output.Remove(this);
+ }
+ }
+
+ public List<NodeOutput> 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;
+ }
+
+ /// <summary>
+ /// The input is anchored at the left side of the node.
+ /// </summary>
+ /// <returns></returns>
+ 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<NodeInput>();
+ input.Init(parent, multipleConnections);
+
+ NodeConnection.OnConnectionCreated(input);
+ return input;
+ }
+ }
+} \ No newline at end of file