From b378d51f736b2b0fcf4e9da25d6b2f6f01227831 Mon Sep 17 00:00:00 2001 From: Jay <96156114+jaydev00a@users.noreply.github.com> Date: Thu, 24 Apr 2025 14:27:46 +0900 Subject: [PATCH] =?UTF-8?q?DEG-94=20[FEAT]=20=ED=9A=8C=ED=94=BC=20?= =?UTF-8?q?=ED=96=89=EB=8F=99=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/JAY/Animation/Attack04.anim | 4 +- .../Scripts/IPlayerAction/PlayerActionDash.cs | 53 ++++++++++ .../IPlayerAction/PlayerActionDash.cs.meta | 3 + Assets/JAY/Scripts/PlayerController.cs | 100 ++++++++++++++---- Assets/JAY/Scripts/PlayerControllerEditor.cs | 1 + .../Scripts/PlayerState/PlayerStateIdle.cs | 4 +- .../Scripts/PlayerState/PlayerStateMove.cs | 8 +- 7 files changed, 142 insertions(+), 31 deletions(-) create mode 100644 Assets/JAY/Scripts/IPlayerAction/PlayerActionDash.cs create mode 100644 Assets/JAY/Scripts/IPlayerAction/PlayerActionDash.cs.meta diff --git a/Assets/JAY/Animation/Attack04.anim b/Assets/JAY/Animation/Attack04.anim index 0dd4649a..4c55f7c4 100644 --- a/Assets/JAY/Animation/Attack04.anim +++ b/Assets/JAY/Animation/Attack04.anim @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:b7cd9ef4b089d4cb8c37104f3c8394664b89cb584cf7b9cb976a1f1843ebb4b2 -size 915194 +oid sha256:5d83b7ac61c2e7be0c4df6529e2a716d552181ebf981da79c54f2ccc8b4df009 +size 915187 diff --git a/Assets/JAY/Scripts/IPlayerAction/PlayerActionDash.cs b/Assets/JAY/Scripts/IPlayerAction/PlayerActionDash.cs new file mode 100644 index 00000000..0b7904e2 --- /dev/null +++ b/Assets/JAY/Scripts/IPlayerAction/PlayerActionDash.cs @@ -0,0 +1,53 @@ +using UnityEngine; + +public class PlayerActionDash : IPlayerAction +{ + private PlayerController player; + private float duration = 0.25f; + private float timer; + private Vector3 direction; + + private float dashSpeedMultiplier = 3f; // 기본 이동 속도의 n배 + private float dashSpeed; + + public bool IsActive { get; private set; } + + public void StartAction(PlayerController player) + { + this.player = player; + IsActive = true; + timer = 0f; + + direction = player.GetMoveDirectionOrForward().normalized; + + dashSpeed = player.moveSpeed * dashSpeedMultiplier; + + // player.PlayerAnimator.SetTrigger("Roll"); + } + + public void UpdateAction() + { + if (!IsActive) return; + + DoDash(); + } + + private void DoDash() + { + timer += Time.deltaTime; + if (timer < duration) + { + player.CharacterController.Move(direction * dashSpeed * Time.deltaTime); + } + else + { + EndAction(); + } + } + + public void EndAction() + { + IsActive = false; + player = null; + } +} diff --git a/Assets/JAY/Scripts/IPlayerAction/PlayerActionDash.cs.meta b/Assets/JAY/Scripts/IPlayerAction/PlayerActionDash.cs.meta new file mode 100644 index 00000000..fd30de5b --- /dev/null +++ b/Assets/JAY/Scripts/IPlayerAction/PlayerActionDash.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: eceb0c738c2c4690b8b4dd02e10c7df4 +timeCreated: 1745459840 \ No newline at end of file diff --git a/Assets/JAY/Scripts/PlayerController.cs b/Assets/JAY/Scripts/PlayerController.cs index 33d0f019..f1ea7b80 100644 --- a/Assets/JAY/Scripts/PlayerController.cs +++ b/Assets/JAY/Scripts/PlayerController.cs @@ -17,18 +17,20 @@ public class PlayerController : CharacterBase, IObserver private GameObject weapon; private WeaponController _weaponController; - private IPlayerState CurrentStateClass { get; set; } - private IPlayerAction currentAction; + private IPlayerState _currentStateClass { get; set; } + private IPlayerAction _currentAction; + public IPlayerAction CurrentAction => _currentAction; // 상태 관련 private PlayerStateIdle _playerStateIdle; private PlayerStateMove _playerStateMove; // 행동 관련 - private PlayerActionAttack attackAction; + private PlayerActionAttack _attackAction; + private PlayerActionDash _actionDash; // 외부에서도 사용하는 변수 - public FixedJoystick joystick { get; private set; } + public FixedJoystick Joystick { get; private set; } public PlayerState CurrentState { get; private set; } private Dictionary _playerStates; public Animator PlayerAnimator { get; private set; } @@ -38,9 +40,9 @@ public class PlayerController : CharacterBase, IObserver { PlayerAnimator = GetComponent(); _characterController = GetComponent(); - if (joystick == null) + if (Joystick == null) { - joystick = FindObjectOfType(); + Joystick = FindObjectOfType(); } } @@ -58,7 +60,8 @@ public class PlayerController : CharacterBase, IObserver { PlayerState.Move, _playerStateMove }, }; - attackAction = new PlayerActionAttack(); + _attackAction = new PlayerActionAttack(); + _actionDash = new PlayerActionDash(); PlayerInit(); } @@ -70,20 +73,23 @@ public class PlayerController : CharacterBase, IObserver _playerStates[CurrentState].Update(); } - // 현재 액션이 활성화 되어 있으면 Update 호출 - if (currentAction != null && currentAction.IsActive) { - currentAction.UpdateAction(); + // 대시 우선 입력 처리 + if (Input.GetKeyDown(KeyCode.Space)) + { + StartDashAction(); + return; } // 공격 입력 처리 - if (Input.GetKeyDown(KeyCode.X) && (currentAction == null || !currentAction.IsActive)) { + if (Input.GetKeyDown(KeyCode.X) && (_currentAction == null || !_currentAction.IsActive)) { StartAttackAction(); } - } - - public void StartAttackAction() { - currentAction = attackAction; - currentAction.StartAction(this); + + // 액션 업데이트 + if (_currentAction != null && _currentAction.IsActive) + { + _currentAction.UpdateAction(); + } } #region 초기화 관련 @@ -108,7 +114,9 @@ public class PlayerController : CharacterBase, IObserver } #endregion - + + #region 상태, 동작 변화 관련 + public void SetState(PlayerState state) { if (CurrentState != PlayerState.None) @@ -116,10 +124,36 @@ public class PlayerController : CharacterBase, IObserver _playerStates[CurrentState].Exit(); } CurrentState = state; - CurrentStateClass = _playerStates[state]; - CurrentStateClass.Enter(this); + _currentStateClass = _playerStates[state]; + _currentStateClass.Enter(this); } + + public void StartAttackAction() { + _currentAction = _attackAction; + _currentAction.StartAction(this); + } + + public void StartDashAction() + { + // 만약 공격 중이면 강제로 공격 종료 + if (_currentAction == _attackAction && _attackAction.IsActive) + { + _attackAction.EndAction(); // 애니메이션도 중단 + } + + // 기존 대시 중이면 중복 실행 안 함 + if (_actionDash.IsActive) + return; + + _currentAction = _actionDash; + _actionDash.StartAction(this); + } + + #endregion + + #region 공격 관련 + public void SwitchBattleMode() { _isBattle = !_isBattle; @@ -130,19 +164,39 @@ public class PlayerController : CharacterBase, IObserver public void SetAttackComboTrue() { if (_weaponController.IsAttacking) return; // 이미 공격 중이면 실행 안함 - if (currentAction == attackAction) { - attackAction.EnableCombo(); + if (_currentAction == _attackAction) { + _attackAction.EnableCombo(); _weaponController.AttackStart(); } } public void SetAttackComboFalse() { - if (currentAction == attackAction) { - attackAction.DisableCombo(); + if (_currentAction == _attackAction) { + _attackAction.DisableCombo(); _weaponController.AttackEnd(); } } + #endregion + + #region 대시 관련 + + public Vector3 GetMoveDirectionOrForward() + { + Vector3 dir = new Vector3(Joystick.Horizontal, 0, Joystick.Vertical); + return dir.sqrMagnitude > 0.01f ? dir.normalized : transform.forward; + } + + public void DashButtonPressed() + { + if (!_actionDash.IsActive) + { + StartDashAction(); + } + } + + #endregion + #region IObserver 관련 public void OnNext(GameObject value) diff --git a/Assets/JAY/Scripts/PlayerControllerEditor.cs b/Assets/JAY/Scripts/PlayerControllerEditor.cs index 0c7a78db..2ddbbbe0 100644 --- a/Assets/JAY/Scripts/PlayerControllerEditor.cs +++ b/Assets/JAY/Scripts/PlayerControllerEditor.cs @@ -22,6 +22,7 @@ public class PlayerControllerEditor : Editor EditorGUILayout.BeginVertical(EditorStyles.helpBox); EditorGUILayout.LabelField("현재 상태", playerController.CurrentState.ToString(), EditorStyles.boldLabel); + EditorGUILayout.LabelField("현재 행동", playerController.CurrentAction != null ? playerController.CurrentAction.ToString() : "-", EditorStyles.boldLabel); EditorGUILayout.EndVertical(); diff --git a/Assets/JAY/Scripts/PlayerState/PlayerStateIdle.cs b/Assets/JAY/Scripts/PlayerState/PlayerStateIdle.cs index 733053ba..ed8ff3d3 100644 --- a/Assets/JAY/Scripts/PlayerState/PlayerStateIdle.cs +++ b/Assets/JAY/Scripts/PlayerState/PlayerStateIdle.cs @@ -11,8 +11,8 @@ public class PlayerStateIdle : IPlayerState public void Update() { - float inputHorizontal = _playerController.joystick.Horizontal; - float inputVertical = _playerController.joystick.Vertical; + float inputHorizontal = _playerController.Joystick.Horizontal; + float inputVertical = _playerController.Joystick.Vertical; // 이동 if (inputHorizontal != 0 || inputVertical != 0) diff --git a/Assets/JAY/Scripts/PlayerState/PlayerStateMove.cs b/Assets/JAY/Scripts/PlayerState/PlayerStateMove.cs index 97a6e84e..19f5bd7a 100644 --- a/Assets/JAY/Scripts/PlayerState/PlayerStateMove.cs +++ b/Assets/JAY/Scripts/PlayerState/PlayerStateMove.cs @@ -14,8 +14,8 @@ public class PlayerStateMove : IPlayerState public void Update() { - float inputHorizontal = _playerController.joystick.Horizontal; - float inputVertical = _playerController.joystick.Vertical; + float inputHorizontal = _playerController.Joystick.Horizontal; + float inputVertical = _playerController.Joystick.Vertical; // 이동 if (inputHorizontal != 0 || inputVertical != 0) @@ -36,8 +36,8 @@ public class PlayerStateMove : IPlayerState private void HandleMovement() { - float inputHorizontal = _playerController.joystick.Horizontal; - float inputVertical = _playerController.joystick.Vertical; + float inputHorizontal = _playerController.Joystick.Horizontal; + float inputVertical = _playerController.Joystick.Vertical; Vector3 moveDir = new Vector3(inputHorizontal, 0, inputVertical); Vector3 move = moveDir.normalized * _playerController.moveSpeed;