Author Topic: Loading atlas from server  (Read 2581 times)

Peter83

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1
    • View Profile
Loading atlas from server
« on: April 09, 2014, 09:13:37 AM »
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?


 
  1. AssetBundle atlasBundle = bigWWW.assetBundle;
  2.  
  3.                         Object[] objectsInBundle = atlasBundle.LoadAll ();
  4.  
  5.                         //Debug.Log ("objectsInBundle.Length = " + objectsInBundle.Length.ToString() );
  6.  
  7.                         for (int i = 0; i < objectsInBundle.Length; i++) {
  8.                        
  9.                                 //Debug.Log(i.ToString() + "  " + objectsInBundle[i].name + " " + objectsInBundle[i]);
  10.                        
  11.                                 if (objectsInBundle[i] is GameObject) {
  12.  
  13.                                         GameObject gameObjectWithAtlas = (GameObject)(objectsInBundle[i]);
  14.                                         UIAtlas atlas = gameObjectWithAtlas.GetComponent<UIAtlas>();
  15.  
  16.                                         GameFieldViewBindings gameFieldViewBindings = GameObject.Find ("gameFieldBindings").GetComponent<GameFieldViewBindings> ();
  17.                                         gameFieldViewBindings.atlasProcs.replacement = atlas;
  18.  
  19.                                         BetterList<string> spriteList = atlas.GetListOfSprites();
  20.  
  21.                                         //Debug.Log(i.ToString() + " is GameObject");
  22.                                 }
  23.                         }


Thanks for your help.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Loading atlas from server
« Reply #1 on: April 10, 2014, 06:36:00 AM »
You will need to create separate asset bundles. One per platform. They are inherently incompatible with each other from what I remember.