using UnityEngine; namespace Unity.VisualScripting { /// /// A configurable event to handle global button input. /// [UnitCategory("Events/Input")] public sealed class OnButtonInput : MachineEventUnit { protected override string hookName => EventHooks.Update; /// /// The name of the button that received input. /// [DoNotSerialize] [PortLabel("Name")] public ValueInput buttonName { get; private set; } /// /// The type of input. /// [DoNotSerialize] public ValueInput action { get; private set; } protected override void Definition() { base.Definition(); buttonName = ValueInput(nameof(buttonName), string.Empty); action = ValueInput(nameof(action), PressState.Down); } protected override bool ShouldTrigger(Flow flow, EmptyEventArgs args) { var buttonName = flow.GetValue(this.buttonName); var action = flow.GetValue(this.action); switch (action) { case PressState.Down: return Input.GetButtonDown(buttonName); case PressState.Up: return Input.GetButtonUp(buttonName); case PressState.Hold: return Input.GetButton(buttonName); default: throw new UnexpectedEnumValueException(action); } } } }