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