Author Topic: Switch between SD and HD Textures - Memory Usage/Cleanup on iOS  (Read 3453 times)

pordox

  • Guest
Hello Everybody

I've bought NGUI recently, so I'm relatively new to the subject.

I'm developing a game for iPhone, iPad and Android and I have lots of textures for the UI. Currently I have to use up to 25 different atlases only for the Tablet-UI (Tablet and Phone need special UIs). The Unity GUI was at it's limits, the game was brutally slow in the end, that's why I switched over to NGUI. But now, I've some trouble with the memory on older devices (the game should run on an iPad 1st Gen).

I dont want to publish a special version for retina displays. As shown in several tutorials, I have to use atlas-references. So now, when the game starts, I first check the device and screen resolution. Then the game loads all atlas-references and the right atlases (HD or SD) from the resources-folder (all atlases are in there). Then I set all the references (atlasReference.replacement) and the pixel size (atlasReference.pixelSize = 1 for HD, 2 for SD). This works great...

But the game always has the same amount of total allocated memory, doesnt matter if I load the HD or SD atlases. Unloading unused assets in Unity does nothing. So, am I doing something basically wrong or is there a way to tell Unity or NGUI not to load all atlases?  ???

Thanks for your time,
*prox

Here's a little bit of code of what the game does with the atlas references...

  1.  
  2. [...]
  3.  
  4. atlasPath = "UI/Atlases/" + game.PlatformType.ToString();
  5. atlasReferencesPath = atlasPath + "/References";
  6.  
  7. Object[] atlasReferenceObjects = Resources.LoadAll(atlasReferencesPath, typeof(UIAtlas));
  8.  
  9. foreach (UIAtlas atlasReference in atlasReferenceObjects) {
  10.  
  11.         UIAtlas atlas = Resources.Load(atlasPath +"/"+ atlasReference.name +"_"+ pscreenType.ToString(), typeof(UIAtlas)) as UIAtlas;
  12.                        
  13.         if (atlas != null)
  14.         {
  15.                 atlasReference.replacement = atlas;
  16.                                
  17.                 if (pscreenType == ScreenType.HD) {
  18.                         atlasReference.pixelSize = 1;
  19.                 }
  20.                 else {
  21.                         atlasReference.pixelSize = 2;
  22.                 }
  23.         }
  24. }
  25. Resources.UnloadUnusedAssets();
  26. System.GC.Collect();
  27.  
  28. [...]
  29.  
  30.  

Resources folder looks like this, for example...

Resources/UI/Atlases/Tablet/References/Buttons
Resources/UI/Atlases/Tablet/Buttons_HD
Resources/UI/Atlases/Tablet/Buttons_SD

RevenantX

  • Guest
Re: Switch between SD and HD Textures - Memory Usage/Cleanup on iOS
« Reply #1 on: March 26, 2013, 07:08:35 AM »
I have that problem too. I thing this is NGUI bug.

RevenantX

  • Guest
Re: Switch between SD and HD Textures - Memory Usage/Cleanup on iOS
« Reply #2 on: April 03, 2013, 03:41:27 AM »
Up

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Switch between SD and HD Textures - Memory Usage/Cleanup on iOS
« Reply #3 on: April 03, 2013, 02:59:11 PM »
Before you can unload an asset, you must completely stop using it -- which in this case means making sure that the process of switching atlases actually has time to take effect (which is delayed until the next frame). Other than that, this is a Unity question, not an NGUI question.