summaryrefslogtreecommitdiff
path: root/Other/NodeEditorExamples/Assets/xNode-examples/Examples/RuntimeMathGraph/Scripts/RuntimeNodes/UGUIVector.cs
blob: ca517a3e36deef7da3ee01b17193f0bb39566d23 (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
46
47
48
49
50
51
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using XNode.Examples.MathNodes;

namespace XNode.Examples.RuntimeMathNodes {
	public class UGUIVector : UGUIMathBaseNode {
		public InputField valX;
		public InputField valY;
		public InputField valZ;

		private Vector vectorNode;

		public override void Start() {
			base.Start();
			vectorNode = node as Vector;

			valX.onValueChanged.AddListener(OnChangeValX);
			valY.onValueChanged.AddListener(OnChangeValY);
			valZ.onValueChanged.AddListener(OnChangeValZ);
			UpdateGUI();
		}

		public override void UpdateGUI() {
			NodePort portX = node.GetInputPort("x");
			NodePort portY = node.GetInputPort("y");
			NodePort portZ = node.GetInputPort("z");
			valX.gameObject.SetActive(!portX.IsConnected);
			valY.gameObject.SetActive(!portY.IsConnected);
			valZ.gameObject.SetActive(!portZ.IsConnected);

			Vector vectorNode = node as Vector;
			valX.text = vectorNode.x.ToString();
			valY.text = vectorNode.y.ToString();
			valZ.text = vectorNode.z.ToString();
		}

		private void OnChangeValX(string val) {
			vectorNode.x = float.Parse(valX.text);
		}

		private void OnChangeValY(string val) {
			vectorNode.y = float.Parse(valY.text);
		}

		private void OnChangeValZ(string val) {
			vectorNode.z = float.Parse(valZ.text);
		}
	}
}