레스토랑 플레이어 FSM 추가
This commit is contained in:
parent
51e76f7a47
commit
ebfec6457d
@ -1,6 +1,6 @@
|
||||
namespace DDD
|
||||
{
|
||||
public interface IPlayerState
|
||||
public interface IStateMachine
|
||||
{
|
||||
void Enter();
|
||||
void Update();
|
@ -2,18 +2,18 @@ namespace DDD
|
||||
{
|
||||
public class PlayerStateMachine
|
||||
{
|
||||
private IPlayerState _currentState;
|
||||
private IStateMachine _currentStateMachine;
|
||||
|
||||
public void ChangeState(IPlayerState newState)
|
||||
public void ChangeState(IStateMachine newStateMachine)
|
||||
{
|
||||
_currentState?.Exit();
|
||||
_currentState = newState;
|
||||
_currentState.Enter();
|
||||
_currentStateMachine?.Exit();
|
||||
_currentStateMachine = newStateMachine;
|
||||
_currentStateMachine.Enter();
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
_currentState?.Update();
|
||||
_currentStateMachine?.Update();
|
||||
}
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.Serialization;
|
||||
|
||||
namespace DDD
|
||||
{
|
||||
@ -18,11 +19,14 @@ public class RestaurantPlayer : MonoBehaviour
|
||||
|
||||
private Vector3 _inputDirection;
|
||||
private Vector3 _currentDirection = Vector3.back;
|
||||
|
||||
public bool IsMoving;
|
||||
public bool IsDashing;
|
||||
public bool IsDashCoolDownActive;
|
||||
|
||||
private bool _isMoving;
|
||||
private bool _isDashing;
|
||||
private bool _isDashCoolDownActive;
|
||||
private float _finalSpeed;
|
||||
|
||||
private PlayerStateMachine _stateMachine;
|
||||
|
||||
#endregion
|
||||
|
||||
@ -44,11 +48,16 @@ private void Start()
|
||||
_moveAction.performed += OnMove;
|
||||
_moveAction.canceled += OnMove;
|
||||
_dashAction.performed += OnDash;
|
||||
|
||||
_stateMachine = new PlayerStateMachine();
|
||||
ChangeState(new IdleState(this, _playerView));
|
||||
}
|
||||
|
||||
//public CellManager cellManager;
|
||||
private void Update()
|
||||
{
|
||||
_stateMachine.Update();
|
||||
|
||||
FlipVisualLook();
|
||||
|
||||
//UpdateCell
|
||||
@ -101,13 +110,13 @@ public void OnMove(InputAction.CallbackContext context)
|
||||
|
||||
public bool CanMove()
|
||||
{
|
||||
return _playerData.IsMoveEnabled && !_isDashing;
|
||||
return _playerData.IsMoveEnabled && !IsDashing;
|
||||
}
|
||||
|
||||
public void Move()
|
||||
{
|
||||
SetCurrentDirection(_inputDirection);
|
||||
_isMoving = _inputDirection != Vector3.zero;
|
||||
IsMoving = _inputDirection != Vector3.zero;
|
||||
|
||||
var finalVelocity = _inputDirection * _playerData.MoveSpeed;
|
||||
_playerView.SetVelocity(finalVelocity);
|
||||
@ -122,7 +131,7 @@ public void OnDash(InputAction.CallbackContext context)
|
||||
|
||||
public bool CanDash()
|
||||
{
|
||||
return _playerData.IsDashEnabled && !_isDashing && !_isDashCoolDownActive;
|
||||
return _playerData.IsDashEnabled && !IsDashing && !IsDashCoolDownActive;
|
||||
}
|
||||
|
||||
public void Dash()
|
||||
@ -132,8 +141,8 @@ public void Dash()
|
||||
|
||||
private IEnumerator DashCoroutine()
|
||||
{
|
||||
_isDashing = true;
|
||||
_isDashCoolDownActive = true;
|
||||
IsDashing = true;
|
||||
IsDashCoolDownActive = true;
|
||||
_playerView.PlayDashParticle();
|
||||
|
||||
AudioManager.Instance.PlaySfx(_playerData.DashSfxName);
|
||||
@ -161,7 +170,7 @@ public void EndDash(float dashCooldown = float.PositiveInfinity)
|
||||
{
|
||||
Utils.EndUniqueCoroutine(this, ref _dashInstance);
|
||||
_playerView.SetVelocity(Vector3.zero);
|
||||
_isDashing = false;
|
||||
IsDashing = false;
|
||||
|
||||
if (float.IsPositiveInfinity(dashCooldown))
|
||||
{
|
||||
@ -169,7 +178,12 @@ public void EndDash(float dashCooldown = float.PositiveInfinity)
|
||||
}
|
||||
|
||||
// TODO : ui 연동
|
||||
StartCoroutine(Utils.CoolDownCoroutine(dashCooldown, () => _isDashCoolDownActive = false));
|
||||
StartCoroutine(Utils.CoolDownCoroutine(dashCooldown, () => IsDashCoolDownActive = false));
|
||||
}
|
||||
|
||||
public void ChangeState(IStateMachine stateMachine)
|
||||
{
|
||||
_stateMachine.ChangeState(stateMachine);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@ -1,7 +1,25 @@
|
||||
using Spine;
|
||||
using UnityEngine;
|
||||
|
||||
namespace DDD
|
||||
{
|
||||
public static class RestaurantSpineAnimation
|
||||
{
|
||||
public const string Idle = "Idle";
|
||||
public const string Walking = "RunFast";
|
||||
public const string ServingIdle = "Serving/ServingIdle";
|
||||
public const string Serving = "Serving/ServingFast";
|
||||
public const string Dash = "Dash";
|
||||
public const string CleaningFloor = "Cleaning/CleaningFloor";
|
||||
public const string CleaningTable = "Cleaning/CleaningTable";
|
||||
public const string MakingCocktail = "BeerMaker";
|
||||
public const string Pumping = "Attack/AttackWhip";
|
||||
public const string AttackSlime = "Attack/AttackSlime";
|
||||
public const string AttackLimeTree = "Attack/AttackBat";
|
||||
public const string CookingFried = "Cooking/CookingFried";
|
||||
public const string CookingStew = "Cooking/CookingStew";
|
||||
}
|
||||
|
||||
public class RestaurantPlayerView : MonoBehaviour
|
||||
{
|
||||
private Rigidbody _rigidbody;
|
||||
@ -26,5 +44,12 @@ public void PlayDashParticle()
|
||||
_dashParticle.Play();
|
||||
}
|
||||
}
|
||||
|
||||
public TrackEntry PlayAnimation(string animationName, bool isLoopActive, float speed = 1f, bool isReverse = false, int trackIndex = 0)
|
||||
=> _spineController.PlayAnimation(animationName, isLoopActive, speed, isReverse, trackIndex);
|
||||
public TrackEntry PlayAnimationDuration(string animationName, bool isLoopActive, float duration, bool isReverse = false, int trackIndex = 0) =>
|
||||
_spineController.PlayAnimationDuration(animationName, isLoopActive, duration, isReverse, trackIndex);
|
||||
public TrackEntry AddAnimation(string animationName, bool isLoopActive, int trackIndex = 0)
|
||||
=> _spineController.AddAnimation(animationName, isLoopActive, trackIndex);
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ef03a607bdc3e914aad8e99ab5c6f91b
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,32 @@
|
||||
namespace DDD
|
||||
{
|
||||
public class IdleState : IStateMachine
|
||||
{
|
||||
private RestaurantPlayer _player;
|
||||
private RestaurantPlayerView _view;
|
||||
|
||||
public IdleState(RestaurantPlayer player, RestaurantPlayerView view)
|
||||
{
|
||||
_player = player;
|
||||
_view = view;
|
||||
}
|
||||
|
||||
public void Enter()
|
||||
{
|
||||
_view.PlayAnimation(RestaurantSpineAnimation.Idle, true);
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
if (_player.IsMoving)
|
||||
{
|
||||
_player.ChangeState(new WalkingState(_player, _view));
|
||||
}
|
||||
}
|
||||
|
||||
public void Exit()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8dd7a1f24d102af41848ae82fb8f8ca5
|
@ -0,0 +1,32 @@
|
||||
namespace DDD
|
||||
{
|
||||
public class WalkingState : IStateMachine
|
||||
{
|
||||
private RestaurantPlayer _player;
|
||||
private RestaurantPlayerView _view;
|
||||
|
||||
public WalkingState(RestaurantPlayer player, RestaurantPlayerView view)
|
||||
{
|
||||
_player = player;
|
||||
_view = view;
|
||||
}
|
||||
|
||||
public void Enter()
|
||||
{
|
||||
_view.PlayAnimation(RestaurantSpineAnimation.Walking, true);
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
if (!_player.IsMoving)
|
||||
{
|
||||
_player.ChangeState(new IdleState(_player, _view));
|
||||
}
|
||||
}
|
||||
|
||||
public void Exit()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 08926e2ade87cab459e625851316b00c
|
Loading…
Reference in New Issue
Block a user