50 lines
1.4 KiB
C#
50 lines
1.4 KiB
C#
![]() |
using System.Collections;
|
||
|
using Unity.VisualScripting;
|
||
|
using UnityEngine;
|
||
|
|
||
|
// ReSharper disable once CheckNamespace
|
||
|
namespace BlueWaterProject
|
||
|
{
|
||
|
public class NpcStateMachine : MonoBehaviour
|
||
|
{
|
||
|
public INpcState CurrentState { get; private set; }
|
||
|
public NpcStateContext Context { get; private set; } = new NpcStateContext();
|
||
|
|
||
|
public void ChangeState(INpcState newState)
|
||
|
{
|
||
|
CurrentState?.OnExit(this);
|
||
|
CurrentState = newState;
|
||
|
CurrentState.OnEnter(this);
|
||
|
}
|
||
|
|
||
|
public void Update()
|
||
|
{
|
||
|
CurrentState?.OnUpdate(this);
|
||
|
}
|
||
|
|
||
|
public void StartWaitCoroutine(float waitTime, UsuallyPointState state)
|
||
|
{
|
||
|
StartCoroutine(WaitCoroutine(waitTime, state));
|
||
|
}
|
||
|
|
||
|
private IEnumerator WaitCoroutine(float waitTime, UsuallyPointState state)
|
||
|
{
|
||
|
yield return new WaitForSeconds(waitTime);
|
||
|
state.EndWait();
|
||
|
}
|
||
|
|
||
|
// 이 메소드는 플레이어의 명령을 처리합니다.
|
||
|
public void HandlePlayerCommand(/* 명령 파라미터 */)
|
||
|
{
|
||
|
// 이전 상태와 목적지를 저장
|
||
|
Context.PreviousState = CurrentState;
|
||
|
// Context.PreviousDestination = 현재 AI의 목적지;
|
||
|
|
||
|
// 명령 처리 로직
|
||
|
// ...
|
||
|
|
||
|
// 명령 처리 후 원래 상태로 복귀하는 로직
|
||
|
// ...
|
||
|
}
|
||
|
}
|
||
|
}
|