From 0f84310d907a89510a2bdbd782847faabbd9264b Mon Sep 17 00:00:00 2001 From: Jay <96156114+jaydev00a@users.noreply.github.com> Date: Tue, 13 May 2025 11:42:41 +0900 Subject: [PATCH 1/2] =?UTF-8?q?DEG-151=20[FEAT]=20=EA=B3=B5=EA=B2=A9=20?= =?UTF-8?q?=EB=B0=A9=EC=8B=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/JAY/Scripts/AnimatorEventRelay.cs | 10 --- .../PlayerAction/PlayerActionAttack.cs | 83 ++++++++++--------- Assets/JAY/Scripts/PlayerController.cs | 24 +----- 3 files changed, 49 insertions(+), 68 deletions(-) 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 From 0b2b8045ab1e3bafd6be8865e864df24f7147fa5 Mon Sep 17 00:00:00 2001 From: Jay <96156114+jaydev00a@users.noreply.github.com> Date: Tue, 13 May 2025 11:44:21 +0900 Subject: [PATCH 2/2] =?UTF-8?q?DEG-151=20[FEAT]=20=EB=8D=94=EC=9D=B4?= =?UTF-8?q?=EC=83=81=20=EC=82=AC=EC=9A=A9=ED=95=98=EC=A7=80=20=EC=95=8A?= =?UTF-8?q?=EB=8A=94=20=EC=95=A0=EB=8B=88=EB=A9=94=EC=9D=B4=EC=85=98=20?= =?UTF-8?q?=EC=9D=B4=EB=B2=A4=ED=8A=B8=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/JAY/Animation/CustomAttack01.anim | 4 ++-- Assets/JAY/Animation/CustomAttack02.anim | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) 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