[MenuItem ("Custom/Fix Up Atlas References")]
static void FixUpAtlasRefs()
{
UIAtlas
[] atlases
= FindObjectsOfType
(typeof(UIAtlas
)) as UIAtlas
[];
// This will only work if there is but one solitary atlas in the scene.
// Othewise we won't know which one to pick as the replacement.
if(atlases.Length == 1)
{
UIAtlas newAtlas = atlases[0];
// Won't work with deactivated objects, so you'll need to manually activate everything first.
// Thanks, Unity... *sigh*
UISprite
[] sprites
= FindObjectsOfType
(typeof(UISprite
)) as UISprite
[];
if(sprites != null)
{
foreach(UISprite sprite in sprites)
{
sprite.atlas = newAtlas;
}
}
UILabel
[] labels
= FindObjectsOfType
(typeof(UILabel
)) as UILabel
[];
if(labels != null)
{
foreach(UILabel label in labels)
{
label.font.atlas = newAtlas;
}
}
Debug.Log("Fixed up " + sprites.Length + " sprites and " + labels.Length + "labels");
}
else
{
Debug.Log("Found " + atlases.Length + " UIAtlases in the scene. There should be exactly 1 UIAtlas in the scene.");
}
}