45 lines
1.1 KiB
C#
45 lines
1.1 KiB
C#
using SepCore.InputModule;
|
|
using UnityEngine;
|
|
|
|
namespace SepCore.Components
|
|
{
|
|
public class InputComponent : MonoBehaviour
|
|
{
|
|
private bool _isListening = false;
|
|
|
|
[SerializeField] private Vector3 _direction = Vector3.zero;
|
|
public Vector3 Direction => _direction;
|
|
|
|
public void OnInit()
|
|
{
|
|
GameEntry.InputModule.RegisterListener(InputActionId.Move, OnMove);
|
|
}
|
|
|
|
public void OnUpdate(float elapseSeconds, float realElapseSeconds)
|
|
{
|
|
}
|
|
|
|
public void OnReset()
|
|
{
|
|
GameEntry.InputModule.UnregisterListener(InputActionId.Move, OnMove);
|
|
_isListening = false;
|
|
_direction = Vector3.zero;
|
|
}
|
|
|
|
private void OnMove(InputCommand cmd)
|
|
{
|
|
if (!_isListening) return;
|
|
Vector2 raw = cmd.Vector2Value;
|
|
_direction = new Vector3(raw.x, 0, raw.y);
|
|
}
|
|
|
|
public void SetListening(bool isListening)
|
|
{
|
|
_isListening = isListening;
|
|
if (!_isListening)
|
|
{
|
|
_direction = Vector3.zero;
|
|
}
|
|
}
|
|
}
|
|
} |