78 lines
1.5 KiB
C#
78 lines
1.5 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace UFS2.Gameplay
|
|
{
|
|
public class FishFSM : MonoBehaviour
|
|
{
|
|
protected StateMachine _FSM;
|
|
|
|
protected FishState _State;
|
|
|
|
protected Dictionary<FishState, IState> _States;
|
|
|
|
protected float _StateChangeTime;
|
|
|
|
protected void InitializeFSM(FishEntity fishEntity)
|
|
{
|
|
_FSM = new StateMachine();
|
|
_States = new Dictionary<FishState, IState>
|
|
{
|
|
{
|
|
FishState.Idle,
|
|
new FishIdleState(fishEntity)
|
|
},
|
|
{
|
|
FishState.MoveToWaypoint,
|
|
new FishMoveState(fishEntity)
|
|
},
|
|
{
|
|
FishState.Atack,
|
|
new FishAttackState(fishEntity)
|
|
},
|
|
{
|
|
FishState.Fight,
|
|
new FishFightState(fishEntity)
|
|
},
|
|
{
|
|
FishState.Interest,
|
|
new FishInterestState(fishEntity)
|
|
},
|
|
{
|
|
FishState.Catched,
|
|
new FishCatchState(fishEntity)
|
|
},
|
|
{
|
|
FishState.BaitEat,
|
|
new FishEatBaitState(fishEntity)
|
|
},
|
|
{
|
|
FishState.MultiplayerIdle,
|
|
new FishMultiplayerIdleState(fishEntity)
|
|
},
|
|
{
|
|
FishState.MultiplayerMoveToWaypoint,
|
|
new FishMultiplayerMoveToWaypointState(fishEntity)
|
|
},
|
|
{
|
|
FishState.MultiplayerHide,
|
|
new FishMultiplayerHideState(fishEntity)
|
|
}
|
|
};
|
|
ChangeState(FishState.Idle);
|
|
}
|
|
|
|
protected void ChangeState(FishState newState)
|
|
{
|
|
_FSM.ChangeState(_States[newState]);
|
|
_State = newState;
|
|
_StateChangeTime = Time.time;
|
|
}
|
|
|
|
protected void OnDestroy()
|
|
{
|
|
_FSM?.Current?.Exit();
|
|
}
|
|
}
|
|
}
|