// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
using System.Collections.Generic;
using FlaxEngine;
using FlaxEngine.Utilities;
namespace FlaxEditor.States
{
///
/// Flax Editor states machine.
///
///
[HideInEditor]
public sealed class EditorStateMachine : StateMachine
{
private readonly Queue _pendingStates = new Queue();
///
/// Gets the current state.
///
public new EditorState CurrentState => currentState as EditorState;
///
/// Checks if editor is in playing mode
///
public bool IsPlayMode => CurrentState == PlayingState;
///
/// Checks if editor is in editing mode
///
public bool IsEditMode => CurrentState == EditingSceneState;
///
/// Editor loading state.
///
public readonly LoadingState LoadingState;
///
/// Editor closing state.
///
public readonly ClosingState ClosingState;
///
/// Editor editing scene state.
///
public readonly EditingSceneState EditingSceneState;
///
/// Editor changing scenes state.
///
public readonly ChangingScenesState ChangingScenesState;
///
/// Editor playing state.
///
public readonly PlayingState PlayingState;
///
/// Editor reloading scripts state.
///
public readonly ReloadingScriptsState ReloadingScriptsState;
///
/// Editor building lighting state.
///
public readonly BuildingLightingState BuildingLightingState;
///
/// Editor building scenes data state.
///
public readonly BuildingScenesState BuildingScenesState;
internal EditorStateMachine(Editor editor)
{
// Register all in-build states
AddState(LoadingState = new LoadingState(editor));
AddState(ClosingState = new ClosingState(editor));
AddState(EditingSceneState = new EditingSceneState(editor));
AddState(ChangingScenesState = new ChangingScenesState(editor));
AddState(PlayingState = new PlayingState(editor));
AddState(ReloadingScriptsState = new ReloadingScriptsState(editor));
AddState(BuildingLightingState = new BuildingLightingState(editor));
AddState(BuildingScenesState = new BuildingScenesState(editor));
// Set initial state
GoToState(LoadingState);
}
internal void Update()
{
// Changing states
while (_pendingStates.Count > 0)
{
GoToState(_pendingStates.Dequeue());
}
// State update
if (CurrentState != null)
{
CurrentState.Update();
CurrentState.UpdateFPS();
}
}
///
protected override void SwitchState(State nextState)
{
Editor.Log($"Changing editor state from {currentState} to {nextState}");
base.SwitchState(nextState);
}
}
}