Author Topic: Loading and UIAtlas texture out and replacing it with a different resolution one  (Read 4144 times)

triggly_glix

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 13
    • View Profile
Hi,

So i'm not sure why this won't work. I tried creating dummy atlases and using the .replacement feature. that works okay but is a huge work overhead for our project which has more than 100 atlases.
What i basically would like to do is create the atlas at one resolution and then manually replace the texture with a lower res one in code. this works but the texture coordinates for the individual sprites is off. The UIAtlas is set to Tex Coords ... and the scale is uniform so ican't see why this wouldn 't work. Is there some internal storage of the pixel positions of sprites or something, or some call i can call to get NGUI to recalculate whatever it has in there...?

Thanks,
Ross

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Judging by your mention of TexCoords, I am guessing you're using NGUI 2 as this feature is gone in NGUI 3.

As I recall nothing is stored internally like that. You need to make sure that the atlas is set to tex coords before changing the texture, and that the sprites are located in the same exact positions.

triggly_glix

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 13
    • View Profile
Okay thanks - I think this is working now - i do it like this ->

...

atlasScript = (UIAtlas)gameObject.GetComponent(typeof(UIAtlas));
                  
Resources.UnloadAsset(atlasScript.spriteMaterial.mainTexture);
         
atlasScript.spriteMaterial.mainTexture = (Texture2D)Resources.Load ("Ross_Atlases/@iPad2/PigbyBar_Atlas_@2x" );

...

but at this point the sprites on screen get full of garbage - and ONLY once i move something in the editor do they get refreshed and filled up with the new correct texture...

i tried calling panel.Refresh() on their panel straight after the above - but no joy there... any clues ? thanks...

« Last Edit: November 18, 2013, 02:43:42 PM by triggly_glix »

triggly_glix

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 13
    • View Profile
In an attempt to make this nice and clear - here's a very short video of the behaviour -
what i am ultimately trying to achieve is just loading in atlases at different resolutions - with this system i have the atlas set to "Tex Coords" as i said - and I'm loading in and out the actual atlas texture. I would also be happy to go the dummy & .replacement technique - but i don't seem to be able to get that to actually remove the unused textures from memory.

so here's what's happening now...
i've tried Refresh on the UIPAnel and MakeItDirty on the UIAtlas but neither of them work -
any help very much appreciated - this is late on in a project where we;ve used NGUI quite heavily (too late to switch to 3 (!))

https://dl.dropboxusercontent.com/u/11634924/NGUI_redraw_problem.mp4

thanks,
Ross

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
UIAtlas has the MarkAsChanged() function which finds all sprites using the atlas and marks them as dirty. This is what the atlas maker uses after it changes sprite data. Have you tried it?