// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved. using FlaxEditor.Utilities; namespace FlaxEditor.Progress.Handlers { /// /// Scripts compilation progress reporting handler. /// /// public sealed class CompileScriptsProgress : ProgressHandler { private SelectionCache _selectionCache; /// /// Initializes a new instance of the class. /// public CompileScriptsProgress() { // Link for events ScriptsBuilder.CompilationBegin += OnStart; ScriptsBuilder.CompilationSuccess += OnEnd; ScriptsBuilder.CompilationFailed += OnCompilationFailed; ScriptsBuilder.CompilationStarted += () => OnUpdate(0.2f, "Compiling scripts..."); ScriptsBuilder.ScriptsReloadCalled += () => OnUpdate(0.8f, "Reloading scripts..."); ScriptsBuilder.ScriptsReloadBegin += OnScriptsReloadBegin; ScriptsBuilder.ScriptsReloadEnd += OnScriptsReloadEnd; ScriptsBuilder.ScriptsReload += OnScriptsReload; } private void OnScriptsReloadBegin() { if (_selectionCache == null) _selectionCache = new SelectionCache(); _selectionCache.Cache(); // Clear references to the user scripts (we gonna reload an assembly) Editor.Instance.Scene.ClearRefsToSceneObjects(true); } private void OnScriptsReload() { #if !USE_NETCORE // Clear types cache Newtonsoft.Json.JsonSerializer.ClearCache(); #endif } private void OnCompilationFailed() { OnFail("Scripts compilation failed"); } private void OnScriptsReloadEnd() { _selectionCache.Restore(); } /// protected override void OnStart() { base.OnStart(); OnUpdate(0, "Starting scripts compilation..."); } } }