summaryrefslogtreecommitdiff
path: root/Other/NodeEditorExamples/Assets/xNode-examples/Examples/RuntimeMathGraph/Scripts/Connection.cs
blob: ac4e889b10162ef8baae5bee36ae6f25219581e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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);
		}
	}
}