Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: DZP on June 27, 2014, 04:27:54 AM

Title: Buttons become unresponsive when programmatically changing screen orientation
Post by: DZP on June 27, 2014, 04:27:54 AM
Hey,

I'm on NGUI 3.5.5 with Unity 4.5.1 (EDITED FROM 5.1  ::) ) and I'm trying to programmatically change the screen orientation of my iOS device (iPad iOS 7.1) for different parts of my game. The buttons are responsive and work until I change the orientation using for example
  1. Screen.orientation = ScreenOrientation.Portrait;

The buttons work with the rotation on Android (tested on a Nexus 5 4.2.2).

Once I do that, the buttons can no longer be clicked. I see the code in UICamera for detecting screen changes gets executed, so the UIAnchors must be getting updated as well. What could be preventing my buttons from being responsive again?

Thanks.
Title: Re: Buttons become unresponsive when programmatically changing screen orientation
Post by: ArenMook on June 27, 2014, 01:31:36 PM
Unity 5.1? Can I have a copy? I've always wanted to have something from 2 years in the future. :)

Your NGUI is quite a bit out of date, so I would start by updating to the latest version. After that, enable the Debug option on the UICamera so that you can see what the touch is interacting with. Beyond that, I'm not sure -- you will need to add some Debug.Logs there. I suggest covering your entire screen with a big collider and logging the UICamera.lastTouchPosition via NGUIDebug.Log in OnDrag.
Title: Re: Buttons become unresponsive when programmatically changing screen orientation
Post by: DZP on June 30, 2014, 02:32:22 AM
Unity 5.1? Can I have a copy? I've always wanted to have something from 2 years in the future. :)

Your NGUI is quite a bit out of date, so I would start by updating to the latest version. After that, enable the Debug option on the UICamera so that you can see what the touch is interacting with. Beyond that, I'm not sure -- you will need to add some Debug.Logs there. I suggest covering your entire screen with a big collider and logging the UICamera.lastTouchPosition via NGUIDebug.Log in OnDrag.

Ha! I wish :(

I did as you asked after updating and was able to see the touch locations prior to the orientation change, but as soon as the orientation changed then the huge collider I put in the background to receive the touches no longer did anything. That was on iOS. On Android the huge collider continued to spit out values for me after the orientation change.
Title: Re: Buttons become unresponsive when programmatically changing screen orientation
Post by: ArenMook on July 01, 2014, 03:04:29 AM
Well, from NGUI's point of view, all it does is performs a raycast into the screen using physics (2D or 3D, depending on your UI type). Have you tried switching your UI colliders from 2D to 3D or vice versa via NGUI -> Extras menu? (make sure you have the latest NGUI first)
Title: Re: Buttons become unresponsive when programmatically changing screen orientation
Post by: bfriedman on July 02, 2014, 02:36:51 PM
FYI, I have this exact problem as well.  Unity 4.5.1p3,  NGUI just updated via asset store, so I guess 3.6.6?  In my case, NGUI works perfectly fine letting Unity auto-rotate the GUI.  But when I programmatically change to:

  1.                 Screen.orientation = ScreenOrientation.Landscape;

During normal user input handling, I get no more events from the UICamera when running in iOS.

So NGUI updates the layout to the new orientation.  But events stop flowing to it.  I do get them when running in Android.  Everything seems fine there.

Anecdotally, the gyro input that I'm running in parallel (outside of the NGUI system) continues to work fine.  So Unity itself isn't frozen.  It's just the UI events that are not flowing.

I'm about to dig into this.  But thought I'd confirm it as best I can.
Title: Re: Buttons become unresponsive when programmatically changing screen orientation
Post by: bfriedman on July 02, 2014, 03:47:20 PM
So upon doing some debugging on the device (iPad), I find that after the screen rotation, Unity is reporting touch positions as negative in x.  If I break inside UICamera.ProcessTouhces and look at the touch returned by calling Unity's "Input.GetTouch(i)", and watch it's position and rawPosition fields, I get negatives.  Which I believe is a Unity bug.  Though I suppose it could instead be intended behavior I don't understand.  I'll be moving investigation in that direction.

Anyhow, as far as NGUI goes:  Later on in NGUI's logic, it skips touches outside the 0-1 range.  Which is correct behavior I believe.
Title: Re: Buttons become unresponsive when programmatically changing screen orientation
Post by: bfriedman on July 02, 2014, 04:24:35 PM
I've isolated the problem as a unity issue and built a test project to show it.  I submitted it to Unity as a bug.  Will update if I get a tracking number or response.

-brad
Title: Re: Buttons become unresponsive when programmatically changing screen orientation
Post by: bfriedman on July 02, 2014, 05:11:03 PM
FYI a workaround for me is to toggle between this two modes:

  1.                 Screen.orientation = Screen.orientation;
and
  1.                 Screen.orientation = ScreenOrientation.AutoRotation;

That moves between freezing the orientation, and setting back to auto.  That may not work for everyone.  My particular use-case simply requires temporarily disabling auto-rotation while my gyro mode is active.  I don't care if it's in portrait or landscape when that happens.  Then I restore it to auto when my gyro mode is deactivated.

Whatever is wrong with Unity's orientation changing logic, moving between these two modes doesn't cause errant behavior at least.
Title: Re: Buttons become unresponsive when programmatically changing screen orientation
Post by: fanling3 on July 03, 2014, 01:27:38 AM
I can confirm that my game has the same problem on iOS (no problem on Android).
I felt strange that a number of people wrote reviews on app store reporting they are unable to play my game and gave my game 1 star, and my colleague accidently discover that it is caused by rotating the device to another orientation
Title: Re: Buttons become unresponsive when programmatically changing screen orientation
Post by: ArenMook on July 03, 2014, 05:07:43 AM
Thanks for investigating it bfriedman, and for submitting a bug to Unity to boot.
Title: Re: Buttons become unresponsive when programmatically changing screen orientation
Post by: DZP on July 15, 2014, 05:05:07 AM
Thanks bfriedman, your solution works for me. It sucks that I have to give the device a jiggle before the device auto rotates, but it is better than nothing until a solution is found!
Title: Re: Buttons become unresponsive when programmatically changing screen orientation
Post by: morgue on August 01, 2014, 03:04:28 PM
Apparently this has been fixed for Unity 4.3 (not yet available at the time of this posting).

I want it now :(
Title: Re: Buttons become unresponsive when programmatically changing screen orientation
Post by: garing on August 07, 2014, 11:23:27 AM
For those still struggling with this issue, the bug was fixed in 4.5.2p3, available here: http://forum.unity3d.com/threads/unity-patch-releases.246198/#post-1718700
Title: Re: Buttons become unresponsive when programmatically changing screen orientation
Post by: huixiong on November 27, 2014, 05:06:55 AM
FYI a workaround for me is to toggle between this two modes:

  1.                 Screen.orientation = Screen.orientation;
and
  1.                 Screen.orientation = ScreenOrientation.AutoRotation;

That moves between freezing the orientation, and setting back to auto.  That may not work for everyone.  My particular use-case simply requires temporarily disabling auto-rotation while my gyro mode is active.  I don't care if it's in portrait or landscape when that happens.  Then I restore it to auto when my gyro mode is deactivated.

Whatever is wrong with Unity's orientation changing logic, moving between these two modes doesn't cause errant behavior at least.

我是Unity4.5.5,当我在IOS平台调用相册,这时候游戏并未进入后台,切换回来后屏幕就不能点击了