using UnityEngine; namespace Unity.VisualScripting { /// /// A configurable event to handle global keyboard input. /// [UnitCategory("Events/Input")] public sealed class OnKeyboardInput : MachineEventUnit { protected override string hookName => EventHooks.Update; /// /// The key that received input. /// [DoNotSerialize] public ValueInput key { get; private set; } /// /// The type of input. /// [DoNotSerialize] public ValueInput action { get; private set; } protected override void Definition() { base.Definition(); key = ValueInput(nameof(key), KeyCode.Space); action = ValueInput(nameof(action), PressState.Down); } protected override bool ShouldTrigger(Flow flow, EmptyEventArgs args) { var key = flow.GetValue(this.key); var action = flow.GetValue(this.action); switch (action) { case PressState.Down: return Input.GetKeyDown(key); case PressState.Up: return Input.GetKeyUp(key); case PressState.Hold: return Input.GetKey(key); default: throw new UnexpectedEnumValueException(action); } } } }