Author Topic: Resolution change not recognized on mobile devices  (Read 2944 times)

Asse

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 70
    • View Profile
Resolution change not recognized on mobile devices
« on: June 08, 2012, 05:08:26 AM »
Hey,

Sometimes I have problems with the resolution on mobile devices. When UIRoot.automatic is set to true it keeps the old manualHeight.

What I've noticed also in other projects, is that Mathf.Approximately isn't very accurate on mobile devices. So when I change to following code in UIRoot from

  1. void Update ()
  2. {
  3.         manualHeight = Mathf.Max(2, automatic ? Screen.height : manualHeight);
  4.  
  5.         float size = 2f / manualHeight;
  6.         Vector3 ls = mTrans.localScale;
  7.  
  8.         if (!Mathf.Approximately(ls.x, size) ||
  9.                 !Mathf.Approximately(ls.y, size) ||
  10.                 !Mathf.Approximately(ls.z, size))
  11.         {
  12.                 mTrans.localScale = new Vector3(size, size, size);
  13.         }
  14. }

to

  1. void Update ()
  2. {
  3.         manualHeight = Mathf.Max(2, automatic ? Screen.height : manualHeight);
  4.  
  5.         float size = 2f / manualHeight;
  6.         Vector3 ls = mTrans.localScale;
  7.  
  8.         if( !(Mathf.Abs( ls.x - size ) <= float.Epsilon ) ||
  9.                 !(Mathf.Abs( ls.y - size ) <= float.Epsilon ) ||
  10.                 !(Mathf.Abs( ls.z - size ) <= float.Epsilon ))
  11.         {
  12.                 mTrans.localScale = new Vector3(size, size, size);
  13.         }
  14. }

everything works like a charm.

Anybody else can confirm this?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Resolution change not recognized on mobile devices
« Reply #1 on: June 08, 2012, 01:48:32 PM »
Seems harmless enough.