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;
相关推荐
平行云PVT2 小时前
数字孪生信创云渲染技术解析:从混合信创到全国产化架构
linux·unity·云原生·ue5·图形渲染·webgl·gpu算力
RickeyBoy4 小时前
解决 Swift Testing 中 DI 容器的竞态条件
ios
2501_915918416 小时前
苹果App Store上架审核卡住原因分析与解决方案指南
android·ios·小程序·https·uni-app·iphone·webview
开心就好20257 小时前
不依赖 Mac 也能做 iOS 开发?跨设备开发流程
后端·ios
小小数媒成员8 小时前
Unity的包含文件
unity·游戏引擎
开心就好20258 小时前
Windows 上传 IPA 到 App Store 的步骤讲解
后端·ios
mxwin10 小时前
Unity Shader 实战屏幕颜色抓取实现径向模糊 (URP)
unity·游戏引擎·shader·uv
for_ever_love__10 小时前
Objective- C学习: 手动内存管理
c语言·学习·ios·objective-c
林枫依依14 小时前
Unity2017 项目源码打开即崩溃,无法打开的解决办法
unity
wearegogog12314 小时前
ESP32迷你无人机开发代码详解
游戏引擎·无人机·cocos2d