연속 액션 기능 및 관련 설정 기능 추가
This commit is contained in:
@@ -58,6 +58,9 @@ public class PlayerNetworkController : NetworkBehaviour
|
||||
private bool _isGrounded;
|
||||
private bool _isHoldingInteract = false;
|
||||
|
||||
private bool _isHoldingAction = false;
|
||||
private bool _hasExecutedOnce = false; // 단발성 액션이 중복 실행되지 않도록 방지
|
||||
|
||||
// 현재 플레이어가 어떤 행동을 하고 있는지 나타내는 상태
|
||||
public enum ActionState { Idle, Busy }
|
||||
private ActionState _currentState = ActionState.Idle;
|
||||
@@ -102,8 +105,17 @@ public class PlayerNetworkController : NetworkBehaviour
|
||||
_inputActions.Player.Action.performed += ctx => OnActionInput();
|
||||
_inputActions.Player.Interact.performed += ctx => OnInteractTap(); // 탭 상호작용
|
||||
|
||||
_inputActions.Player.Interact.started += ctx => _isHoldingInteract = true;
|
||||
_inputActions.Player.Interact.canceled += ctx => _isHoldingInteract = false;
|
||||
// started: 버튼을 누르는 순간 즉시 첫 번째 시도
|
||||
_inputActions.Player.Action.started += ctx => {
|
||||
_isHoldingAction = true;
|
||||
_hasExecutedOnce = false; // 누르기 시작할 때 초기화
|
||||
TryExecuteAction();
|
||||
};
|
||||
|
||||
// canceled: 버튼을 떼는 순간
|
||||
_inputActions.Player.Action.canceled += ctx => {
|
||||
_isHoldingAction = false;
|
||||
};
|
||||
|
||||
_inputActions.Player.Select1.performed += ctx => _inventory.ChangeSelectedSlotRpc(0);
|
||||
_inputActions.Player.Select2.performed += ctx => _inventory.ChangeSelectedSlotRpc(1);
|
||||
@@ -147,6 +159,12 @@ public class PlayerNetworkController : NetworkBehaviour
|
||||
_lastRevealTime = Time.time;
|
||||
RevealSurroundings();
|
||||
}
|
||||
|
||||
// 버튼을 꾹 누르고 있고, 아직 액션이 진행 중이 아닐 때만 반복 체크
|
||||
if (_isHoldingAction && !_actionHandler.IsBusy)
|
||||
{
|
||||
HandleContinuousAction();
|
||||
}
|
||||
}
|
||||
|
||||
// --- 이동 관련 로직 (기존 유지) ---
|
||||
@@ -210,6 +228,7 @@ public class PlayerNetworkController : NetworkBehaviour
|
||||
else
|
||||
{
|
||||
Debug.Log("조준된 블록이 없음 (하이라이트 확인 필요)");
|
||||
_actionHandler.PerformAction(selectedItem.toolAction, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -465,6 +484,35 @@ public class PlayerNetworkController : NetworkBehaviour
|
||||
return closest;
|
||||
}
|
||||
|
||||
private void HandleContinuousAction()
|
||||
{
|
||||
ItemData selectedItem = _inventory.GetSelectedItemData();
|
||||
if (selectedItem == null || !selectedItem.isTool || selectedItem.toolAction == null) return;
|
||||
|
||||
// [핵심] 반복 가능한 액션일 때만 Update에서 재실행
|
||||
if (selectedItem.toolAction.canRepeat)
|
||||
{
|
||||
TryExecuteAction();
|
||||
}
|
||||
}
|
||||
|
||||
private void TryExecuteAction()
|
||||
{
|
||||
if (_actionHandler.IsBusy) return;
|
||||
|
||||
ItemData selectedItem = _inventory.GetSelectedItemData();
|
||||
if (selectedItem != null && selectedItem.isTool && selectedItem.toolAction != null)
|
||||
{
|
||||
// 단발성 액션인데 이미 한 번 실행했다면 스킵
|
||||
if (!selectedItem.toolAction.canRepeat && _hasExecutedOnce) return;
|
||||
|
||||
GameObject target = _lastHighlightedBlock != null ? _lastHighlightedBlock.gameObject : null;
|
||||
_actionHandler.PerformAction(selectedItem.toolAction, target);
|
||||
|
||||
_hasExecutedOnce = true; // 실행 기록 저장
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDrawGizmos()
|
||||
{
|
||||
if (!Application.isPlaying || !IsOwner) return;
|
||||
|
||||
Reference in New Issue
Block a user