Author Topic: Asset Bundled NGUI  (Read 17202 times)

littlemuggo

  • Guest
Asset Bundled NGUI
« on: April 26, 2012, 04:06:56 PM »
Heylo peeps,

Has anyone tried to access NGUI through Asset Bundles?

I've created a full HUD and bundled it together. In another scene, I am spawning the HUD and it is spawning in the scene with all children, logic, etc - however... none of the sprites, fonts, etc are showing after spawned.

I also get the following error:
NullReferenceException: Object reference not set to an instance of an object
UIAtlas.GetListOfSprites() (at UIAtlas.cs:259)

If I pause Unity and click on an object within the NGUI HUD, I get the above error again. It wants to draw it but doesn't have a reference to the Atlas - even though it should have been bundled when the asset bundle is created...

Any guidance or help would be great!




ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Asset Bundled NGUI
« Reply #1 on: April 26, 2012, 04:12:26 PM »
Did you really bundle the atlas, or just the hierarchy of the UI that uses it? It's generally easy to tell. The size of the bundle changes drastically when the atlas texture is in it.

littlemuggo

  • Guest
Re: Asset Bundled NGUI
« Reply #2 on: April 26, 2012, 04:48:52 PM »
Yessir - for sure it is included. Triple checked, re-built a few times to verify, etc. Not finding it though... Weird things are afoot. :)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Asset Bundled NGUI
« Reply #3 on: April 26, 2012, 04:53:55 PM »
Odd. Any reason why you're using asset bundles for this though? Asset bundles are generally for downloading content via the web. If you want to create a UI in one scene and use it in another, you should use prefabs for that instead.

littlemuggo

  • Guest
Re: Asset Bundled NGUI
« Reply #4 on: April 26, 2012, 05:02:47 PM »
This is how we setup our system. We create the GUI, spawnable/changeable GameObjects, etc in a separate project. Then, asset bundle each object out for download purposes, flexibility, etc.

Would do it as just a prefab, but it is located in the GUI project and not in the login, levels, game, etc... So, asset bundle is required.  I can copy and paste the object, atlas, etc in all projects anytime a change is made - but... this is not the way to go.

littlemuggo

  • Guest
Re: Asset Bundled NGUI
« Reply #5 on: April 26, 2012, 05:04:10 PM »
Forgot to mention... This also allows people to work quicker without having to open up a main project which is 12+ gigs.  ;D Instead, we are focused in specific smaller areas to reduce rebuild time, etc.

littlemuggo

  • Guest
Re: Asset Bundled NGUI
« Reply #6 on: April 27, 2012, 09:47:35 AM »
So... Assume NGUI will not be supporting itself in Asset Bundles?

littlemuggo

  • Guest
Re: Asset Bundled NGUI
« Reply #7 on: April 27, 2012, 11:58:28 AM »
Found a work around for the time being. Adding the Atlas and any Fonts to the actual hierarchy allowed it to work. Referencing, etc does not work within the Asset Bundle.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Asset Bundled NGUI
« Reply #8 on: April 27, 2012, 06:02:23 PM »
By actual hierarchy you mean instantiating them in your scene?

littlemuggo

  • Guest
Re: Asset Bundled NGUI
« Reply #9 on: April 30, 2012, 12:05:13 PM »
The hierarchy of the HUD that was asset bundled. Had to add them somewhere in the hierarchy of the HUD that is being asset bundled.

Example (* = child):
UI Root(2D)
* Camera
* * Anchor's...

* NGUI Requirements
* * HUD Atlas
* * HUD Font

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Asset Bundled NGUI
« Reply #10 on: April 30, 2012, 12:26:14 PM »
Ah, interesting, thanks.

patch24

  • Guest
Re: Asset Bundled NGUI
« Reply #11 on: November 01, 2012, 02:41:18 PM »
Hi I'm trying to do the same thing, bundling an NGUI UI into an Asset Bundle.  I'm curious how you actually include the Atlas into the hierarchy? Is it just added as a material which points to the 2d atlas image?

pretender

  • Full Member
  • ***
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 155
    • View Profile
Re: Asset Bundled NGUI
« Reply #12 on: February 08, 2016, 08:23:01 AM »
Any ideas about this? I am trying to bundle sd,hd and ud atlases and downoad in the first splash scene the one that is determined by the screen width?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Asset Bundled NGUI
« Reply #13 on: February 09, 2016, 02:47:56 AM »
My suggestion is... don't.

What takes up 99.9% of the space is the texture. So that's all you need to download. You should keep the atlas, just dereference its material's texture. Then download the texture at run-time and re-assign it to your atlas' material.

pretender

  • Full Member
  • ***
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 155
    • View Profile
Re: Asset Bundled NGUI
« Reply #14 on: February 12, 2016, 03:50:31 AM »
Thanks Aren! I followed your advice and made asset bundles for three textures sd,hd and ud.
It correctly downloads and replaces texture on material but I suspect that I need one more step to notify
NGUI that change took place. For example, I have label set with reference atlas set to DefaultSD, for test I set
texture UD to be downloaded and it does but sprites get messed up when changed. Is this proper way to change textures on materials:

  1.  
  2. Caching.CleanCache();
  3.  
  4.         Debug.Log(url);
  5.         _download = WWW.LoadFromCacheOrDownload(url, 1);
  6.         yield return _download;
  7.         if (!string.IsNullOrEmpty(_download.error))
  8.         {
  9.             Debug.LogError(_download.error);
  10.         }
  11.         else
  12.         {
  13.             _bundle = _download.assetBundle;
  14.             Debug.Log("Bundle Loaded Successfully" + _bundle.name);
  15.         }
  16.  
  17.         if (_bundle != null)
  18.         {
  19.             var texture =_bundle.LoadAsset(assetName,typeof(Texture));
  20.             AtlasREF.spriteMaterial.mainTexture = texture as Texture;
  21.             AtlasREF.MarkAsChanged();
  22.         }
  23.  
  24.