清理项目目录,引入 InputModule 做多平台输入适配
This commit is contained in:
@@ -1,50 +1,44 @@
|
||||
using SepCore.InputModule;
|
||||
using UnityEngine;
|
||||
|
||||
namespace SepCore.Components
|
||||
{
|
||||
public class InputComponent : MonoBehaviour
|
||||
{
|
||||
private PlayerInputActions _inputActions;
|
||||
[SerializeField] private bool _isListening = false;
|
||||
private bool _isListening = false;
|
||||
|
||||
[SerializeField] private Vector3 _direction = Vector3.zero;
|
||||
public Vector3 Direction => _direction;
|
||||
|
||||
public void OnInit()
|
||||
{
|
||||
_inputActions = new();
|
||||
GameEntry.InputModule.RegisterListener(InputActionId.Move, OnMove);
|
||||
}
|
||||
|
||||
public void OnUpdate(float elapseSeconds, float realElapseSeconds)
|
||||
{
|
||||
if (_isListening && _inputActions != null)
|
||||
{
|
||||
ReadInput();
|
||||
}
|
||||
}
|
||||
|
||||
public void OnReset()
|
||||
{
|
||||
_inputActions = null;
|
||||
GameEntry.InputModule.UnregisterListener(InputActionId.Move, OnMove);
|
||||
_isListening = false;
|
||||
_direction = Vector3.zero;
|
||||
}
|
||||
|
||||
private void ReadInput()
|
||||
private void OnMove(InputCommand cmd)
|
||||
{
|
||||
Vector2 rawDir = _inputActions.Game.Move.ReadValue<Vector2>();
|
||||
_direction = new Vector3(rawDir.x, 0, rawDir.y);
|
||||
if (!_isListening) return;
|
||||
Vector2 raw = cmd.Vector2Value;
|
||||
_direction = new Vector3(raw.x, 0, raw.y);
|
||||
}
|
||||
|
||||
public void SetListening(bool isListening)
|
||||
{
|
||||
_isListening = isListening;
|
||||
if (_isListening)
|
||||
if (!_isListening)
|
||||
{
|
||||
_inputActions.Enable();
|
||||
}
|
||||
else
|
||||
{
|
||||
_inputActions.Disable();
|
||||
_direction = Vector3.zero;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user