summaryrefslogtreecommitdiff
path: root/Runtime/Graphs/UnityEngine.Graphs/LogicNodeLibrary/Input/InputNodes.cs
blob: d1687db92724183cfb5face9aa8334d8efeaf8fc (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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using UnityEngine;

namespace UnityEngine.Graphs.LogicGraph
{
	public partial class InputNodes
	{
		public delegate void AxisDelegate (float value);
		public delegate void MouseDelegate (Vector3 mousePosition);

		[Logic]
		[Title("Input/Get Button")]
		public static void GetButton(string buttonName, Action onDown, Action onUp, Action down, Action up)
		{
			if (onDown != null && Input.GetButtonDown (buttonName))
				onDown ();

			if (onUp != null && Input.GetButtonUp (buttonName))
				onUp ();

			if (down != null || up != null)
			{
				var stateDelegate = Input.GetButton (buttonName) ? down : up;
				if (stateDelegate != null)
					stateDelegate ();
			}
		}

		[Logic]
		[Title("Input/Get Mouse Button")]
		public static void GetMouseButton (int mouseButton, MouseDelegate onDown, MouseDelegate onUp, MouseDelegate down, MouseDelegate up)
		{
			if (onDown != null && Input.GetMouseButtonDown(mouseButton))
				onDown(Input.mousePosition);

			if (onUp != null && Input.GetMouseButtonUp(mouseButton))
				onUp(Input.mousePosition);

			if (down != null || up != null)
			{
				MouseDelegate stateDelegate = Input.GetMouseButton(mouseButton) ? down : up;
				if (stateDelegate != null)
					stateDelegate(Input.mousePosition);
			}
		}

		[Logic]
		[Title("Input/Get Key")]
		public static void GetKey(KeyCode key, Action onDown, Action onUp, Action down, Action up)
		{
			if (onDown != null && Input.GetKeyDown (key))
				onDown ();

			if (onUp != null && Input.GetKeyUp (key))
				onUp ();

			if (down != null || up != null)
			{
				var stateDelegate = Input.GetKey (key) ? down : up;
				if (stateDelegate != null)
					stateDelegate ();
			}
		}

		[Logic]
		[Title("Input/Get Axis")]
		public static void GetAxis(string axisName, AxisDelegate down, AxisDelegate up)
		{
			AxisDelegate stateDelegate = Input.GetButton (axisName) ? down : up;
			if (stateDelegate != null)
				stateDelegate (Input.GetAxis (axisName));
		}

		[LogicEval]
		[Title("Input/Mouse Position")]
		[return: Title("Mouse Position")]
		public static Vector3 MousePosition ()
		{
			return Input.mousePosition;
		}
	}
}