Gamepad Buttons#
Input / Gamepad Buttons
Can Read
Cannot Write
Description#
Returns the value of four custom Gamepad buttons as a Vector2
Parameters#
| Name | Description |
|---|---|
| Up | The button that pushes the value towards the positive Y axis |
| Left | The button that pushes the value towards the negative X axis |
| Down | The button that pushes the value towards the negative Y axis |
| Right | The button that pushes the value towards the positive X axis |
Code#
using System;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.LowLevel;
using VisualScript.Icons;
namespace VisualScript.Runtime
{
[Get]
[Title("Gamepad Buttons")]
[Category("Input/Gamepad Buttons")]
[Description("Returns the value of four custom Gamepad buttons as a Vector2")]
[Image(typeof(IconGamepad), ColorTheme.Type.Blue, typeof(BadgeArrowUp))]
[Parameter("Up", "The button that pushes the value towards the positive Y axis")]
[Parameter("Left", "The button that pushes the value towards the negative X axis")]
[Parameter("Down", "The button that pushes the value towards the negative Y axis")]
[Parameter("Right", "The button that pushes the value towards the positive X axis")]
[Keywords("Move", "Buttons", "Composite", "Custom", "Direction")]
[Serializable]
public class TypeVector2InputGamepadButtons : TypeVector2
{
[SerializeField] private GamepadButton m_Up = GamepadButton.DpadUp;
[SerializeField] private GamepadButton m_Left = GamepadButton.DpadLeft;
[SerializeField] private GamepadButton m_Down = GamepadButton.DpadDown;
[SerializeField] private GamepadButton m_Right = GamepadButton.DpadRight;
public override Vector2 Get(Args args)
{
Gamepad gamepad = Gamepad.current;
if (gamepad == null) return default;
Vector2 value = Vector2.zero;
if (gamepad[this.m_Up].isPressed) value += Vector2.up;
if (gamepad[this.m_Left].isPressed) value += Vector2.left;
if (gamepad[this.m_Down].isPressed) value += Vector2.down;
if (gamepad[this.m_Right].isPressed) value += Vector2.right;
return value.normalized;
}
public override string ToString()
{
return $"Buttons {this.m_Up} {this.m_Left} {this.m_Down} {this.m_Right}";
}
protected override SubscriptionMode Subscription => SubscriptionMode.OnChange;
}
}