summaryrefslogtreecommitdiff
path: root/Other/NodeEditorExamples/Assets/xNode-examples/Examples/RuntimeMathGraph/Scripts/UGUITooltip.cs
blob: fd61a32948edf053a357f8dab47c312bb93f4cc8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

namespace XNode.Examples.RuntimeMathNodes {
	public class UGUITooltip : MonoBehaviour {
		public CanvasGroup group;
		public Text label;
		private bool show;
		private RuntimeMathGraph graph;

		private void Awake() {
			graph = GetComponentInParent<RuntimeMathGraph>();
		}

		private void Start() {
			Hide();
		}

		private void Update() {
			if (show) UpdatePosition();
		}

		public void Show() {
			show = true;
			group.alpha = 1;
			UpdatePosition();
			transform.SetAsLastSibling();
		}

		public void Hide() {
			show = false;
			group.alpha = 0;
		}

		private void UpdatePosition() {
			Vector2 pos;
			RectTransform rect = graph.scrollRect.content.transform as RectTransform;
			Camera cam = graph.gameObject.GetComponentInParent<Canvas>().worldCamera;
			RectTransformUtility.ScreenPointToLocalPointInRectangle(rect, Input.mousePosition, cam, out pos);
			transform.localPosition = pos;
		}
	}
}