Keyboard WASD#
Input / Keyboard WASD
Can Read
Cannot Write
Description#
Returns the value of the W, A, S and D keys as a Vector2
Code#
using System;
using UnityEngine;
using UnityEngine.InputSystem;
using VisualScript.Icons;
namespace VisualScript.Runtime
{
[Get]
[Title("Keyboard WASD")]
[Category("Input/Keyboard WASD")]
[Description("Returns the value of the W, A, S and D keys as a Vector2")]
[Image(typeof(IconWASD), ColorTheme.Type.Blue)]
[Keywords("Move", "Keys")]
[Serializable]
public class TypeVector2InputKeyboardWASD : TypeVector2
{
[NonSerialized] private UnityEngine.InputSystem.InputAction m_InputAction;
~TypeVector2InputKeyboardWASD()
{
this.m_InputAction?.Disable();
this.m_InputAction?.Dispose();
}
public UnityEngine.InputSystem.InputAction InputAction
{
get
{
if (this.m_InputAction == null)
{
this.m_InputAction = new UnityEngine.InputSystem.InputAction(
"WASD",
InputActionType.Value
);
this.m_InputAction.AddCompositeBinding("2DVector")
.With("Up", "<Keyboard>/w")
.With("Down", "<Keyboard>/s")
.With("Left", "<Keyboard>/a")
.With("Right", "<Keyboard>/d");
this.m_InputAction.Enable();
}
return this.m_InputAction;
}
}
public override Vector2 Get(Args args)
{
return this.InputAction?.ReadValue<Vector2>() ?? default;
}
public override string ToString()
{
return "Keyboard WASD";
}
protected override SubscriptionMode Subscription => SubscriptionMode.OnChange;
}
}