I love both FSM and state pattern and the videos explain them pretty well (once you get your head around them) and I can see pro’s and con’s of each.
What would be good @sampattuzzi is to show how the best way to initiate an action during transition for both the FSM and the State Machine for completeness.
I think it’s fairly clear for the FSM where you put the code as you pop it in the Switch statement for each case and the video refers to it.
However I have implemented the State Machine that works well but can’t fathom the best way to take an action based on a transition for this model.
e.g. If we were writing the state for a simple car Reverse, Forward and Brake
if (driveAmount < 0) { steerAmount = -steerAmount; Reverse(); } else if (driveAmount > 0) { Forward(); } else { Brake(); }
and then we want to do something on the based on the state when it reverses
public class DriveReverse : BinLorryState
{public void Forward(BinLorryContext context) { context.SetState(new DriveForward()); } public void Reverse(BinLorryContext context) { Debug.Log("Still Reversing"); } public void Brake(BinLorryContext context) { context.SetState(new Stop()); }
}