整合的部分參見其他文章 iOS中Unity橫屏
有個(gè)問題一直沒有解決,就是使用AR功能時(shí),圖像有時(shí)候會(huì)顛倒,最近意外解決了
橫屏的方式仍然相同,主工程保持Portrait不變
在具體顯示Unity的頁面携御,添加橫屏代碼
override var shouldAutorotate: Bool{
return false
}
override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation{
return .landscapeRight
}
在UnityAppController.mm中
注釋以下三行代碼
- (void)applicationWillResignActive:(UIApplication*)application
{
::printf("-> applicationWillResignActive()\n");
if(_unityAppReady)
{
UnitySetPlayerFocus(0);
_wasPausedExternal = UnityIsPaused();
if (_wasPausedExternal == false)
{
// do pause unity only if we dont need special background processing
// otherwise batched player loop can be called to run user scripts
int bgBehavior = UnityGetAppBackgroundBehavior();
if(bgBehavior == appbgSuspend || bgBehavior == appbgExit)
{
// Force player to do one more frame, so scripts get a chance to render custom screen for minimized app in task manager.
// NB: UnityWillPause will schedule OnApplicationPause message, which will be sent normally inside repaint (unity player loop)
// NB: We will actually pause after the loop (when calling UnityPause).
UnityWillPause();
[self repaint];
UnityPause(1);
// _snapshotView = [self createSnapshotView];
// if(_snapshotView)
// [_rootView addSubview:_snapshotView];
}
}
}
_didResignActive = true;
}
就可以了,但支持向右橫屏,向左橫屏啄刹,圖像一直是顛倒的涮坐。