Author Topic: Suggestion for UIRoot : "virtual screen size"  (Read 2049 times)

nah0y

  • Sr. Member
  • ****
  • Thank You
  • -Given: 1
  • -Receive: 2
  • Posts: 430
  • \o/
    • View Profile
Suggestion for UIRoot : "virtual screen size"
« on: October 04, 2012, 09:32:52 AM »
Hi,

I often need to have the "virtual screen size" of the device when I set my UIRoot to be non automatic and set it's size manually.

I'm building all my UI based on an iPad screen size, so I set the UIRoot manual height to 768.
And my screen size is then 1024x768.

If I switch to an iPhone screen size, the screen size is 960x640, but as the UIRoot is manual, the height of my UI is 768.
That also mean that the screen size 960x640 for my UI is not true, and I have to do some calculation to have the width depending on this 768 height (this is : 960x768/640 = 1152px).

Now, what I'm asking is to have two static attributes to UIRoot such as :
public static int virtualScreenWidth;
public static int virtualScreenHeight;

And in the Start or Awake of the script, just do :
virtualScreenHeight = activeHeight
virtualScreenWidth = Screen.width * pixelSizeAdjustement

So we can retrieve easily the UI screen width and height.

What do you think ?

nah0y

  • Sr. Member
  • ****
  • Thank You
  • -Given: 1
  • -Receive: 2
  • Posts: 430
  • \o/
    • View Profile
Re: Suggestion for UIRoot : "virtual screen size"
« Reply #1 on: October 18, 2012, 05:42:13 AM »
A little UP for this one :)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Suggestion for UIRoot : "virtual screen size"
« Reply #2 on: October 18, 2012, 02:23:34 PM »
This implies having to have a reference to your UIRoot somewhere.

I recommend creating a singleton manager for your game where you can put such helper functions. In Windward I have a few of them -- one for game settings, one for game-related prefabs, and another for audio.

nah0y

  • Sr. Member
  • ****
  • Thank You
  • -Given: 1
  • -Receive: 2
  • Posts: 430
  • \o/
    • View Profile
Re: Suggestion for UIRoot : "virtual screen size"
« Reply #3 on: October 18, 2012, 02:48:16 PM »
Hum, why a reference to the UIRoot ?
Every NGUI interface need a UIRoot, so we can just make a static field inside the UIRoot, no ?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Suggestion for UIRoot : "virtual screen size"
« Reply #4 on: October 18, 2012, 03:11:34 PM »
UIRoot is completely optional, and there can be more than one.