43 lines
1.5 KiB
C#
43 lines
1.5 KiB
C#
using System;
|
|
using UnityEngine;
|
|
using UnityEngine.InputSystem;
|
|
|
|
public class InputManager : MonoBehaviour, GameInput.IPlayerActions
|
|
{
|
|
// 외부에서 InputManager.Instance.OnXxx_Event += handler 형태로 구독.
|
|
public static InputManager Instance { get; private set; }
|
|
|
|
private GameInput _input;
|
|
|
|
// ─── 입력 이벤트들 (PlayerController 등이 구독) ──────────────────────
|
|
public event Action OnJump_Event; // 한 번씩 (눌렀을 때)
|
|
|
|
private void Awake()
|
|
{
|
|
if (Instance == null)
|
|
{
|
|
Instance = this; //만들어진 자신을 인스턴스로 설정
|
|
DontDestroyOnLoad(gameObject);
|
|
}
|
|
else
|
|
{
|
|
Destroy(gameObject); //이미 인스턴스가 있으면 자신을 파괴
|
|
}
|
|
|
|
_input = new GameInput();
|
|
// IPlayerActions의 OnJump/... 메서드를 인풋 액션의 콜백으로 자동 연결.
|
|
_input.Player.SetCallbacks(this);
|
|
}
|
|
|
|
// GameInput은 활성/비활성 토글이 필요한 자원 ?. 처리로 Awake보다 OnEnable이 먼저 호출되는 경우 보호.
|
|
private void OnEnable() => _input?.Player.Enable();
|
|
private void OnDisable() => _input?.Player.Disable();
|
|
private void OnDestroy() => _input?.Dispose();
|
|
|
|
public void OnJump(InputAction.CallbackContext ctx)
|
|
{
|
|
if (ctx.phase == InputActionPhase.Started)
|
|
OnJump_Event?.Invoke();
|
|
}
|
|
}
|