Unity iOS Vuforia 横竖屏切换摄像机镜像问题

问题:

unity iOS横屏时,主工程Portrait,unity工程AutoRotation,主工程打开unity后设置横屏方向会偶现出现摄像机翻转镜像问题。

unity iOS横竖屏切换时,主工程Portrait,unity工程AutoRotation,在手机设备iPhone 13Pro必现,横屏进入后在切换竖屏进入必镜像翻转。

原因:

在进入unity后,哪怕主工程设置正确的屏幕方向:Portrait和LandscapeLeft(iOS端设置朝右侧),但是进入unity后根据打印日志发现并不是正确的屏幕方向,会出现PortraitUpsideDown和LandscapeRight异常朝向方向。

解决方法:

Update监测横竖屏状态,强制翻转屏幕朝向。

cs 复制代码
    public bool isPortrait = true;
    public bool isCheck = true;
    private void UpdateRotate()
    {
        if(!isCheck) return;
        if (isPortrait && Screen.orientation != ScreenOrientation.Portrait)
        {
            Debug.Log($"ScreenManager::UpdateRotate - IOS端,竖屏但是监测到屏幕:{Screen.orientation}不是竖屏,强制翻转");
            Screen.orientation = ScreenOrientation.AutoRotation;
            Screen.autorotateToPortrait = true;
            Screen.autorotateToPortraitUpsideDown = false;
            Screen.autorotateToLandscapeRight = false;
            Screen.autorotateToLandscapeLeft = false;
            Screen.orientation = ScreenOrientation.Portrait;
        }
        else if (!isPortrait && Screen.orientation != ScreenOrientation.LandscapeLeft)
        {
            Debug.Log($"ScreenManager::UpdateRotate - IOS端,横屏但是监测到屏幕:{Screen.orientation}不是横屏,强制翻转");
            Screen.orientation = ScreenOrientation.AutoRotation;
            Screen.autorotateToPortrait = false;
            Screen.autorotateToPortraitUpsideDown = false;
            Screen.autorotateToLandscapeRight = false;
            Screen.autorotateToLandscapeLeft = true;
            Screen.orientation = ScreenOrientation.LandscapeLeft;
        }
    }

注意事项:

  1. iOS的左右朝向和Unity的左右朝向是相反的,Screen.orientation = ScreenOrientation.LandscapeLeft;相当于iOS的右侧。
  2. unity打包的工程设置为AutoRotation,并在unity启动成功后等待iOS发送过来横竖屏切换在设置,否则iOS主工程会报错,操作相同屏幕朝向参数异常。
  3. unity工程退出的时候,需要还原屏幕朝向,否则iOS主工程退出异常。
cs 复制代码
       Screen.orientation = ScreenOrientation.AutoRotation;
       Screen.autorotateToPortrait = true;
       Screen.autorotateToPortraitUpsideDown = true;
       Screen.autorotateToLandscapeRight = true;
       Screen.autorotateToLandscapeLeft = true;
相关推荐
AA陈超1 小时前
虚幻引擎5 GAS开发俯视角RPG游戏 P06-14 属性菜单 - 文本值行
c++·游戏·ue5·游戏引擎·虚幻
2501_916008894 小时前
Web 前端开发常用工具推荐与团队实践分享
android·前端·ios·小程序·uni-app·iphone·webview
2501_915921434 小时前
“HTTPS 个人化”实战,个人站点与设备调试的部署、验证与抓包排查方法
网络协议·http·ios·小程序·https·uni-app·iphone
future_studio6 小时前
聊聊 Unity(小白专享、C# 小程序 之 联机对战)
unity·小程序·c#
Digitally7 小时前
将联系人添加到iPhone的8种有效方法
ios·iphone
Digitally7 小时前
如何在没有 iCloud 的情况下备份 iPhone
ios·iphone·icloud
Dashing9 小时前
KN:Kotlin 与 OC 交互
ios·kotlin
黄毛火烧雪下10 小时前
创建一个ios小组件项目
ios
songgeb11 小时前
🧩 iOS DiffableDataSource 死锁问题记录
ios·swift
2501_9291576814 小时前
「IOS苹果游戏」600个
游戏·ios