2026-04-01 상호작용
This commit is contained in:
@@ -31,7 +31,7 @@ public void InteractClose()
|
||||
|
||||
public void InteractExec(PlayerCharacterController player)
|
||||
{
|
||||
player.transform.position = gameObject.transform.position;
|
||||
player.transform.rotation = gameObject.transform.rotation;
|
||||
player.PointSitAction(this.transform);
|
||||
GameManager.Instance.InGameUI.InteractionVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,11 @@ public void VisibleCrossHair(bool isOn)
|
||||
_crosshairRoot.SetActive(isOn);
|
||||
}
|
||||
|
||||
public void InteractionVisible(bool isOn)
|
||||
{
|
||||
Interaction.gameObject.SetActive(isOn);
|
||||
}
|
||||
|
||||
public SplitWindowUI GetSplitWindowUI()
|
||||
{
|
||||
return SplitWindow;
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
// 상호작용 객체인지 확인
|
||||
|
||||
@@ -1 +1 @@
|
||||
public enum PlayerState { Idle, Walk, Run, Dodge, Jump, Fall, Attack, Charge, Hit, Dead, Inertia, None }
|
||||
public enum PlayerState { Idle, Walk, Run, Dodge, Jump, Fall, Attack, Charge, Hit, Dead, Inertia, Action, Trans, None }
|
||||
@@ -57,13 +57,13 @@ public void SetMaxJumpCount(int maxCount)
|
||||
|
||||
#region 상태확인용 헬퍼함수들
|
||||
//지상 이동이 가능한가?
|
||||
public bool CanMove() => IsGrounded && !IsMoveCut && (CurrentState == PlayerState.Idle || CurrentState == PlayerState.Walk || CurrentState == PlayerState.Run) && (CurrentState != PlayerState.Inertia);
|
||||
public bool CanMove() => IsGrounded && !IsMoveCut && (CurrentState == PlayerState.Idle || CurrentState == PlayerState.Walk || CurrentState == PlayerState.Run) && (CurrentState != PlayerState.Inertia && CurrentState != PlayerState.Action && CurrentState != PlayerState.Trans);
|
||||
//점프가 가능한 상태인가?
|
||||
public bool CanJump()
|
||||
{
|
||||
bool jumpAlreadyMax = (_maxJumpCount <= _jumpCount);
|
||||
|
||||
return IsGrounded && !IsMoveCut && !jumpAlreadyMax && (CurrentState == PlayerState.Idle || CurrentState == PlayerState.Walk || CurrentState == PlayerState.Run) && (CurrentState != PlayerState.Inertia);
|
||||
return IsGrounded && !IsMoveCut && !jumpAlreadyMax && (CurrentState == PlayerState.Idle || CurrentState == PlayerState.Walk || CurrentState == PlayerState.Run) && (CurrentState != PlayerState.Inertia && CurrentState != PlayerState.Action && CurrentState != PlayerState.Trans);
|
||||
}
|
||||
//대쉬가 가능한 상태인가?
|
||||
public bool CanDodge()
|
||||
@@ -79,6 +79,8 @@ public bool CanDodge()
|
||||
|
||||
if (IsMoveCut) return false;
|
||||
if (CurrentState == PlayerState.Inertia) return false;
|
||||
if (CurrentState == PlayerState.Action) return false;
|
||||
if (CurrentState == PlayerState.Trans) return false;
|
||||
|
||||
// 스태미나 시스템이 있다면 체크
|
||||
// if (CurrentStamina < DodgeCost) return false;
|
||||
@@ -86,7 +88,7 @@ public bool CanDodge()
|
||||
return true;
|
||||
}
|
||||
//공중에서 조작 가능한 상태인가?
|
||||
public bool CanControlInAir() => !IsGrounded && !IsMoveCut && (CurrentState == PlayerState.Jump || CurrentState == PlayerState.Fall) && (CurrentState != PlayerState.Inertia);
|
||||
public bool CanControlInAir() => !IsGrounded && !IsMoveCut && (CurrentState == PlayerState.Jump || CurrentState == PlayerState.Fall) && (CurrentState != PlayerState.Inertia && CurrentState != PlayerState.Action && CurrentState != PlayerState.Trans);
|
||||
//공격이 가능한 상태인가?
|
||||
public bool CanAttack()
|
||||
{
|
||||
@@ -101,6 +103,9 @@ public bool CanAttack()
|
||||
if (CurrentState == PlayerState.Dodge || CurrentState == PlayerState.Inertia)
|
||||
return false;
|
||||
|
||||
if (CurrentState == PlayerState.Action || CurrentState == PlayerState.Trans)
|
||||
return false;
|
||||
|
||||
// (Idle, Walk, Run, Jump, Fall 상태에서 공격 가능)
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user