Author Topic: Unusual content  (Read 2858 times)

Lex_87

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 11
    • View Profile
Unusual content
« on: February 24, 2014, 06:28:59 AM »
Is there a way to find unusual content such as sprites in atlases?

We have too many atlases wich contains unusual sprites.
Content changes dynamically. It is too hard to investigate this every time.

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: Unusual content
« Reply #1 on: February 24, 2014, 07:52:20 AM »
What do you mean by "unusual"?

Lex_87

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 11
    • View Profile
Re: Unusual content
« Reply #2 on: February 24, 2014, 12:16:58 PM »
I meant that sprites in atlases which do not use in the components of objects the scene hierarchy.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Unusual content
« Reply #3 on: February 24, 2014, 04:40:04 PM »
There is no such functionality with the stock NGUI, no.

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: Unusual content
« Reply #4 on: February 24, 2014, 05:01:36 PM »
Aaa, "unused". :) Well, it's a bit tricky to do something like that, because you have to account for all prefabs and all other scenes which may have sprites used as well.

It's easy enough to check the current scene, but to check all the other stuff is a bit more difficult.

Lex_87

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 11
    • View Profile
Re: Unusual content
« Reply #5 on: February 25, 2014, 03:21:07 AM »
Quote
It's easy enough to check the current scene

Okay, master!
I can't check other stuff and i can check stuff of the current scene.
But how can i do it? FAQ does not contain this topic.

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: Unusual content
« Reply #6 on: February 25, 2014, 05:02:47 AM »
Since each UISprite references its atlas and has a spriteName, you can check all the relevant atlases for sprite names and remove the used ones. Whatever's left over is unused.

Here's some scribblecode:
  1. public UIAtlas[] allMyAtlases; //drag references from inspector
  2.  
  3.  
  4. void start(){
  5. //naming all sprites
  6. var allSpritesInAtlases = new List<string>[]();
  7. for(int i=0;i<allMyAtlases;i++){
  8. var atlas in allMyAtlases[i];
  9. allSpritesInAtlases[i] = atlas.GetListOfSprites().ToArray();
  10. }
  11.  
  12. UISprite[] allSpritesInScene = FindObjectsOfType<UISprite>();
  13.  
  14. foreach(var s in allSpritesInScene){
  15. for(int i = 0; i<allMyAtlases; i++){
  16. if (allMyAtlases[i] == s.atlas){
  17. allSpritesInAtlases[i].Remove(s.spriteName);
  18. continue;
  19. }
  20. }
  21. }
  22.  
  23. //whatever's left over in the appSpritesInAtlases is unused. Debug.Log it and remove the source files and clean up the atlas manually based on this.
  24. }
  25.  
  26.  

If you're hardcore, you can even have the atlasmaker remove the sprites from the atlas directly, but it can be a little dangerous
see http://www.tasharen.com/ngui/docs/class_u_i_atlas_maker.html

Lex_87

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 11
    • View Profile
Re: Unusual content
« Reply #7 on: February 25, 2014, 07:16:04 AM »
Thank you for a good idea!