- 1.7.0 Input System에서는 문제 없다가 1.8.2로 업그레이드되면서 처음 PlayerInput의 모든 Action이 Enable되는 현상이 생겼습니다. - CombatPlayer프리팹에서 PlayerInput컴포넌트를 비활성화 하고, 생성과 동시에 활성화합니다. - 첫 번째 튜토리얼에 진입하는 순간, 키 입력을 순간적으로 비활성화하고 되돌립니다. Closes #1
125 lines
3.8 KiB
C#
125 lines
3.8 KiB
C#
using UnityEngine;
|
|
using UnityEngine.InputSystem;
|
|
|
|
namespace BlueWater
|
|
{
|
|
public enum InputActionMaps
|
|
{
|
|
None = 0,
|
|
Combat,
|
|
CombatUi,
|
|
}
|
|
|
|
public class PlayerInputKeyManager : Singleton<PlayerInputKeyManager>
|
|
{
|
|
[SerializeField]
|
|
private PlayerInput _currentPlayerInput;
|
|
private string _previousInputActionMaps;
|
|
private InputActionMap _previousInputActionMap;
|
|
|
|
/// <summary>
|
|
/// 현재 실행되고 있는 PlayerInput을 관리할 수 있게
|
|
/// PlayerInput 컴포넌트를 받아와서 사용하는 경우에 필수로 호출
|
|
/// </summary>
|
|
/// <param name="playerInput"></param>
|
|
public void SetCurrentPlayerInput(PlayerInput playerInput) => _currentPlayerInput = playerInput;
|
|
|
|
private bool IsNullCurrentPlayerInput()
|
|
{
|
|
if (_currentPlayerInput) return false;
|
|
|
|
Debug.Log("CurrentPlayerInput가 할당되지 않았습니다.");
|
|
return true;
|
|
}
|
|
|
|
public void SwitchCurrentActionMap(string inputActionMaps)
|
|
{
|
|
if (IsNullCurrentPlayerInput()) return;
|
|
|
|
_previousInputActionMaps = _currentPlayerInput.currentActionMap.name;
|
|
_currentPlayerInput.SwitchCurrentActionMap(inputActionMaps);
|
|
}
|
|
|
|
public void SwitchCurrentActionMap(InputActionMaps inputActionMaps)
|
|
{
|
|
if (IsNullCurrentPlayerInput()) return;
|
|
|
|
_previousInputActionMaps = _currentPlayerInput.currentActionMap.name;
|
|
_currentPlayerInput.SwitchCurrentActionMap(inputActionMaps.ToString());
|
|
}
|
|
|
|
public void SwitchPreviousActionMap()
|
|
{
|
|
if (IsNullCurrentPlayerInput()) return;
|
|
|
|
if (string.IsNullOrEmpty(_previousInputActionMaps))
|
|
{
|
|
Debug.Log("저장된 _previousInputActionMaps값이 없습니다.");
|
|
return;
|
|
}
|
|
|
|
_currentPlayerInput.SwitchCurrentActionMap(_previousInputActionMaps);
|
|
_previousInputActionMaps = null;
|
|
}
|
|
|
|
public InputActionMap GetCurrentInputActionMap()
|
|
{
|
|
if (IsNullCurrentPlayerInput()) return null;
|
|
|
|
return _currentPlayerInput.currentActionMap;
|
|
}
|
|
|
|
public void EnableCurrentPlayerInput()
|
|
{
|
|
if (IsNullCurrentPlayerInput()) return;
|
|
|
|
_currentPlayerInput.enabled = true;
|
|
}
|
|
|
|
public void DisableCurrentPlayerInput()
|
|
{
|
|
if (IsNullCurrentPlayerInput()) return;
|
|
|
|
_currentPlayerInput.enabled = false;
|
|
}
|
|
|
|
public void DisableAllActionMaps()
|
|
{
|
|
if (IsNullCurrentPlayerInput()) return;
|
|
|
|
foreach (var element in _currentPlayerInput.actions.actionMaps)
|
|
{
|
|
element.Disable();
|
|
}
|
|
}
|
|
|
|
public void DisableAllActionsExcept(string exceptActionName)
|
|
{
|
|
if (IsNullCurrentPlayerInput()) return;
|
|
|
|
var exceptAction = _currentPlayerInput.currentActionMap.FindAction(exceptActionName);
|
|
|
|
foreach (var action in _currentPlayerInput.currentActionMap.actions)
|
|
{
|
|
if (action != exceptAction)
|
|
{
|
|
action.Disable();
|
|
}
|
|
else
|
|
{
|
|
action.Enable();
|
|
}
|
|
}
|
|
}
|
|
|
|
public void EnableAllActions()
|
|
{
|
|
if (IsNullCurrentPlayerInput()) return;
|
|
|
|
foreach (var action in _currentPlayerInput.actions)
|
|
{
|
|
action.Enable();
|
|
}
|
|
}
|
|
}
|
|
} |