using System; using UnityEngine; using UnityEngine.Events; using UnityEngine.InputSystem; public class InputManager : MonoBehaviour, GameInput.IPlayerActions { // 외부에서 InputManager.Instance.OnXxx_Event += handler 형태로 구독. public static InputManager Instance { get; private set; } private GameInput _input; public event Action OnDialogNext_Event; private void Awake() { if (Instance == null) { Instance = this; //만들어진 자신을 인스턴스로 설정 } else { Destroy(gameObject); //이미 인스턴스가 있으면 자신을 파괴 } _input = new GameInput(); _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 OnDialogNext(InputAction.CallbackContext ctx) { if (ctx.phase == InputActionPhase.Started) OnDialogNext_Event?.Invoke(); } }