using System.Collections.Generic; using UnityEditor; namespace Ubisoft.Hotel.PackageManager.Editor { internal class BuildStep_ReloadAssemblies : BuildStep { private enum EStep { None, ReloadingAssemblies, Compiling, Done } internal const string StepName = "BuildStep_ReloadAssemblies"; private const string PREFS_STEP_KEY = "HT.PACKAGEMANAGER.ReloadingAssembliesStep"; internal BuildStep_ReloadAssemblies() : base(StepName) { } protected override void ExtendedPerform() { // Assemblies need to be reloaded only if the collection of packages has changed if (PackageManager.BuildBatch_ManifestHasChanged) { if (Step == EStep.None) { Step = EStep.ReloadingAssemblies; } } else { Step = EStep.Done; } } private EStep Step { get { return (EStep)EditorPrefs.GetInt(PREFS_STEP_KEY, 0); } set { EditorPrefs.SetInt(PREFS_STEP_KEY, (int)value); switch (value) { case EStep.ReloadingAssemblies: Step = EStep.Compiling; BuildTargetGroup buildTargetGroup = BuildPipeline.GetBuildTargetGroup(EditorUserBuildSettings.activeBuildTarget); // We need to formce compilation to reload all assemblies effectively. We'll do that by deleting all symbols HashSet symbols = new HashSet(); // If there's no symbols defined then we need to at least define one to force compilation HashSet currentSymbols = HtPlayerSettings.GetScriptingDefineSymbolsForGroup(buildTargetGroup); if (currentSymbols.Count == 0) { _ = symbols.Add("FORCE_COMPILATION"); } HtPlayerSettings.SetScriptingDefineSymbolsForGroup(buildTargetGroup, symbols); EditorUtility.RequestScriptReload(); break; case EStep.Done: Step = EStep.None; OnDone(); break; } } } internal override void Update() { switch (Step) { case EStep.Compiling: if (!EditorApplication.isCompiling) { Step = EStep.Done; } break; } } } }