From 49b25e755b70ec412feaaf0b898d6f7e09d2bea6 Mon Sep 17 00:00:00 2001 From: chai Date: Tue, 28 Jun 2022 09:40:37 +0800 Subject: +node example --- .../Examples/RuntimeMathGraph/Scripts/Connection.cs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Other/NodeEditorExamples/Assets/xNode-examples/Examples/RuntimeMathGraph/Scripts/Connection.cs (limited to 'Other/NodeEditorExamples/Assets/xNode-examples/Examples/RuntimeMathGraph/Scripts/Connection.cs') diff --git a/Other/NodeEditorExamples/Assets/xNode-examples/Examples/RuntimeMathGraph/Scripts/Connection.cs b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/RuntimeMathGraph/Scripts/Connection.cs new file mode 100644 index 00000000..ac4e889b --- /dev/null +++ b/Other/NodeEditorExamples/Assets/xNode-examples/Examples/RuntimeMathGraph/Scripts/Connection.cs @@ -0,0 +1,18 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using XNode; + +namespace XNode.Examples.RuntimeMathNodes { + public class Connection : MonoBehaviour { + private RectTransform rectTransform; + public void SetPosition(Vector2 start, Vector2 end) { + if (!rectTransform) rectTransform = (RectTransform) transform; + transform.position = (start + end) * 0.5f; + + float r = Mathf.Atan2(start.y - end.y, start.x - end.x) * Mathf.Rad2Deg; + transform.rotation = Quaternion.Euler(0, 0, r); + rectTransform.sizeDelta = new Vector2(Vector2.Distance(start, end), rectTransform.sizeDelta.y); + } + } +} \ No newline at end of file -- cgit v1.1-26-g67d0