Smooth rotation of unity window

Hello!

I would like to have smooth rotation of unity window, using stadard iOS fetures.

Here is what I did:

  1. create class inherited from UIViewController and override
    (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

  2. in method
    int OpenEAGL_UnityCallback(UIWindow** window, int* screenWidth, int* screenHeight, int* openglesVersion)
    replace first lines of code with

// Create a full-screen window
_window = [[UIWindow alloc] initWithFrame:CGRectMake(0, 0, 480, 320)];
EAGLView* view = [[EAGLView alloc] initWithFrame:CGRectMake(0, 0, 480, 320)];
RotationViewController * rotationCtrl = [[RotationViewController alloc] init];
[_window addSubview:rotationCtrl.view];
[rotationCtrl.view addSubview:view];

I got incorrect behaviour on device… Rotation is smoothed - but with bugs (view did not correspond to expected)

Question:

  • what should be done inside unity code?
    (now i am doing following in FixedUpdate()

if (iPhoneInput.orientation == iPhoneOrientation.LandscapeLeft
iPhoneSettings.screenOrientation != iPhoneScreenOrientation.LandscapeLeft)
{
iPhoneSettings.screenOrientation = iPhoneScreenOrientation.LandscapeLeft;
}
else if (iPhoneInput.orientation == iPhoneOrientation.LandscapeRight
iPhoneSettings.screenOrientation != iPhoneScreenOrientation.LandscapeRight)
{
iPhoneSettings.screenOrientation = iPhoneScreenOrientation.LandscapeRight;
}

)

  • what should be done in xCode?

Thanks!

I think unity developers should add such behavioud as DEFAULT in the xCode project

  • the smooth rotaion is very nice feature - donot skip it :slight_smile:

Regards,
Alex

Hi, I seem to have got this working and it was not necessary to modify appcontroller.mm at all! Make sure your Info.plist has UIInterfaceOrientation and UISupportedInterfaceOrientations filled in correctly. Here is my code,adapted from yours but turned into a coroutine and not using deprecated iPhoneInput members.

private IEnumerator UpdateIOSDeviceOrientation ()
	{
		while (true)
		{
			if (Input.deviceOrientation == DeviceOrientation.LandscapeLeft  
				iPhoneSettings.screenOrientation != iPhoneScreenOrientation.LandscapeLeft) 
			{
				Debug.Log (string.Format ("changing orientation {0} => {1}", 
					iPhoneSettings.screenOrientation,
					iPhoneScreenOrientation.LandscapeLeft));
				iPhoneSettings.screenOrientation = iPhoneScreenOrientation.LandscapeLeft;
			}
			else if (Input.deviceOrientation == DeviceOrientation.LandscapeRight 
				iPhoneSettings.screenOrientation != iPhoneScreenOrientation.LandscapeRight) 
			{
				Debug.Log (string.Format ("changing orientation {0} => {1}", 
					iPhoneSettings.screenOrientation, 
					iPhoneScreenOrientation.LandscapeRight));
				iPhoneSettings.screenOrientation = iPhoneScreenOrientation.LandscapeRight;
			}
			yield return new WaitForSeconds(0.2f);
		}
	}