Author Topic: Change UIAtlas References from downloaded bundle  (Read 3021 times)

jandujar

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
Change UIAtlas References from downloaded bundle
« on: May 27, 2014, 10:32:27 AM »
Hello,

I'm trying to change a UIAtlas reference at runtime after loading a bundle

This is our situation.

We have 2 bundles for each platform
bundle_HD_ios.unity3d
bundle_SD_ios.unity3d
bundle_HD_android.unity3d
bundle_SD_android.unity3d

We have a loadingScene that loads the correct bundle from www (or local) (ios or android version) with the correct atlas for the platform used.

At this point, we have all of our scenes pointing to a UIAtlas Reference (for example SD version atlas or dummy atlas), and we want to change the Reference of this atlas after loading the atlas from the bundle.

This is the code we have, but doesn't work only works if we use the atlas (with prefab) in the loading scene and we make a sprite using this atlas.

Any idea/help will be very appreciated.

  1. ...
  2.                                         //The download is done, instantiate the asset from the bundle
  3.                                         GameObject obj = asset.InstantiateAsset();
  4.                                         gui_pack_001_link = GameObject.FindWithTag("gui_pack_001_link").GetComponent<UIAtlas>();
  5.                                         //gui_pack_001_link = GameObject.Find ("gui_pack_001_link").GetComponent<UIAtlas>();
  6.                                         gui_pack_001_link.replacement = obj.GetComponent<UIAtlas>();
  7.                                         //Remove the asset from the loading list
  8. ...
  9.  


jandujar

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
Re: Change UIAtlas References from downloaded bundle
« Reply #1 on: May 27, 2014, 10:47:07 AM »
Do we need to create a instance atlas like this?

  1.     #region Singleton
  2.     private static AssetBundleManager instance = null;
  3.     public static AssetBundleManager Instance
  4.     {
  5.         get
  6.         {
  7.             if (instance == null) // if the static instance is null, then create an instance of the manager
  8.             {
  9.                 Debug.Log("Creating an AssetBundle manager instance");
  10.                 GameObject go = new GameObject();
  11.                 instance = go.AddComponent<AssetBundleManager>();
  12.                 go.name = "AssetBundleManager";
  13.                                
  14.                 DontDestroyOnLoad(go);
  15.             }
  16.  
  17.             return instance;
  18.         }
  19.     }
  20.     #endregion
  21.  

jandujar

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
Re: Change UIAtlas References from downloaded bundle
« Reply #2 on: May 28, 2014, 03:49:22 AM »
finally I found the solution.

  1.  
  2. //The download is done, instantiate the asset from the bundle
  3.                                         GameObject obj = asset.InstantiateAsset();
  4.                                         gui_pack_001_link = Resources.Load("AtlasReferences/" + "gui_pack_001_link" , typeof(UIAtlas)) as UIAtlas;
  5.                                         gui_pack_001_link.replacement = obj.GetComponent<UIAtlas>();
  6.                                         DontDestroyOnLoad(obj);

pretender

  • Full Member
  • ***
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 155
    • View Profile
Re: Change UIAtlas References from downloaded bundle
« Reply #3 on: February 12, 2016, 04:08:45 AM »
Can you help me by telling me what kind of bundle you built? only textures or complete Atlas prefab?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile