summaryrefslogtreecommitdiff
path: root/Runtime/Graphs/UnityEngine.Graphs/LogicNodeLibrary/Input/OnButton.cs
blob: a5d08094b65aacf9c42733ed89da43ce1753e845 (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
using UnityEngine;

namespace UnityEngine.Graphs.LogicGraph
{
	public partial class InputNodes
	{
		[Logic]
		[Title("Input/On Button")]
		public sealed class OnButton : OnStateInputNode
		{
			private string m_ButtonName;
			public string buttonName { set { m_ButtonName = value; } }

			public OnButton (GraphBehaviour graphBehaviour) : base (graphBehaviour) { }
			public OnButton (IMonoBehaviourEventCaller graphBehaviour, string buttonName) : base (graphBehaviour)
			{
				m_ButtonName = buttonName;
			}

			protected override void OnUpdate ()
			{
				if (onDown != null && Input.GetButtonDown (m_ButtonName))
					onDown ();

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

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