Author Topic: NGUI with different orientations [SOLVED]  (Read 8103 times)

ivomarel

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 53
    • View Profile
NGUI with different orientations [SOLVED]
« on: March 11, 2013, 02:46:14 AM »
Hey there!

I am currently developing a game for iOS which requires me to have portrait-menu and a landscape-game. I know how to change this in code, but I'm actually trying to create the game NGUI menu now and I'm not sure what the best approach is, since I'm using Anchors in both orientations. Should I create 2 UI-Roots?

Cheers,

Ivo
« Last Edit: March 12, 2013, 04:26:19 AM by ivomarel »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI with different orientations
« Reply #1 on: March 11, 2013, 09:21:14 AM »
Anchors should work just fine as-is.

ivomarel

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 53
    • View Profile
Re: NGUI with different orientations
« Reply #2 on: March 12, 2013, 12:43:41 AM »
Hey ArenMook,

Thanks for the quick response.

I haven't made myself very clear I'm afraid. I am using some NGUI-buttons which are anchored from top-right, which works fine in portrait mode. However, since my gamescreen (same UnityScene) is oriented to landscape, I want those anchors to have their offset from what the top-right would be in landscape.

I am looking for an option (like a bool) which enables me to use NGUI's WYSIWYG with Anchors, when one screen is oriented to portrait and the other screen is oriented to landscape.

I am trying to figure it out myself as well and will let you know if I do.

Cheers,

Ivo

ivomarel

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 53
    • View Profile
Re: NGUI with different orientations
« Reply #3 on: March 12, 2013, 04:24:08 AM »
Hello ArenMook (& others)

As usual, it wasn't that hard to figure out after all. The problem was actually the UIRoot manual height, which was manually set to 1136 (iPhone 5), which is good for portrait, but for landscape the height should actually be 640. I was looking in UIPanel and UIAnchor before, but it turned out to be as simple as adding this to my GUIManager-class:

  1.                
  2.                 UIRoot root = NGUITools.FindInParents<UIRoot>(gameObject);
  3.  
  4.                 if (menuName == "InGame") {
  5.                         root.manualHeight = 640;
  6.                         Screen.autorotateToPortrait = false;
  7.                         Screen.autorotateToPortraitUpsideDown = false;
  8.                         Screen.orientation  = ScreenOrientation.Landscape;
  9.                         Screen.autorotateToLandscapeLeft = true;
  10.                         Screen.autorotateToLandscapeRight = true;      
  11.                 } else {
  12.                         root.manualHeight = 1136;
  13.                         Screen.autorotateToLandscapeLeft = false;
  14.                         Screen.autorotateToLandscapeRight = false;
  15.                         Screen.orientation  = ScreenOrientation.Portrait;
  16.                         Screen.autorotateToPortrait = true;
  17.                         Screen.autorotateToPortraitUpsideDown = true;
  18.                 }
  19.  

Little FYI (has nothing to do with NGUI), I had to add this to my update-class.

  1. Screen.orientation  = ScreenOrientation.AutoRotation;

Why? Because if I didn't do it, it wouldn't be on AutoRotation and even though I set autorotateToPortraitUpsideDown to true, it will just stay in the previously set ScreenOrientation.Portrait . However, I had to set ScreenOrientation.Portrait once, otherwise it would still be in ScreenOrientation.Landscape if I came from the game-screen, until I rotated my phone another 90 degrees.

Although I've had way more frustrating bugs, I hope others won't have to deal with my problems.