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/xNode-examples/Examples/RuntimeMathGraph/Scripts/UGUIContextMenu.cs | |
parent | c92269331692feca2c276649f6c4ee8911f1f859 (diff) |
+node example
Diffstat (limited to 'Other/NodeEditorExamples/Assets/xNode-examples/Examples/RuntimeMathGraph/Scripts/UGUIContextMenu.cs')
-rw-r--r-- | Other/NodeEditorExamples/Assets/xNode-examples/Examples/RuntimeMathGraph/Scripts/UGUIContextMenu.cs | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/Other/NodeEditorExamples/Assets/xNode-examples/Examples/RuntimeMathGraph/Scripts/UGUIContextMenu.cs b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/RuntimeMathGraph/Scripts/UGUIContextMenu.cs new file mode 100644 index 00000000..0d2e85c1 --- /dev/null +++ b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/RuntimeMathGraph/Scripts/UGUIContextMenu.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.EventSystems; + +namespace XNode.Examples.RuntimeMathNodes { + public class UGUIContextMenu : MonoBehaviour, IPointerExitHandler { + + public Action<Type, Vector2> onClickSpawn; + public CanvasGroup group; + [HideInInspector] public Node selectedNode; + private Vector2 pos; + + private void Start() { + Close(); + } + + public void OpenAt(Vector2 pos) { + transform.position = pos; + group.alpha = 1; + group.interactable = true; + group.blocksRaycasts = true; + transform.SetAsLastSibling(); + } + + public void Close() { + group.alpha = 0; + group.interactable = false; + group.blocksRaycasts = false; + } + + public void SpawnMathNode() { + SpawnNode(typeof(XNode.Examples.MathNodes.MathNode)); + } + + public void SpawnDisplayNode() { + SpawnNode(typeof(XNode.Examples.MathNodes.DisplayValue)); + } + + public void SpawnVectorNode() { + SpawnNode(typeof(XNode.Examples.MathNodes.Vector)); + } + + private void SpawnNode(Type nodeType) { + Vector2 pos = new Vector2(transform.localPosition.x, -transform.localPosition.y); + onClickSpawn(nodeType, pos); + } + + public void RemoveNode() { + RuntimeMathGraph runtimeMathGraph = GetComponentInParent<RuntimeMathGraph>(); + runtimeMathGraph.graph.RemoveNode(selectedNode); + runtimeMathGraph.Refresh(); + Close(); + } + + public void OnPointerExit(PointerEventData eventData) { + Close(); + } + } +}
\ No newline at end of file |