Merge pull request 'DEG-151-플레이어-공격-되다가-안되는-이슈-공격속도-강화를-위해-수정-필요' (!43) from DEG-151-플레이어-공격-되다가-안되는-이슈-공격속도-강화를-위해-수정-필요 into main

Reviewed-on: #43
Reviewed-by: Sehyeon <sehyeon1837@gmail.com>
Reviewed-by: 99jamin <rhwk341@naver.com>
This commit is contained in:
jay 2025-05-13 04:13:41 +00:00
commit 940d967b4f
5 changed files with 53 additions and 72 deletions

BIN
Assets/JAY/Animation/CustomAttack01.anim (Stored with Git LFS)

Binary file not shown.

BIN
Assets/JAY/Animation/CustomAttack02.anim (Stored with Git LFS)

Binary file not shown.

View File

@ -8,16 +8,6 @@ public class AnimatorEventRelay : MonoBehaviour
{
_playerController = GetComponentInParent<PlayerController>();
}
public void SetAttackComboTrue()
{
_playerController?.SetAttackComboTrue();
}
public void SetAttackComboFalse()
{
_playerController?.SetAttackComboFalse();
}
public void PlayAttackEffect()
{

View File

@ -2,72 +2,79 @@
public class PlayerActionAttack : IPlayerAction {
private static readonly int ComboStep = Animator.StringToHash("ComboStep");
private PlayerController player;
private int comboStep = 1;
private bool comboQueued = false;
private bool canReceiveCombo = false;
public int CurrentComboStep => comboStep;
private float comboTimer = 0f;
[SerializeField] private float comboDuration = 0.7f;
private int maxComboStep = 4;
public bool IsActive { get; private set; }
public int CurrentComboStep => comboStep;
public void StartAction(PlayerController player) {
this.player = player;
IsActive = true;
comboStep = 1;
comboQueued = false;
PlayComboAnimation(comboStep);
canReceiveCombo = true;
comboTimer = 0f;
player.SafeSetBool("Attack", true);
PlayComboAnimation(comboStep);
}
public void UpdateAction() {
if (Input.GetKeyDown(KeyCode.X) && canReceiveCombo) {
comboTimer += Time.deltaTime;
if (canReceiveCombo && Input.GetKeyDown(KeyCode.X)) {
comboQueued = true;
}
if (comboTimer >= comboDuration) {
ProceedComboOrEnd();
}
}
private void ProceedComboOrEnd() {
canReceiveCombo = false;
if (comboQueued && comboStep < maxComboStep) {
comboStep++;
comboQueued = false;
comboTimer = 0f;
canReceiveCombo = true;
PlayComboAnimation(comboStep);
} else {
EndAction();
}
}
public void EndAction() {
if (player == null) return;
player.SafeSetBool("Attack", false);
IsActive = false;
player.OnActionEnded(this); // player 에서도 action 초기화
player.OnActionEnded(this);
player = null;
}
public void EnableCombo() {
canReceiveCombo = true;
}
private void PlayComboAnimation(int step) {
if (player?.PlayerAnimator == null) return;
public void DisableCombo() {
canReceiveCombo = false;
player.PlayerAnimator.SetInteger(ComboStep, step);
if (comboQueued && comboStep < 4) {
comboStep++;
PlayComboAnimation(comboStep);
comboQueued = false;
} else {
EndAction(); // 행동 종료
}
}
private void PlayComboAnimation(int step)
{
if (player.PlayerAnimator == null) return;
// 안전하게 파라미터 체크
foreach (var param in player.PlayerAnimator.parameters)
{
if (param.nameHash == ComboStep && param.type == AnimatorControllerParameterType.Int)
{
player.PlayerAnimator.SetInteger(ComboStep, step);
break;
}
}
// 무기에 콤보 단계 전달
var weapon = player.GetComponentInChildren<WeaponController>();
if (weapon != null)
{
weapon.SetComboStep(step);
weapon?.SetComboStep(step);
}
public void OnComboInput() {
if (canReceiveCombo) {
comboQueued = true;
}
}
}
}

View File

@ -291,27 +291,7 @@ public class PlayerController : CharacterBase, IObserver<GameObject>
// 무기도 전투모드에만
weapon.SetActive(_isBattle);
}
// Animation Event에서 호출될 메서드
public void SetAttackComboTrue()
{
if (_weaponController.IsAttacking) return; // 이미 공격 중이면 실행 안함
if (_currentAction == _attackAction) {
_attackAction.EnableCombo();
_weaponController.AttackStart();
}
}
public void SetAttackComboFalse()
{
if (_currentAction == _attackAction) {
// 이벤트 중복 호출? 공격 종료 시 SetAttackComboFalse가 아니라 ~True로 끝나서 오류 발생. (공격 안하는 상태여도 공격으로 판정됨)
_attackAction.DisableCombo();
_weaponController.AttackEnd(); // IsAttacking = false로 변경
}
}
public void PlayAttackEffect()
{
if (_attackAction == null) return;
@ -350,6 +330,10 @@ public class PlayerController : CharacterBase, IObserver<GameObject>
GameManager.Instance.PlayPlayerAttackSound();
StartAttackAction();
}
else if (_currentAction is PlayerActionAttack attackAction)
{
attackAction.OnComboInput();
}
}
#endregion