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