Is Any Gamepad Button Pressed#
Input / Is Any Gamepad Button Pressed
Can Read
Cannot Write
Description#
Returns true if any button of the current Gamepad is being held down
Code#
using System;
using Unity.Scripting.LifecycleManagement;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.LowLevel;
using VisualScript.Icons;
namespace VisualScript.Runtime
{
[Get]
[Title("Is Any Gamepad Button Pressed")]
[Category("Input/Is Any Gamepad Button Pressed")]
[Description("Returns true if any button of the current Gamepad is being held down")]
[Image(typeof(IconGamepad), ColorTheme.Type.Blue, typeof(BadgeMagnifier))]
[Keywords("Button", "Down", "Every", "Some")]
[Serializable]
public class TypeBoolInputGamepadAnyPress : TypeBool
{
[NoAutoStaticsCleanup]
private static readonly GamepadButton[] BUTTONS =
{
GamepadButton.North,
GamepadButton.South,
GamepadButton.East,
GamepadButton.West,
GamepadButton.LeftStick,
GamepadButton.RightStick,
GamepadButton.LeftShoulder,
GamepadButton.RightShoulder,
GamepadButton.LeftTrigger,
GamepadButton.RightTrigger,
GamepadButton.Start,
GamepadButton.Select,
GamepadButton.DpadUp,
GamepadButton.DpadDown,
GamepadButton.DpadLeft,
GamepadButton.DpadRight
};
public override bool Get(Args args)
{
Gamepad gamepad = Gamepad.current;
if (gamepad == null) return false;
foreach (GamepadButton button in BUTTONS)
{
if (gamepad[button].isPressed) return true;
}
return false;
}
public override string ToString()
{
return "Pressing any Gamepad Button";
}
protected override SubscriptionMode Subscription => SubscriptionMode.OnChange;
}
}