public virtual void Destroy() { #if !FRB_MDX StateManager.Current.Activating -= ActivatingAction; StateManager.Current.Deactivating -= DeactivatingAction; #endif if (mLastLoadedScene != null) { mLastLoadedScene.Clear(); } FlatRedBall.Debugging.Debugger.DestroyText(); // It's common for users to forget to add Particle Sprites // to the mSprites SpriteList. This will either create leftover // particles when the next screen loads or will throw an assert when // the ScreenManager checks if there are any leftover Sprites. To make // things easier we'll just clear the Particle Sprites here. bool isPopup = this != ScreenManager.CurrentScreen; if (!isPopup) { SpriteManager.RemoveAllParticleSprites(); } if (UnloadsContentManagerWhenDestroyed && mContentManagerName != FlatRedBallServices.GlobalContentManager) { FlatRedBallServices.Unload(mContentManagerName); FlatRedBallServices.Clean(); } if (ShouldRemoveLayer && mLayer != null) { SpriteManager.RemoveLayer(mLayer); } if (IsPaused) { UnpauseThisScreen(); } GuiManager.Cursor.IgnoreNextClick = true; if (mNumberOfThreadsBeforeAsync != -1) { FlatRedBallServices.SetNumberOfThreadsToUse(mNumberOfThreadsBeforeAsync); } if (ScreenDestroy != null) { ScreenDestroy(); } }
public void StartAsyncLoad(string screenType, Action afterLoaded = null) { if (AsyncLoadingState == AsyncLoadingState.LoadingScreen) { #if DEBUG throw new InvalidOperationException("This Screen is already loading a Screen of type " + asyncScreenTypeToLoad + ". This is a DEBUG-only exception"); #endif } else if (AsyncLoadingState == AsyncLoadingState.Done) { #if DEBUG throw new InvalidOperationException("This Screen has already loaded a Screen of type " + asyncScreenTypeToLoad + ". This is a DEBUG-only exception"); #endif } else { AsyncLoadingState = AsyncLoadingState.LoadingScreen; asyncScreenTypeToLoad = ScreenManager.MainAssembly.GetType(screenType); if (asyncScreenTypeToLoad == null) { throw new Exception("Could not find the type " + screenType); } #if REQUIRES_PRIMARY_THREAD_LOADING // We're going to do the "async" loading on the primary thread // since we can't actually do it async. PerformAsyncLoad(); if (afterLoaded != null) { afterLoaded(); } #else mNumberOfThreadsBeforeAsync = FlatRedBallServices.GetNumberOfThreadsToUse(); FlatRedBallServices.SetNumberOfThreadsToUse(1); Action action; if (afterLoaded == null) { action = (Action)PerformAsyncLoad; } else { action = () => { PerformAsyncLoad(); // We're going to add this to the instruction manager so it executes on the main thread: InstructionManager.AddSafe(new DelegateInstruction(afterLoaded)); }; } #if WINDOWS_8 || UWP System.Threading.Tasks.Task.Run(action); #else ThreadStart threadStart = new ThreadStart(action); Thread thread = new Thread(threadStart); thread.Start(); #endif #endif } }