On Gamepad Press#
Input / Gamepad / On Gamepad Press
Description#
Executes when the Gamepad button is pressed down
Code#
using System;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.LowLevel;
using VisualScript.Icons;
namespace VisualScript.Runtime
{
[Title("On Gamepad Press")]
[Image(typeof(IconGamepad), ColorTheme.Type.Blue, typeof(BadgeArrowDown))]
[Description("Executes when the Gamepad button is pressed down")]
[Category("Input/Gamepad/On Press")]
[Keywords("Button", "Down", "Cursor")]
[Serializable]
public class TriggerCoreInputGamepadPress : TriggerHandleSubscriptionBase<HandleOnInputGamepad>
{
// EXPOSED MEMBERS: -----------------------------------------------------------------------
[SerializeField] private GamepadButton m_Button = GamepadButton.South;
// PROPERTIES: ----------------------------------------------------------------------------
protected override string GetTitle(GameObject source)
{
string button = TextUtils.Humanize(this.m_Button);
return $"Press {TextUtils.ThemeAsKeyword(button)}";
}
// OVERRIDE METHODS: ----------------------------------------------------------------------
protected override void OnTrigger(GameObject target)
{
if (!Gamepad.current[this.m_Button].wasPressedThisFrame) return;
using Args args = Args.Get(this.Component, target);
this.Run(args);
}
}
}