Book Image

Learning NGUI for Unity

By : Charles Bernardoff (EURO)
Book Image

Learning NGUI for Unity

By: Charles Bernardoff (EURO)

Overview of this book

Table of Contents (17 chapters)
Learning NGUI for Unity
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Switching atlases


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.

The AtlasSwitchController component

Follow these steps to create the new AtlasSwitchController component:

  1. Select our UI Root GameObject.

  2. In the Inspector panel, click on the Add Component button.

  3. Type in AtlasSwitchController and hit the Enter key.

  4. 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;

Now, add the following Awake() method that...