diff --git a/Assets/JAY/Animation/CustomAttack01.anim b/Assets/JAY/Animation/CustomAttack01.anim index 87ed2397..cdb44bb5 100644 --- a/Assets/JAY/Animation/CustomAttack01.anim +++ b/Assets/JAY/Animation/CustomAttack01.anim @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:51c6f4c4d0aa53532545f61a997fbe42e2de2395443bbc0437546b93cb259037 -size 68742 +oid sha256:a78c0ae5bd17e84ad7484d6345f51126e0123d5d46864b537e9c5cc0e958ac48 +size 68398 diff --git a/Assets/JAY/Animation/CustomAttack02.anim b/Assets/JAY/Animation/CustomAttack02.anim index db82e99a..32d86cfd 100644 --- a/Assets/JAY/Animation/CustomAttack02.anim +++ b/Assets/JAY/Animation/CustomAttack02.anim @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:6840d07e637f812131e19cdb5d3f853f96ce3a07cf94d648b4ccc7335ff31522 -size 64417 +oid sha256:56d4a41618cb3e9820775285a048b7fad66ad497b569e8846a2133d5eb971f9c +size 64073 diff --git a/Assets/JAY/Scripts/AnimatorEventRelay.cs b/Assets/JAY/Scripts/AnimatorEventRelay.cs index 8b2ffee9..005347e4 100644 --- a/Assets/JAY/Scripts/AnimatorEventRelay.cs +++ b/Assets/JAY/Scripts/AnimatorEventRelay.cs @@ -8,16 +8,6 @@ public class AnimatorEventRelay : MonoBehaviour { _playerController = GetComponentInParent(); } - - public void SetAttackComboTrue() - { - _playerController?.SetAttackComboTrue(); - } - - public void SetAttackComboFalse() - { - _playerController?.SetAttackComboFalse(); - } public void PlayAttackEffect() { diff --git a/Assets/JAY/Scripts/PlayerAction/PlayerActionAttack.cs b/Assets/JAY/Scripts/PlayerAction/PlayerActionAttack.cs index bd6a6662..9256970b 100644 --- a/Assets/JAY/Scripts/PlayerAction/PlayerActionAttack.cs +++ b/Assets/JAY/Scripts/PlayerAction/PlayerActionAttack.cs @@ -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(); - if (weapon != null) - { - weapon.SetComboStep(step); + weapon?.SetComboStep(step); + } + + public void OnComboInput() { + if (canReceiveCombo) { + comboQueued = true; } } -} \ No newline at end of file +} diff --git a/Assets/JAY/Scripts/PlayerController.cs b/Assets/JAY/Scripts/PlayerController.cs index 153d20b3..2ca2f45b 100644 --- a/Assets/JAY/Scripts/PlayerController.cs +++ b/Assets/JAY/Scripts/PlayerController.cs @@ -291,27 +291,7 @@ public class PlayerController : CharacterBase, IObserver // 무기도 전투모드에만 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 GameManager.Instance.PlayPlayerAttackSound(); StartAttackAction(); } + else if (_currentAction is PlayerActionAttack attackAction) + { + attackAction.OnComboInput(); + } } #endregion