ProjectDDD/Assets/_DDD/_Scripts/InputSystem/InputManager.cs

72 lines
1.8 KiB
C#
Raw Normal View History

2025-07-09 09:45:11 +00:00
using System;
2025-07-22 07:46:37 +00:00
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.InputSystem;
namespace DDD
{
2025-07-22 07:46:37 +00:00
public static class InputActionMapExtensions
{
2025-07-22 07:46:37 +00:00
public static string ToName(this InputActionMaps map)
{
return map.ToString();
}
}
2025-07-09 09:45:11 +00:00
2025-07-22 07:46:37 +00:00
public enum InputActionMaps
{
2025-07-09 09:45:11 +00:00
None = 0,
2025-07-22 07:46:37 +00:00
Ui = 1,
Restaurant = 2,
RestaurantUi = 3
}
2025-07-22 07:46:37 +00:00
public class InputManager : Singleton<InputManager>, IManager
{
private PlayerInput _currentPlayerInput;
2025-07-22 07:46:37 +00:00
public void PreInit()
{
2025-07-22 07:46:37 +00:00
_currentPlayerInput = GetComponent<PlayerInput>();
}
2025-07-22 07:46:37 +00:00
public Task Init()
{
2025-07-22 07:46:37 +00:00
return Task.CompletedTask;
}
2025-07-22 07:46:37 +00:00
public void PostInit()
{
2025-07-22 07:46:37 +00:00
}
2025-07-22 07:46:37 +00:00
private bool IsNullCurrentPlayerInput()
{
2025-07-22 07:46:37 +00:00
if (_currentPlayerInput && _currentPlayerInput.enabled) return false;
2025-07-22 07:46:37 +00:00
Debug.Log("CurrentPlayerInput가 할당되지 않았습니다.");
return true;
}
public void SwitchCurrentActionMap(InputActionMaps inputActionMaps)
{
2025-07-22 07:46:37 +00:00
if (IsNullCurrentPlayerInput() || inputActionMaps == InputActionMaps.None) return;
2025-07-22 07:46:37 +00:00
_currentPlayerInput.SwitchCurrentActionMap(inputActionMaps.ToName());
}
2025-07-22 07:46:37 +00:00
public InputActionMaps GetCurrentActionMap()
{
2025-07-22 07:46:37 +00:00
if (IsNullCurrentPlayerInput()) return InputActionMaps.None;
2025-07-22 07:46:37 +00:00
string mapName = _currentPlayerInput.currentActionMap.name;
if (Enum.TryParse(mapName, out InputActionMaps parsedMap))
{
2025-07-22 07:46:37 +00:00
return parsedMap;
}
2025-07-22 07:46:37 +00:00
Debug.LogError($"[InputManager] 알 수 없는 ActionMap 이름: {mapName}");
return InputActionMaps.None;
}
}
}