Author Topic: Universal SD / HD Switching for iOS (iPad / iPhone) - Refresh problem  (Read 18632 times)

iandunlop_oefun

  • Guest
Hi,

First of all I'm new to NGUI so perhaps I'm missing some step. I've reviewed the docs, video and several posts on this issue but none seem to have the issue I have.

I have a button and a group of radio buttons (under the UIRoot / Camera / Anchor / Panel) as well as a couple of labels.

Setup:
- game reference atlas prefab
- font reference prefab
- iPad HD game atlas (and font) prefabs (pixel size set to 1.0)
- iPhone HD game atlas (and font) prefabs (pixel size set to 2.0)
- UIRoot (auto off and set to manual height of 1536)
- UIRoot has a atlas change script, on Awake() it swaps the atlas references to point to the appropriate iPad / iPhone selection (uses the .replacement property as mentioned in other threads)
- UI elements all point to the reference atlas / font
- Note: both the iPad and iPhone atlases use the exact same art / names. There is no change in the actual size. I'm using a different atlas so I can set the pixel size on the atlas. (Perhaps there is a better way to handle this?)

1. I select the 960x640 rez and run the app in the editor.

2. When I run the app, the script correctly switches my atlas and font references over to the iPhone atlas.

3. However when I view the screen, they are the wrong size. They are still accessing the iPad atlas.

4. If I mouse/hover over the button or touch the button it will "pop" to a larger size. I'm assuming this is now displaying the correct sprite from the iPhone atlas. Once the button has refreshed it's forever at the larger size (expected).

5. My radio button group does not exhibit this behavior. They stay at the iPad size.


I was expecting that when viewing at 960x640 all the buttons would appear twice as large. But this does not happen. Does anyone have any ideas?


Cheers,
   Ian Dunlop



Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Is the panel marked as static?

loopyllama

  • Guest
At least one problem you have is the UIRoot manual height. It needs to be set to the height of the screen resolution...so on iphone HD it needs to be either 960 or 640, depending on your app being landscape or portrait.

iandunlop_oefun

  • Guest
Is the panel marked as static?

I assume you're referring to the 'Check if widgets won't move' on the UIPanel - this is unchecked.

iandunlop_oefun

  • Guest
At least one problem you have is the UIRoot manual height. It needs to be set to the height of the screen resolution...so on iphone HD it needs to be either 960 or 640, depending on your app being landscape or portrait.

My app is landscape. I did experiment setting this to 640 and it does increase the size of the buttons etc. However, I don't see how this would work properly given the pixel size property on the atlas. There is still a refresh issue. When I mouse hover over or touch the button it doubles in size (so it's now approx. x4 larger than the iPad version).

loopyllama

  • Guest
Maybe it is a refresh problem, but that can not be certain until all other things are correct. You definitely need to set the manual height to 640 for the iphone. Also your pixel size is wrong. Did you set up your ref atlas using the iPad hd resolution? If so, your pixel size needs to be iPad hd height / 640 for your iPhone hd atlas instead of 2.0

iandunlop_oefun

  • Guest
Maybe it is a refresh problem, but that can not be certain until all other things are correct. You definitely need to set the manual height to 640 for the iphone. Also your pixel size is wrong. Did you set up your ref atlas using the iPad hd resolution? If so, your pixel size needs to be iPad hd height / 640 for your iPhone hd atlas instead of 2.0

The app was / is setup as a manual height of 1536 and using the iPad HD atlases (referenced by the main atlas / font reference).

It shouldn't make any difference what I set the pixel size to. It's a multiplier so the view should adjust as needed. For a test I set the manual height and pixel size as you state above. The view initially presents as "double" the size (due to the 1536 / 640). However, I still get the same refresh issue. When I hover / touch the button it expands to x2 the size so I end up with approx. x4 the iPad size.

The manual height settings works as advertised. The switching of the atlases is also working, but the effect doesn't occur for anything. The exception to this case is when I hover or touch the button. Then it "pops" to "double" the size.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
After changing your reference atlas, try this:

NGUITools.Broadcast("MarkAsChanged");

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Btw, there is a bug in Unity in regards to Awake() execution, my guess is you're running into it here.

Your Awake() function is getting called after OnEnable() of others unless you add an empty OnEnable() function to your script.

iandunlop_oefun

  • Guest
After changing your reference atlas, try this:

NGUITools.Broadcast("MarkAsChanged");

I tried this. It made no difference - same refresh problem still exists.

iandunlop_oefun

  • Guest
Btw, there is a bug in Unity in regards to Awake() execution, my guess is you're running into it here.

Your Awake() function is getting called after OnEnable() of others unless you add an empty OnEnable() function to your script.

Interesting - thanks for the tip. However, I tried it and it made no difference. Same refresh issue still exists.

What about the script execution order feature in Unity - is there a particular order that would work here?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Your atlas replacement script should run first.

iandunlop_oefun

  • Guest
Your atlas replacement script should run first.

I set my script to -500 (which is before everything in the script execution order list). The issue still persists.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
One other thing you can try is have your atlas get switched in a different scene (usually the load scene), that will then load your actual scene.

iandunlop_oefun

  • Guest
One other thing you can try is have your atlas get switched in a different scene (usually the load scene), that will then load your actual scene.

I think I can safely say this problem is not an order of execution issue. I just tried this and it did not fix the issue. It's appears to be an update issue. For some reason the button draws with the iPad atlas and only reflects the replaced (replacement) iPhone atlas when I hover or touch the button.

Can you offer some insight into how the pixel size property is used on startup? (FWIW, my atlases are for iPhone and iPad are identical.)