Last active
February 7, 2020 04:21
-
-
Save Streamweaver/187b913ed6a90f2a2bdde32579ef29b8 to your computer and use it in GitHub Desktop.
An Action State Machine Pattern I like in Unity.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Got this from Jason Weimann's videos. I like the pattern much better. | |
// from https://unity3d.college/2017/05/26/unity3d-design-patterns-state-basic-state-machine/ | |
public class Entity: Monobehavior | |
{ | |
private ActionState _currentState; | |
private void Update() { | |
_currentState.Tick(); | |
} | |
} | |
// Abstract Class to build real actions from. | |
public abstract class ActionState | |
{ | |
protected Entity entity; | |
public abstract void Tick(); | |
public virtual void OnStateEnter() { } | |
public virtual void OnStateExit() { } | |
public ActionState(Entity entity) | |
{ | |
this.entity = entity; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment