class EnemyController : MonoBehaviour
{
IState PatrolState;
IState AttackState;
StateMachine FSM;
void Awake()
{
//The state has an Action delegate as an argument called Enter, Execute, Exit in order
PatrolState = new State(StartWalkingAnim, Patrol, StopWalkingAnim);
//an overloaded one with only execute as an argument
AttackState = new State(Attack);
FSM = new StateMachine();
FSM.SetCurrentState(AttackState);
}
void Update()
{
FSM.Update();
}
private void StopWalkingAnim()
{
//stop walking animation
}
private void StartWalkingAnim()
{
//stop walking animation
}
private void Patrol()
{
//if (player.Onsight)
// FSM.ChangeState(Attack)
//movement.Patrol();
}
private void Attack()
{
//if (!player.Onsight)
// FSM.ChangeState(Idle)
//AttackController.Attack();
}
}
The benefit I could see here is all the functions has a direct access to member variables so no passing of reference is necessary. and also no need for seperate class for each state. this is inspired by the command pattern in WPF and Xaml databinding
what do you guys think? do you think this will scale? if not whats the way to make this better? or something is fundamentally wrong here?