While Mouse Pressing#
Input / Mouse / While Mouse Pressing
Description#
Executes every frame that the Mouse button is being held down
Code#
using System;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.InputSystem.LowLevel;
using VisualScript.Icons;
namespace VisualScript.Runtime
{
[Title("While Mouse Pressing")]
[Image(typeof(IconMouse), ColorTheme.Type.Blue, typeof(BadgeDot))]
[Description("Executes every frame that the Mouse button is being held down")]
[Category("Input/Mouse/While Pressing")]
[Keywords("Button", "Hold", "Down")]
[Serializable]
public class TriggerCoreInputMouseHold : TriggerHandleSubscriptionBase<HandleOnInputMouse>
{
// EXPOSED MEMBERS: -----------------------------------------------------------------------
[SerializeField] private MouseButton m_Button = MouseButton.Left;
// PROPERTIES: ----------------------------------------------------------------------------
protected override string GetTitle(GameObject source)
{
string button = TextUtils.Humanize(this.m_Button);
return $"Pressing {TextUtils.ThemeAsKeyword(button)} Down";
}
// OVERRIDE METHODS: ----------------------------------------------------------------------
protected override void OnTrigger(GameObject target)
{
ButtonControl button = this.m_Button switch
{
MouseButton.Left => Mouse.current.leftButton,
MouseButton.Right => Mouse.current.rightButton,
MouseButton.Middle => Mouse.current.middleButton,
MouseButton.Forward => Mouse.current.forwardButton,
MouseButton.Back => Mouse.current.backButton,
_ => throw new ArgumentOutOfRangeException()
};
if (!button.isPressed) return;
using Args args = Args.Get(this.Component, target);
this.Run(args);
}
}
}