I'd just like to share my Atlas swapping method in case it was useful for anyone or someone could offer further suggestions!
My goal is: At runtime, only load the Atlas textures that are needed for the device resolution. So if the game is run on iPhone 3gs, only SD Atlases are loaded into memory, not HD or IPAD3-HD.
1. Set up all UISprites to use Reference type UIAtlas.
2. Create SD, HD, IPAD3-HD UIAtlases for the different resolutions. Place these in a Resources folder so they can be loaded at runtime.
3. Run a custom pre-build script that strips all UIAtlas references when building for iOS.
4. At runtime, loop through all loaded UIAtlas components and set the correct reference to either SD, HD or IPAD-HD depending on the device resolution. (Note only reference UIAtlases are loaded at this point)
Here is the code for looping through and sets the correct reference for all UIAtlas components in the game -
// find all LOADED UIAtlas components
UIAtlas
[] uiAtlases
= Resources
.FindObjectsOfTypeAll(typeof(UIAtlas
)) as UIAtlas
[];
foreach(UIAtlas atlasRef in uiAtlases)
{
// If this is a reference atlas and the atlas dosen't have a replacement...
if (atlasRef.name.Contains("-Ref") && atlasRef.replacement == null)
{
// Gets the name of the atlas that needs to be used (SD, HD or IPAD-HD)
string resAppropriatePath = GetCorrectReplacementAtlasName(atlasRef);
// Loads the new atlas
UIAtlas replacementAtlas
= Resources
.Load(resAppropriatePath,
typeof(UIAtlas
)) as UIAtlas
;
// Sets the new atlas as the replacment
atlasRef.replacement = replacementAtlas;
Debug.Log("UIHandlerClass setting replacementAtlas: "+replacementAtlas);
}
}
I look forward to any sugestions on this!