From 15740faf9fe9fe4be08965098bbf2947e096aeeb Mon Sep 17 00:00:00 2001 From: chai Date: Wed, 14 Aug 2019 22:50:43 +0800 Subject: +Unity Runtime code --- .../LogicNodeLibrary/Input/OnButton.cs | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Runtime/Graphs/UnityEngine.Graphs/LogicNodeLibrary/Input/OnButton.cs (limited to 'Runtime/Graphs/UnityEngine.Graphs/LogicNodeLibrary/Input/OnButton.cs') 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 (); + } + } + } + } +} + -- cgit v1.1-26-g67d0