using Unity.VisualScripting; using UnityEngine; using UnityEngine.InputSystem; using UnityEngine.InputSystem.Interactions;
public class GameInputManager : MonoSingle<GameInputManager> { private GameInputAction _gameInputAction; //书写按键逻辑 public Vector2 movement => _gameInputAction.GameInput.Move.ReadValue<Vector2>(); //锁敌 private bool _lock = false; //贴墙 private bool _wall = false; //切武器 private bool _weapon = false; public bool Lock { get { if (_gameInputAction.GameInput.Lock.triggered) _lock = !_lock; return _lock;
} } //格挡 public bool Parry => _gameInputAction.GameInput.Parry.IsPressed(); // 冲刺 public bool Sprint => _gameInputAction.GameInput.Sprint.triggered;
// 疾跑 public bool Fast_Run => _gameInputAction.GameInput.Fast_Run.IsPressed(); //攻击 public bool LeftAttack => _gameInputAction.GameInput.LeftAttack.triggered; public bool RightAttack => _gameInputAction.GameInput.RightAttack.triggered;
//相机 public Vector2 Camera => _gameInputAction.GameInput.Camera.ReadValue<Vector2>(); //技能 public bool Ctrl => _gameInputAction.GameInput.Ctrl.triggered; public bool Q => _gameInputAction.GameInput.Q.triggered; //切换技能 public bool Z => _gameInputAction.GameInput.Q.triggered; //贴墙 public bool X { get { if (_gameInputAction.GameInput.Lock.triggered) _wall = !_wall; return _wall; } }
//切换武器
public bool Tab { get { if (_gameInputAction.GameInput.Tab.triggered) _weapon = !_weapon; return _weapon; } }
private void OnEnable() { _gameInputAction ??= new GameInputAction(); _gameInputAction.Enable(); }