Author Topic: iPhone 5 Height and different aspect ratio  (Read 22098 times)

mdeletrain

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 71
    • View Profile
Re: iPhone 5 Height and different aspect ratio
« Reply #15 on: October 11, 2012, 04:42:03 AM »
Sure ! :p

mdeletrain

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 71
    • View Profile
Re: iPhone 5 Height and different aspect ratio
« Reply #16 on: October 15, 2012, 09:51:18 AM »
Reminder !!  :D

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: iPhone 5 Height and different aspect ratio
« Reply #17 on: October 15, 2012, 01:51:32 PM »
*looks around for a snooze button* <_<

gamesonytablet

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 13
    • View Profile
Re: iPhone 5 Height and different aspect ratio
« Reply #18 on: October 19, 2012, 11:33:34 AM »
Hi, any progress on this? I vote +1 for this to be released on the next version ;)

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: iPhone 5 Height and different aspect ratio
« Reply #19 on: October 19, 2012, 12:56:38 PM »
You can calculate this yourself and set an appropriate manual height which will scale with width to fit the design from iphone 4.


gamesonytablet

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 13
    • View Profile
Re: iPhone 5 Height and different aspect ratio
« Reply #20 on: October 20, 2012, 08:04:42 PM »
Sure, manually adjusting height is feasible, and maybe the right solution in most cases.

Though, a friend of mine Udasan has created a short C# code snippet to automatically adjust to either height or width.
(original code is published on his website, and he agreed to share the snippet here below. No liability for usage, and etc. ;))

If you attach this NGUIUtilScalableUIRoot script to UIRoot, it will adjust to either height or width as the attached screen shots.

In any way, it would be great to see this "automatic adjustment" functionality included in further versions of NGUI, as already discussed to make sense. Will this happen?

  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. [ExecuteInEditMode]
  5. public class NGUIUtilScalableUIRoot : MonoBehaviour
  6. {
  7.  public int manualWidth = 320;
  8.  public int manualHeight = 240;
  9.  
  10.  UIRoot uiRoot_;
  11.  
  12.  void Awake()
  13.  {
  14.   uiRoot_ = GetComponent<UIRoot>();
  15.  }
  16.  
  17.  void Update ()
  18.  {
  19.   if(!uiRoot_ || manualWidth <= 0 || manualHeight <= 0){ return; }
  20.    
  21.   int h = manualHeight;
  22.   float r = (float)(Screen.height * manualWidth) / (Screen.width * manualHeight); // (Screen.height / manualHeight) / (Screen.width / manualWidth)
  23.   if(r  > 1){ h = (int)(h * r); } // to pretend target height is more high, because screen width is too smaller to show all UI
  24.    
  25.   if(uiRoot_.automatic){ uiRoot_.automatic = false; }
  26.   if(uiRoot_.manualHeight != h){ uiRoot_.manualHeight = h; }
  27.  }
  28. }

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: iPhone 5 Height and different aspect ratio
« Reply #21 on: October 20, 2012, 09:18:40 PM »
You will see it in the next update, when I push it out.

gamesonytablet

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 13
    • View Profile
Re: iPhone 5 Height and different aspect ratio
« Reply #22 on: November 16, 2012, 11:51:27 AM »
Hi,

I saw an update in 2.2.5 version of the automatic mode, but was not sure if this was the solution to this topic:

- FIX: UIRoot will now only consider min/max clamping in automatic mode.

Please correct me if I'm wrong, but I thought the discussion in this thread was about adding a Width parameter as well.
Was this update due to a different reason? ... Just not sure :-[

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: iPhone 5 Height and different aspect ratio
« Reply #23 on: November 16, 2012, 05:41:24 PM »
It was indeed, and I added it at first, but it was... messy, for the lack of a better word. It involved adjustments to activeHeight and pixelSizeAdjustments properties, and made things quite confusing, so I chose to remove it and look for a more elegant approach. For now, I suggest sticking to that helper script.

favoyang

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 14
    • View Profile
Re: iPhone 5 Height and different aspect ratio
« Reply #24 on: January 15, 2013, 10:10:55 AM »
I have similar issue that the game is original designed on 3:2 screen, then need support 16:9 aspect ratio for iPhone5, 4:3 ratio for iPad. My approach is that 1) keep 3:2 as default design ratio which is the mid aspect ratio of [1.33, 1.5, 1.75], 2) use UIAnchor to adjust UI to stick to edge. However, sometime the 16:9 ratio is too taller / narrower that some UI get cropped.

So I use below script to adjust UIRoot.manualHeight to make it UIRoot follow manualWidth instead of manualHeight. For example, if pick 3:2 as default ratio, UIRoot.manualHeight = 960. Then you need set manualWidth to 640. During runtime, the script will change UIRoot.manualHeight to 1136 on iPhone5, so the width will be 640 as expected.

  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. // The script make UIRoot scale based on manualWidth instead of UIRoot.manualHeight.
  5. // if current aspect ratio > maxAcceptAspectRatio.
  6. [RequireComponent(typeof(UIRoot))]
  7. public class UIRootHelper : MonoBehaviour {
  8.  
  9.     UIRoot uiRoot;
  10.     public int manualWidth;
  11.     public float maxAcceptAspectRatio = 1.67f;
  12.  
  13.     void Awake() {
  14.         uiRoot = GetComponent<UIRoot>();
  15.     }
  16.  
  17.     void OnEnable() {
  18.         UpdateHeight();
  19.     }
  20.  
  21.     void UpdateHeight() {
  22.         float aspect = (float)Screen.height / Screen.width;
  23.         if (aspect > maxAcceptAspectRatio) {
  24.             // Change manualHeight to simulate scale based on manualWidth.
  25.             int manualHeight = (int)(manualWidth * aspect);
  26.             if (uiRoot.manualHeight != manualHeight)
  27.                 uiRoot.manualHeight = manualHeight;
  28.         }
  29.     }
  30. }
  31.