A game about forced loneliness, made by TACStudios
1using UnityEngine; 2 3namespace Unity.VisualScripting 4{ 5 /// <summary> 6 /// A configurable event to handle global keyboard input. 7 /// </summary> 8 [UnitCategory("Events/Input")] 9 public sealed class OnKeyboardInput : MachineEventUnit<EmptyEventArgs> 10 { 11 protected override string hookName => EventHooks.Update; 12 13 /// <summary> 14 /// The key that received input. 15 /// </summary> 16 [DoNotSerialize] 17 public ValueInput key { get; private set; } 18 19 /// <summary> 20 /// The type of input. 21 /// </summary> 22 [DoNotSerialize] 23 public ValueInput action { get; private set; } 24 25 protected override void Definition() 26 { 27 base.Definition(); 28 29 key = ValueInput(nameof(key), KeyCode.Space); 30 action = ValueInput(nameof(action), PressState.Down); 31 } 32 33 protected override bool ShouldTrigger(Flow flow, EmptyEventArgs args) 34 { 35 var key = flow.GetValue<KeyCode>(this.key); 36 var action = flow.GetValue<PressState>(this.action); 37 38 switch (action) 39 { 40 case PressState.Down: return Input.GetKeyDown(key); 41 case PressState.Up: return Input.GetKeyUp(key); 42 case PressState.Hold: return Input.GetKey(key); 43 default: throw new UnexpectedEnumValueException<PressState>(action); 44 } 45 } 46 } 47}