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