diff options
Diffstat (limited to 'Runtime/Graphs/UnityEngine.Graphs/LogicNodeLibrary/Input/OnButton.cs')
-rw-r--r-- | Runtime/Graphs/UnityEngine.Graphs/LogicNodeLibrary/Input/OnButton.cs | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/Runtime/Graphs/UnityEngine.Graphs/LogicNodeLibrary/Input/OnButton.cs b/Runtime/Graphs/UnityEngine.Graphs/LogicNodeLibrary/Input/OnButton.cs new file mode 100644 index 0000000..a5d0809 --- /dev/null +++ b/Runtime/Graphs/UnityEngine.Graphs/LogicNodeLibrary/Input/OnButton.cs @@ -0,0 +1,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 (); + } + } + } + } +} + |