Author Topic: change atlas and atlas correction  (Read 4389 times)

mapleegreen

  • Guest
change atlas and atlas correction
« on: October 16, 2012, 05:47:07 AM »
I use a script to switch atlas.
  1.         void iosChange()
  2.         {
  3.                 if(Application.platform == RuntimePlatform.IPhonePlayer)
  4.                 {
  5.                         if(Screen.currentResolution.width==480)
  6.                                 {
  7.                                         for(int i=0;i<pairs.Length;i++)
  8.                                         {
  9.                                                 pairs[i].atlasRef.replacement = pairs[i].atlas480x320;
  10.                                         }
  11.                                
  12.                                 }
  13.                         if(Screen.currentResolution.width==1136)
  14.                                 {
  15.                                         for(int i=0;i<pairs.Length;i++)
  16.                                         {
  17.                                                 pairs[i].atlasRef.replacement = pairs[i].atlas1136x640;
  18.                                         }
  19.                                
  20.                                 }
  21.                                 if(Screen.currentResolution.width==960)
  22.                                 {
  23.                                         for(int i=0;i<pairs.Length;i++)
  24.                                         {
  25.                                                 pairs[i].atlasRef.replacement = pairs[i].atlas960x640;
  26.                                         }
  27.                                
  28.                                 }
  29.                                 if(Screen.currentResolution.width==1024)
  30.                                 {
  31.                                         for(int i=0;i<pairs.Length;i++)
  32.                                         {
  33.                                                 pairs[i].atlasRef.replacement = pairs[i].atlas1024x768;
  34.                                         }
  35.                                        
  36.                                 }
  37.                 }
  38.         }
  39.        
  40.         void androidChange()
  41.         {
  42.                 if(Application.platform == RuntimePlatform.Android)
  43.                 {
  44.                         if(Screen.currentResolution.width<1024)
  45.                                 {
  46.                                         for(int i=0;i<pairs.Length;i++)
  47.                                         {
  48.                                                 pairs[i].atlasRef.replacement = pairs[i].atlas800x480;
  49.                                         }
  50.                                        
  51.                                 }
  52.                         if(Screen.currentResolution.width>=1024&&Screen.currentResolution.width<1280)
  53.                                 {
  54.                                         for(int i=0;i<pairs.Length;i++)
  55.                                         {
  56.                                                 pairs[i].atlasRef.replacement = pairs[i].atlas1024x768;
  57.                                         }
  58.                                        
  59.                                 }
  60.                        
  61.                         if(Screen.currentResolution.width>=1280)
  62.                                 {
  63.                                         if(Screen.currentResolution.height>=800)
  64.                                         {
  65.                                                         for(int i=0;i<pairs.Length;i++)
  66.                                                 {
  67.                                                         pairs[i].atlasRef.replacement = pairs[i].atlas1280x800;
  68.                                                 }
  69.                                         }
  70.                                         else
  71.                                         {
  72.                                                         for(int i=0;i<pairs.Length;i++)
  73.                                                         {
  74.                                                                 pairs[i].atlasRef.replacement = pairs[i].atlas1280x720;
  75.                                                         }
  76.                                         }
  77.                                
  78.                                        
  79.                                 }
  80.                        
  81.                 }
  82.         }

  I use the device to test the effect and found the result not as I expected.for example,my sprite real size is 161x38 when resolution is 800x480,194x51 size when resolution is 960x640.When I set my editor resolution is 960x640,and add a sprite in editor,and in inspector,it's scale is auto set 194x51,and I deploy the app on iphone,everything is right.
  But I switch the platform and deploy the app on android device.the sprite size is not change,still 194x51.I have change the atlas ,isn't it?To solve this problem,I must select the sprite in editor and click correction --"Make Pixel-Perfect",and it's scale is auto set 161x38.Obviously,So much resolution I can not so each set.
  I don't know where the problem.Help me,please!!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: change atlas and atlas correction
« Reply #1 on: October 16, 2012, 07:48:03 AM »
UIRoot.Broadcast("MakePixelPerfect") will also do the trick -- on all widgets at once.

Keep in mind, atlas switching is mainly intended for SD/HD/UD atlases which are 1/2/4 in sizes, respectively. This makes it easy to set the pixel size on the atlas, and all sprites don't need to be moved at all. Your resolutions don't follow this pattern, so your pixel size either needs to be set properly to compensate (so that widgets don't change their size when you do MakePixelPerfect), or just deal with it via the broadcast command I noted above.

mapleegreen

  • Guest
Re: change atlas and atlas correction
« Reply #2 on: October 16, 2012, 10:16:48 AM »
tanks a lot.

filo

  • Guest
Re: change atlas and atlas correction
« Reply #3 on: January 11, 2013, 09:41:23 AM »
I had the same problem and UIRoot broadcast didn't work. NGUITools broadcast did.

NGUITools.Broadcast("MakePixelPerfect");