On Mouse Release#
Input / Mouse / On Mouse Release
Description#
Executes when the Mouse button is released
Code#
using System;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.InputSystem.LowLevel;
using VisualScript.Icons;
namespace VisualScript.Runtime
{
[Title("On Mouse Release")]
[Image(typeof(IconMouse), ColorTheme.Type.Blue, typeof(BadgeArrowUp))]
[Description("Executes when the Mouse button is released")]
[Category("Input/Mouse/On Release")]
[Keywords("Button", "Up", "Cursor")]
[Serializable]
public class TriggerCoreInputMouseRelease : 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 $"Release {TextUtils.ThemeAsKeyword(button)} Button";
}
// 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.wasReleasedThisFrame) return;
using Args args = Args.Get(this.Component, target);
this.Run(args);
}
}
}