// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved. using FlaxEngine; using FlaxEngine.Utilities; namespace FlaxEditor.States { /// /// Base class for all Editor states. /// /// [HideInEditor] public abstract class EditorState : State { /// /// Gets the editor state machine. /// public new EditorStateMachine StateMachine => owner as EditorStateMachine; /// /// Gets the editor object. /// public readonly Editor Editor; /// /// Checks if can edit assets in this state. /// public virtual bool CanEditContent => true; /// /// Checks if can edit scene in this state /// public virtual bool CanEditScene => false; /// /// Checks if can use toolbox in this state. /// public virtual bool CanUseToolbox => false; /// /// Checks if can use undo/redo in this state. /// public virtual bool CanUseUndoRedo => false; /// /// Checks if can change scene in this state. /// public virtual bool CanChangeScene => false; /// /// Checks if can enter play mode in this state. /// public virtual bool CanEnterPlayMode => false; /// /// Checks if can enter recompile scripts in this state. /// public virtual bool CanReloadScripts => false; /// /// Checks if static is valid for Editor UI calls and other stuff. /// public virtual bool IsEditorReady => true; /// /// Checks if state requires more device resources (eg. for lightmaps baking or navigation cooking). Can be used to disable other engine and editor features during this state. /// public virtual bool IsPerformanceHeavy => false; /// /// Gets the state status message for the UI. Returns null if use the default value. /// public virtual string Status => null; /// /// Initializes a new instance of the class. /// /// The editor. protected EditorState(Editor editor) { Editor = editor; } /// /// Update state. Called every Editor tick. /// public virtual void Update() { } /// /// Updates the Time settings for Update/FixedUpdate/Draw frequency. Can be overriden per-state. /// public virtual void UpdateFPS() { var generalOptions = Editor.Options.Options.General; var editorFps = generalOptions.EditorFPS; if (!Platform.HasFocus) { // Drop performance if app has no focus Time.DrawFPS = generalOptions.EditorFPSWhenNotFocused; Time.UpdateFPS = generalOptions.EditorFPSWhenNotFocused; } else if (editorFps < 1) { // Unlimited power!!! Time.DrawFPS = 0; Time.UpdateFPS = 0; } else { // Custom or default value but just don't go too low editorFps = Mathf.Max(editorFps, 10); Time.DrawFPS = editorFps; Time.UpdateFPS = editorFps; } // Physics is not so much used in edit time Time.PhysicsFPS = 30; } /// public override bool CanExit(State nextState) { // TODO: add blocking changing states based on this state properties return base.CanExit(nextState); } } }