// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved. using FlaxEngine; using FlaxEngine.Assertions; using FlaxEngine.Utilities; namespace FlaxEditor.States { /// /// In this state engine is building static lighting for the scene. Editing scene and content is blocked. /// /// [HideInEditor] public sealed class BuildingLightingState : EditorState { private bool _wasBuildFinished; internal BuildingLightingState(Editor editor) : base(editor) { } /// public override bool CanEditContent => false; /// public override bool IsPerformanceHeavy => true; /// public override string Status => "Baking lighting..."; /// public override bool CanEnter() { return StateMachine.IsEditMode; } /// public override bool CanExit(State nextState) { return _wasBuildFinished; } /// public override void OnEnter() { // Clear flag _wasBuildFinished = false; // Bind event Editor.LightmapsBakeEnd += OnLightmapsBakeEnd; // Start building Editor.Scene.MarkAllScenesEdited(); Editor.Internal_BakeLightmaps(false); } /// public override void UpdateFPS() { Time.DrawFPS = 0; Time.UpdateFPS = 0; Time.PhysicsFPS = 30; } /// public override void OnExit(State nextState) { // Unbind event Editor.LightmapsBakeEnd -= OnLightmapsBakeEnd; } private void OnLightmapsBakeEnd(bool failed) { Assert.IsTrue(IsActive && !_wasBuildFinished); _wasBuildFinished = true; Editor.StateMachine.GoToState(); } } }