인풋매니저 구조 개선 (키 직접 할당 방식)
This commit is contained in:
parent
7096e82d43
commit
7d9c064165
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.InputSystem;
|
using UnityEngine.InputSystem;
|
||||||
@ -21,13 +22,49 @@ public enum InputActionMaps
|
|||||||
RestaurantUi = 3
|
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<InputManager>, IManager
|
public class InputManager : Singleton<InputManager>, IManager
|
||||||
{
|
{
|
||||||
private PlayerInput _currentPlayerInput;
|
private PlayerInput _currentPlayerInput;
|
||||||
|
|
||||||
|
public InputActionMaps CurrentInputActionMap { get; private set; }
|
||||||
|
|
||||||
|
private readonly Dictionary<(InputActionMaps, string), InputAction> _cachedActions = new();
|
||||||
|
|
||||||
public void PreInit()
|
public void PreInit()
|
||||||
{
|
{
|
||||||
_currentPlayerInput = GetComponent<PlayerInput>();
|
_currentPlayerInput = GetComponent<PlayerInput>();
|
||||||
|
|
||||||
|
_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()
|
public Task Init()
|
||||||
@ -50,23 +87,33 @@ private bool IsNullCurrentPlayerInput()
|
|||||||
|
|
||||||
public void SwitchCurrentActionMap(InputActionMaps inputActionMaps)
|
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());
|
_currentPlayerInput.SwitchCurrentActionMap(inputActionMaps.ToName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public InputActionMaps GetCurrentActionMap()
|
public InputAction GetAction(InputActionMaps map, string actionName)
|
||||||
{
|
{
|
||||||
if (IsNullCurrentPlayerInput()) return InputActionMaps.None;
|
if (_cachedActions.TryGetValue((map, actionName), out var action))
|
||||||
|
|
||||||
string mapName = _currentPlayerInput.currentActionMap.name;
|
|
||||||
if (Enum.TryParse(mapName, out InputActionMaps parsedMap))
|
|
||||||
{
|
{
|
||||||
return parsedMap;
|
return action;
|
||||||
}
|
}
|
||||||
|
|
||||||
Debug.LogError($"[InputManager] 알 수 없는 ActionMap 이름: {mapName}");
|
Debug.LogError($"[InputManager] Action '{actionName}' in Map '{map}' not found!");
|
||||||
return InputActionMaps.None;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public InputAction GetAction<TActionEnum>(InputActionMaps map, TActionEnum actionEnum)
|
||||||
|
where TActionEnum : Enum
|
||||||
|
{
|
||||||
|
return GetAction(map, actionEnum.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public InputActionMaps GetCurrentActionMap() => CurrentInputActionMap;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user