FSM 작성중
This commit is contained in:
@@ -1,5 +1,34 @@
|
|||||||
using System;
|
using System;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
|
public class IdleState : IState
|
||||||
|
{
|
||||||
|
public void Enter()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Exit()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public IState CheckTransition()
|
||||||
|
{
|
||||||
|
// 우선 순위
|
||||||
|
// Jump를 우선
|
||||||
|
// Move는 Jump보다 낮은 우선
|
||||||
|
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public class PlayerMove : MonoBehaviour
|
public class PlayerMove : MonoBehaviour
|
||||||
{
|
{
|
||||||
private static readonly int IsJumping = Animator.StringToHash("isJumping");
|
private static readonly int IsJumping = Animator.StringToHash("isJumping");
|
||||||
|
|||||||
50
Assets/Scripts/Player/StateMachine.cs
Normal file
50
Assets/Scripts/Player/StateMachine.cs
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public class StateMachine
|
||||||
|
{
|
||||||
|
private Animator animator;
|
||||||
|
private IState _state;
|
||||||
|
private PlayerMove _playerBase;
|
||||||
|
// private TextMeshProUGUI _textState;
|
||||||
|
|
||||||
|
public StateMachine(IState state, PlayerMove playerMove)
|
||||||
|
{
|
||||||
|
// 초기 상태 객체 생성
|
||||||
|
_playerBase = playerMove;;
|
||||||
|
|
||||||
|
_state = state;
|
||||||
|
_state.Enter();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update()
|
||||||
|
{
|
||||||
|
_state.Update();
|
||||||
|
|
||||||
|
var newState = _state.CheckTransition();
|
||||||
|
|
||||||
|
if (_state != newState)
|
||||||
|
{
|
||||||
|
_state.Exit();
|
||||||
|
SetTransition(newState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetTransition(IState state)
|
||||||
|
{
|
||||||
|
// 다음음 상태로 전환
|
||||||
|
_state = state;
|
||||||
|
_state.Enter();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface IState
|
||||||
|
{
|
||||||
|
void Enter();
|
||||||
|
|
||||||
|
void Update();
|
||||||
|
|
||||||
|
void Exit();
|
||||||
|
|
||||||
|
// 트리거 조건일 경우 다음 상태로 전환
|
||||||
|
IState CheckTransition();
|
||||||
|
}
|
||||||
2
Assets/Scripts/Player/StateMachine.cs.meta
Normal file
2
Assets/Scripts/Player/StateMachine.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: d769a06cc3249454987cac52904ad993
|
||||||
Reference in New Issue
Block a user