private IEnumerator UnloadScene() { if (this.GetLoadedSceneRoot()) { this._onBeforeUnload.Invoke(); if (this._unloadDelay > 0f) { yield return(new WaitForSeconds(this._unloadDelay)); } SceneManager.sceneUnloaded += this.SceneManager_sceneUnloaded; yield return(SceneManager.UnloadSceneAsync(this._sceneName)); yield return(null); yield return(null); ResourcesHelper.UnloadUnusedAssets(); yield return(null); yield return(null); ResourcesHelper.GCCollect(); } this._onFinishedUnloading.Invoke(); this.OnActionFinished(); yield break; }
public void DoUnloadUnusedAssets() { ResourcesHelper.UnloadUnusedAssets(); if (this._gcCollect) { ResourcesHelper.GCCollect(); } }
private IEnumerator Start() { yield return(null); ResourcesHelper.UnloadUnusedAssets(); yield return(null); ResourcesHelper.GCCollect(); yield break; }
private IEnumerator LoadLevelWithProgress(string levelToLoad) { using (new PerfTimerLogger("[<color=#FFF>TIMER</color>] Cleanup", PerfTimerLogger.LogResultType.Milliseconds, null)) { if (this.delayForCleanup) { ResourcesHelper.UnloadUnusedAssets(); ResourcesHelper.GCCollect(); yield return(null); } } using (new PerfTimerLogger("[<color=#FFF>TIMER</color>] failsafe", PerfTimerLogger.LogResultType.Milliseconds, null)) { float failsafe = 5f; while (BoltNetwork.isRunning && failsafe > 0f) { failsafe -= Time.deltaTime; yield return(null); } } yield return(null); PerfTimerLogger queryStateTimer = new PerfTimerLogger("[<color=#FFF>TIMER</color>] Query state", PerfTimerLogger.LogResultType.Milliseconds, null); bool canResume = LevelSerializer.CanResume; bool boltIsRunning = BoltNetwork.isRunning; bool boltIsServer = BoltNetwork.isServer; bool boltIsClient = BoltNetwork.isClient; bool isSavedGame = GameSetup.IsSavedGame; queryStateTimer.Stop(); if (canResume && (!boltIsRunning || boltIsServer) && isSavedGame) { PerfTimerLogger resumeTimer = new PerfTimerLogger("[<color=#FFF>TIMER</color>] Resume", PerfTimerLogger.LogResultType.Milliseconds, null); ResourceRequest req = Resources.LoadAsync("PreloadingPrefabs"); while (!req.isDone) { yield return(null); } UnityEngine.Object.Instantiate(req.asset); yield return(null); LevelSerializer.InitPrefabList(); yield return(null); LevelSerializer.Resume(); resumeTimer.Stop(); yield break; } PerfTimerLogger loadLevelTimer = new PerfTimerLogger(string.Format("[<color=#FFF>TIMER</color>] Load {0}", levelToLoad), PerfTimerLogger.LogResultType.Milliseconds, null); UnityEngine.Object.DontDestroyOnLoad(base.gameObject); if (!boltIsClient && !canResume) { GameSetup.SetInitType(InitTypes.New); } try { if (PlayerPreferences.AllowAsync) { this.async = SceneManager.LoadSceneAsync(levelToLoad); } else { SceneManager.LoadScene(levelToLoad); } } catch (Exception ex) { loadLevelTimer.Stop(); this.AttemptLoadRecovery(); UnityEngine.Object.Destroy(base.gameObject); throw; } while (PlayerPreferences.AllowAsync && !this.async.isDone) { LoadingProgress.Progress = this.async.progress * 0.5f; yield return(null); } LoadingProgress.Progress = 0.5f; loadLevelTimer.Stop(); UnityEngine.Object.Destroy(base.gameObject); yield break; }