2026-04-01 상호작용
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading;
|
||||
using Unity.Cinemachine;
|
||||
using Unity.VisualScripting;
|
||||
@@ -79,6 +80,7 @@ public enum PlayerRotationMode {CameraCoupled, CameraDecoupled}
|
||||
//상호작용
|
||||
public SphereCollider InteractionCollider;
|
||||
public List<IInteractable> InteractionTargets = new List<IInteractable>();
|
||||
private bool _actionExitRequested = false;
|
||||
|
||||
//무기
|
||||
//[SerializeField] private Weapon _weapon;
|
||||
@@ -150,6 +152,18 @@ private void PlayerDebug()
|
||||
#region 상태 업데이트
|
||||
private void StateUpdate()
|
||||
{
|
||||
if (_stateMachine.CurrentState == PlayerState.Trans) return;
|
||||
if (_stateMachine.CurrentState == PlayerState.Action)
|
||||
{
|
||||
// Action 중 탈출 입력 감지
|
||||
if (_moveInput.sqrMagnitude > Mathf.Epsilon || _actionExitRequested)
|
||||
{
|
||||
EndAction();
|
||||
_actionExitRequested = false;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (_stateMachine.CurrentState == PlayerState.Inertia && _inertiaTimer > 0f)
|
||||
return; // 관성상태면 상태변환 안함
|
||||
else if(_stateMachine.CurrentState == PlayerState.Inertia && _inertiaTimer <= 0f)
|
||||
@@ -241,7 +255,8 @@ private void WorkGravity()
|
||||
#region 이동
|
||||
private void Movement()
|
||||
{
|
||||
|
||||
if (_stateMachine.CurrentState == PlayerState.Action) return;
|
||||
if (_stateMachine.CurrentState == PlayerState.Trans) return;
|
||||
if (_stateMachine.CurrentState == PlayerState.Inertia) return;
|
||||
|
||||
//구르기중일때 전용 로직
|
||||
@@ -378,6 +393,12 @@ private void OnAnimatorMove()
|
||||
{
|
||||
_rootMotionVelocity = _anim.deltaPosition / Time.deltaTime;
|
||||
}
|
||||
|
||||
if (_stateMachine.CurrentState == PlayerState.Action || _stateMachine.CurrentState == PlayerState.Trans)
|
||||
{
|
||||
_cController.Move(_anim.deltaPosition);
|
||||
transform.rotation *= _anim.deltaRotation;
|
||||
}
|
||||
}
|
||||
private void ApplyMove()
|
||||
{
|
||||
@@ -403,10 +424,38 @@ private void JumpAction()
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region
|
||||
private void PointSitAction()
|
||||
#region 앉기
|
||||
public void PointSitAction(Transform trn)
|
||||
{
|
||||
_cController.enabled = false;
|
||||
|
||||
_stateMachine.ChangeState(PlayerState.Action);
|
||||
|
||||
transform.position = trn.position;
|
||||
transform.rotation = trn.rotation;
|
||||
|
||||
_cController.enabled = true;
|
||||
|
||||
_anim.SetBool("IsSit",true);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 액션 종료
|
||||
public void EndAction()
|
||||
{
|
||||
if (_stateMachine.CurrentState != PlayerState.Action) return;
|
||||
|
||||
_anim.SetBool("IsSit", false);
|
||||
float FreezeTime = 2f;
|
||||
|
||||
_stateMachine.ChangeState(PlayerState.Trans);
|
||||
|
||||
_moveCutTimer = FreezeTime;
|
||||
_ = Util.RunDelayed(FreezeTime, () => {
|
||||
_stateMachine.ChangeState(PlayerState.Idle);
|
||||
RotationMode = PlayerRotationMode.CameraCoupled;
|
||||
GameManager.Instance.InGameUI.InteractionVisible(true);
|
||||
}, default);
|
||||
}
|
||||
#endregion
|
||||
|
||||
@@ -438,6 +487,7 @@ public void SprintInput(InputState inputState)
|
||||
}
|
||||
public void JumpInput(InputState inputState)
|
||||
{
|
||||
if (ActionExitCheck()) return;
|
||||
if (_stateMachine.CanJump())
|
||||
{
|
||||
if (inputState == InputState.Started)
|
||||
@@ -533,10 +583,14 @@ public void AimToggleInput(InputState inputState)
|
||||
|
||||
public void InteractInput()
|
||||
{
|
||||
if (ActionExitCheck()) return;
|
||||
|
||||
if (InteractionTargets.Count > 0)
|
||||
{
|
||||
IInteractable target = InteractionTargets[0];
|
||||
target.InteractExec(this); // 실제 상호작용 실행
|
||||
|
||||
RotationMode = PlayerRotationMode.CameraDecoupled;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -587,6 +641,14 @@ public void SetCursorLockState(bool isLocked)
|
||||
}
|
||||
#endregion
|
||||
|
||||
private bool ActionExitCheck()
|
||||
{
|
||||
if (_stateMachine.CurrentState == PlayerState.Action)
|
||||
_actionExitRequested = true;
|
||||
|
||||
return _actionExitRequested;
|
||||
}
|
||||
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
// 상호작용 객체인지 확인
|
||||
|
||||
Reference in New Issue
Block a user