From 7d9c064165145add72075dbeab0d813fbf2b4045 Mon Sep 17 00:00:00 2001 From: NTG_Lenovo Date: Wed, 23 Jul 2025 12:23:25 +0900 Subject: [PATCH] =?UTF-8?q?=EC=9D=B8=ED=92=8B=EB=A7=A4=EB=8B=88=EC=A0=80?= =?UTF-8?q?=20=EA=B5=AC=EC=A1=B0=20=EA=B0=9C=EC=84=A0=20(=ED=82=A4=20?= =?UTF-8?q?=EC=A7=81=EC=A0=91=20=ED=95=A0=EB=8B=B9=20=EB=B0=A9=EC=8B=9D)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../_DDD/_Scripts/InputSystem/InputManager.cs | 69 ++++++++++++++++--- 1 file changed, 58 insertions(+), 11 deletions(-) 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