Author Topic: Switch between SD and HD atlas with a script!  (Read 14005 times)

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: Switch between SD and HD atlas with a script!
« Reply #15 on: May 16, 2012, 08:18:53 AM »
I actually did my way now, and it's doesn't work all that well.
I'm loading like this instead (which is essentially the same as loopy's)

  1. GameObject go = Resources.Load("gui/SDAtlas", typeof(GameObject)) as GameObject;
  2. UIAtlas myAtlas = go.GetComponent<UIAtlas>();
  3.  

luisdiv

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 32
    • View Profile
Re: Switch between SD and HD atlas with a script!
« Reply #16 on: June 20, 2012, 06:07:25 PM »
Hi guys,

I did my best to try and understand this topic and the one at http://www.tasharen.com/forum/index.php?topic=37.15, yet I still have problems with my referencing atlas :-[. I'm creating buttons dynamically which use that atlas, and reference 2 other which share sprite names.

I have the following code to swap atlases:
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class AtlasSwapper : MonoBehaviour {
  5.        
  6.         public UIAtlas atlasRef;
  7.         private UIAtlas atlasSD;
  8.         private UIAtlas atlasHD;
  9.        
  10.         void Start () {
  11.                 GameObject go = Resources.Load("Atlas_SD", typeof(GameObject)) as GameObject;
  12.                 atlasSD = go.GetComponent<UIAtlas>();
  13.  
  14.                 GameObject go2 = Resources.Load("Atlas_HD", typeof(GameObject)) as GameObject;
  15.                 atlasHD = go2.GetComponent<UIAtlas>(); 
  16.         }
  17.        
  18.         void Awake () {
  19.                 if (Mathf.Max(Screen.currentResolution.width, Screen.currentResolution.height) >= 640)
  20.                         atlasRef.replacement = atlasHD;
  21.                 else
  22.                         atlasRef.replacement = atlasSD;
  23.         }
  24.        
  25.         void OnDisable()
  26.     {
  27.         atlasRef.replacement = atlasSD;
  28.     }
  29. }
  30.  

I also have my main referencing atlas at the resources folder. The problem, is that once the scene loads on game, the referencing atlas converts to Normal instead of Reference, and loses its Atlas value. Therefore, only labels show up on screen :-\

I hope you guys have a solution for this. Thanks in advance.

Luis

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Switch between SD and HD atlas with a script!
« Reply #17 on: June 20, 2012, 09:41:46 PM »
That's because Awake() is called before Start().

Swap them.

luisdiv

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 32
    • View Profile
Re: Switch between SD and HD atlas with a script!
« Reply #18 on: June 21, 2012, 10:25:44 AM »
Works!  ;D

Thanks again!

harko12

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 8
    • View Profile
Re: Switch between SD and HD atlas with a script!
« Reply #19 on: August 28, 2012, 01:25:12 AM »
I had this same problem, and it turned out to be ( I think) because the material, texture and atlas are all named the same, and the .Load method can't figure out which one you want.  I used this code:

      IconAtlas = Resources.Load("Art Assets/Atlases/HackenSlash Icons", typeof(UIAtlas)) as UIAtlas;

and it loaded in correctly.

quischi

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1
    • View Profile
Re: Switch between SD and HD atlas with a script!
« Reply #20 on: March 14, 2014, 02:43:26 AM »
I had made this NGUI-Switch HD&SD (http://www.youtube.com/watch?v=ARfmGCMbJr8) tutorials and i don't how
can I implement the script from lusidiv in the tutorial. :'(

THX