Базовая инфраструктура
This commit is contained in:
1 parent
2e0dc15beb
commit
b5e28c7abb
117 files changed
+2068
-2031
No files matched your search
@@ -0,0 +1,33 @@
|
||||
using Code.App.AppStates;
|
||||
using Code.StateMachine;
|
||||
|
||||
namespace Code.App.StateMachine
|
||||
{
|
||||
public class AppStateMachine : AbstractStateMachine<AppState, AppStateMachineContext>
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
States.Add(AppState.MainMenu, new MainMenuState(StateMachineContext));
|
||||
States.Add(AppState.Gameplay, new GameplayState(StateMachineContext));
|
||||
States.Add(AppState.GameOver, new GameOverState(StateMachineContext));
|
||||
|
||||
AllowedStates |= AppState.MainMenu;
|
||||
AllowedStates |= AppState.Gameplay;
|
||||
}
|
||||
|
||||
protected override bool CheckTransitionAllowed(AppState nextState) => AllowedStates.HasFlag(nextState);
|
||||
protected override void ResetAllowedTransitions() => AllowedStates = 0;
|
||||
}
|
||||
|
||||
public static class AppStateMachineExtensions
|
||||
{
|
||||
public static AbstractStateMachine<AppState, AppStateMachineContext> AllowStateTransition(
|
||||
this AbstractStateMachine<AppState, AppStateMachineContext> appStateMachine, AppState state)
|
||||
{
|
||||
if (appStateMachine == null) return null;
|
||||
|
||||
appStateMachine.AllowedStates |= state;
|
||||
return appStateMachine;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user