summaryrefslogtreecommitdiff
path: root/Other/NodeEditorExamples/Assets/xNode-examples/Examples/RuntimeMathGraph/Scripts/RuntimeNodes/UGUIMathNode.cs
blob: 76c2663e029f4ab208fe72cb8d5a97943ed98679 (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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using XNode.Examples.MathNodes;

namespace XNode.Examples.RuntimeMathNodes {
	public class UGUIMathNode : UGUIMathBaseNode {
		public InputField valA;
		public InputField valB;
		public Dropdown dropDown;

		private MathNode mathNode;

		public override void Start() {
			base.Start();
			mathNode = node as MathNode;

			valA.onValueChanged.AddListener(OnChangeValA);
			valB.onValueChanged.AddListener(OnChangeValB);
			dropDown.onValueChanged.AddListener(OnChangeDropdown);
			UpdateGUI();
		}

		public override void UpdateGUI() {
			NodePort portA = node.GetInputPort("a");
			NodePort portB = node.GetInputPort("b");
			valA.gameObject.SetActive(!portA.IsConnected);
			valB.gameObject.SetActive(!portB.IsConnected);

			valA.text = mathNode.a.ToString();
			valB.text = mathNode.b.ToString();
			dropDown.value = (int) mathNode.mathType;
		}

		private void OnChangeValA(string val) {
			mathNode.a = float.Parse(valA.text);
		}

		private void OnChangeValB(string val) {
			mathNode.b = float.Parse(valB.text);
		}

		private void OnChangeDropdown(int val) {
			mathNode.mathType = (MathNode.MathType) val;
		}
	}
}