Now that our multiple atlases are ready with different qualities, we can write the code to switch between them at runtime. In order to achieve this, we will create a new AtlasSwitchController
component, attached to our scene's UI Root
.
Follow these steps to create the new AtlasSwitchController
component:
Select our
UI Root
GameObject.In the Inspector panel, click on the Add Component button.
Type in
AtlasSwitchController
and hit the Enter key.Make sure that Language is set to CSharp and hit Enter again.
Open our new AtlasSwitchController.cs
script, and declare these global variables:
// The reference atlas public UIAtlas referenceAtlas; // Screen width thresholds public int HDFromWidth = 800; public int SHDFromWidth = 1600; // Atlases for all qualities public UIAtlas SDAtlas; public UIAtlas HDAtlas; public UIAtlas SHDAtlas; // This will store the replacement atlas private UIAtlas replacementAtlas;