So far we've been working with a single Screen. This tutorial covers how to work with multiple screens, including how to add and destroy screens in response to UI events.
Before we write any code, we'll create two screens. A real game might have screens like a TitleScreen, OptionsScreen, GameScreen (which includes hud and a pause menu), and a GameOverScreen. For this tutorial we'll create two simple screens, each with a single button and a Text.
Next we'll make the following modifications to Game1:
Change the first screen to Screen1
Make the Root property public static
so that it can be accessed by the Screens
A full game may keep the Root in a dedicated object which provides access to the Screens, but we're making it public static
to keep the tutorial simple.
Now we can modify both Screen1Runtime.cs and Screen2Runtime.cs to include code that links from one to the other as shown in the following code:
Each screen removes itself from managers when its button is clicked, then creates and adds the next screen to managers.
This tutorial showed how to switch between two screens by removing the old screen with RemoveFromManagers and creating a new screen with ToGraphicalUiElement.