diff --git a/Assets/_DDD/_Scripts/InputSystem/InputManager.cs b/Assets/_DDD/_Scripts/InputSystem/InputManager.cs index 73924ae98..c88cd36b5 100644 --- a/Assets/_DDD/_Scripts/InputSystem/InputManager.cs +++ b/Assets/_DDD/_Scripts/InputSystem/InputManager.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Threading.Tasks; using UnityEngine; using UnityEngine.InputSystem; @@ -21,13 +22,49 @@ public enum InputActionMaps RestaurantUi = 3 } + [Flags] + public enum RestaurantActions + { + None = 0, + Move = 1 << 0, + Dash = 1 << 1, + OpenManagementUi = 1 << 2, + } + + [Flags] + public enum RestaurantUiActions + { + None = 0, + Submit = 1 << 0, + Cancel = 1 << 1, + PreviousTab = 1 << 2, + NextTab = 1 << 3, + Interact1 = 1 << 4, + Interact2 = 1 << 5, + } + public class InputManager : Singleton, IManager { private PlayerInput _currentPlayerInput; + public InputActionMaps CurrentInputActionMap { get; private set; } + + private readonly Dictionary<(InputActionMaps, string), InputAction> _cachedActions = new(); + public void PreInit() { _currentPlayerInput = GetComponent(); + + _cachedActions.Clear(); + foreach (var actionMap in _currentPlayerInput.actions.actionMaps) + { + if (!Enum.TryParse(actionMap.name, out InputActionMaps mapEnum)) continue; + + foreach (var action in actionMap.actions) + { + _cachedActions[(mapEnum, action.name)] = action; + } + } } public Task Init() @@ -50,23 +87,33 @@ private bool IsNullCurrentPlayerInput() public void SwitchCurrentActionMap(InputActionMaps inputActionMaps) { - if (IsNullCurrentPlayerInput() || inputActionMaps == InputActionMaps.None) return; + if (IsNullCurrentPlayerInput() || inputActionMaps == InputActionMaps.None) + { + CurrentInputActionMap = InputActionMaps.None; + return; + } + CurrentInputActionMap = inputActionMaps; _currentPlayerInput.SwitchCurrentActionMap(inputActionMaps.ToName()); } - - public InputActionMaps GetCurrentActionMap() + + public InputAction GetAction(InputActionMaps map, string actionName) { - if (IsNullCurrentPlayerInput()) return InputActionMaps.None; - - string mapName = _currentPlayerInput.currentActionMap.name; - if (Enum.TryParse(mapName, out InputActionMaps parsedMap)) + if (_cachedActions.TryGetValue((map, actionName), out var action)) { - return parsedMap; + return action; } - - Debug.LogError($"[InputManager] 알 수 없는 ActionMap 이름: {mapName}"); - return InputActionMaps.None; + + Debug.LogError($"[InputManager] Action '{actionName}' in Map '{map}' not found!"); + return null; } + + public InputAction GetAction(InputActionMaps map, TActionEnum actionEnum) + where TActionEnum : Enum + { + return GetAction(map, actionEnum.ToString()); + } + + public InputActionMaps GetCurrentActionMap() => CurrentInputActionMap; } } \ No newline at end of file