Hi,
I want to load atlases from asset bundles on a server. (We need to add new sprites without having to deploy a new version of the game. The sprite names will be sent in JSON-Responses.)
I did the following:
I bundled the files of the real normal atlas into an asset bundle. The UI uses a reference atlas, which points to a normal atlas (placeholder with only on small image.)
I download the asset files with www and load the UIAtlas-Object in the bundle. Then I change the replacement in the used reference atlas.
Is this the correct way to do this? Will this work on IOS and Android devices? I tested only with the web player yet.
The code for extracting the UIAtlas-Object looks a bit long-winded. I load all Objects in the bundle, then I look for the game object and collect its UIAtlas-Component. I used this load all solution because the bundle contains 5 objects with the name of the atlas (it contains only the atlas objects). Is there a better way to get correct object?
AssetBundle atlasBundle = bigWWW.assetBundle;
Object[] objectsInBundle = atlasBundle.LoadAll ();
//Debug.Log ("objectsInBundle.Length = " + objectsInBundle.Length.ToString() );
for (int i = 0; i < objectsInBundle.Length; i++) {
//Debug.Log(i.ToString() + " " + objectsInBundle[i].name + " " + objectsInBundle[i]);
if (objectsInBundle
[i
] is GameObject
) {
GameObject gameObjectWithAtlas = (GameObject)(objectsInBundle[i]);
UIAtlas atlas = gameObjectWithAtlas.GetComponent<UIAtlas>();
GameFieldViewBindings gameFieldViewBindings = GameObject.Find ("gameFieldBindings").GetComponent<GameFieldViewBindings> ();
gameFieldViewBindings.atlasProcs.replacement = atlas;
BetterList<string> spriteList = atlas.GetListOfSprites();
//Debug.Log(i.ToString() + " is GameObject");
}
}
Thanks for your help.