입력 시스템 개선
각자의 입력 처리 로직을 갖지 않고 NetworkPlayerController로부터 받아서 쓰도록 함
This commit is contained in:
@@ -34,7 +34,6 @@ namespace Northbound
|
||||
private int currentRotation = 0; // 0-3
|
||||
private Material[] originalMaterials;
|
||||
private Renderer[] previewRenderers;
|
||||
private PlayerInputActions _inputActions;
|
||||
|
||||
// 드래그 건설 관련
|
||||
private bool isDragging = false;
|
||||
@@ -53,35 +52,29 @@ namespace Northbound
|
||||
{
|
||||
_playerController = GetComponent<NetworkPlayerController>();
|
||||
|
||||
// 지연 초기화 - 다음 프레임에 체크
|
||||
StartCoroutine(InitializeAfterOwnerSet());
|
||||
if (_playerController != null)
|
||||
{
|
||||
_playerController.OnInputInitialized += TryInitializeInput;
|
||||
}
|
||||
|
||||
// 이미 로컬 플레이어면 입력 초기화 시도
|
||||
TryInitializeInput();
|
||||
}
|
||||
|
||||
private System.Collections.IEnumerator InitializeAfterOwnerSet()
|
||||
private void TryInitializeInput()
|
||||
{
|
||||
// _ownerPlayerId가 설정될 때까지 대기 (최대 1초)
|
||||
float timeout = 1f;
|
||||
while (_playerController != null && _playerController.OwnerPlayerId == ulong.MaxValue && timeout > 0)
|
||||
{
|
||||
yield return null;
|
||||
timeout -= Time.deltaTime;
|
||||
}
|
||||
|
||||
// 로컬 플레이어인지 확인
|
||||
if (_playerController == null || !_playerController.IsLocalPlayer)
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
if (_isInitialized) return; // 이미 초기화됨
|
||||
if (_playerController == null || !_playerController.IsLocalPlayer) return;
|
||||
if (_playerController.InputActions == null) return;
|
||||
|
||||
_isInitialized = true;
|
||||
|
||||
_inputActions = new PlayerInputActions();
|
||||
_inputActions.Player.ToggleBuildMode.performed += OnToggleBuildMode;
|
||||
_inputActions.Player.Rotate.performed += OnRotate;
|
||||
_inputActions.Player.Build.performed += OnBuildPressed;
|
||||
_inputActions.Player.Build.canceled += OnBuildReleased;
|
||||
_inputActions.Player.Cancel.performed += OnCancel;
|
||||
_inputActions.Enable();
|
||||
var inputActions = _playerController.InputActions;
|
||||
inputActions.Player.ToggleBuildMode.performed += OnToggleBuildMode;
|
||||
inputActions.Player.Rotate.performed += OnRotate;
|
||||
inputActions.Player.Build.performed += OnBuildPressed;
|
||||
inputActions.Player.Build.canceled += OnBuildReleased;
|
||||
inputActions.Player.Cancel.performed += OnCancel;
|
||||
|
||||
// Create default materials if not assigned
|
||||
if (validMaterial == null)
|
||||
@@ -144,15 +137,19 @@ namespace Northbound
|
||||
|
||||
public override void OnNetworkDespawn()
|
||||
{
|
||||
if (_isInitialized && _inputActions != null)
|
||||
if (_playerController != null)
|
||||
{
|
||||
_inputActions.Player.ToggleBuildMode.performed -= OnToggleBuildMode;
|
||||
_inputActions.Player.Rotate.performed -= OnRotate;
|
||||
_inputActions.Player.Build.performed -= OnBuildPressed;
|
||||
_inputActions.Player.Build.canceled -= OnBuildReleased;
|
||||
_inputActions.Player.Cancel.performed -= OnCancel;
|
||||
_inputActions.Disable();
|
||||
_inputActions.Dispose();
|
||||
_playerController.OnInputInitialized -= TryInitializeInput;
|
||||
|
||||
if (_isInitialized && _playerController.InputActions != null)
|
||||
{
|
||||
var inputActions = _playerController.InputActions;
|
||||
inputActions.Player.ToggleBuildMode.performed -= OnToggleBuildMode;
|
||||
inputActions.Player.Rotate.performed -= OnRotate;
|
||||
inputActions.Player.Build.performed -= OnBuildPressed;
|
||||
inputActions.Player.Build.canceled -= OnBuildReleased;
|
||||
inputActions.Player.Cancel.performed -= OnCancel;
|
||||
}
|
||||
}
|
||||
|
||||
ClearDragPreviews();
|
||||
|
||||
Reference in New Issue
Block a user