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;
相关推荐
深海潜水员4 小时前
【Behavior Tree】-- 行为树AI逻辑实现- Unity 游戏引擎实现
游戏·unity·c#
AirDroid_cn7 小时前
OPPO手机怎样被其他手机远程控制?两台OPPO手机如何相互远程控制?
android·windows·ios·智能手机·iphone·远程工作·远程控制
杂雾无尘8 小时前
开发者必看,全面解析应用更新策略,让用户无法拒绝你的应用更新!
ios·xcode·swift
xiangzhihong810 小时前
使用Universal Links与Android App Links实现网页无缝跳转至应用
android·ios
Digitally12 小时前
如何将iPhone备份到Mac/MacBook
macos·ios·iphone
帅次12 小时前
【iOS设计模式】深入理解MVC架构 - 重构你的第一个App
ios·swiftui·objective-c·iphone·swift·safari·cocoapods
Thomas_YXQ14 小时前
Unity3D游戏内存优化指南
游戏·unity·职场和发展·性能优化·蓝桥杯·游戏引擎·unity3d
chillxiaohan14 小时前
Unity接入Steamworks.NET实现通信功能
unity
枯萎穿心攻击1 天前
响应式编程入门教程第二节:构建 ObservableProperty<T> — 封装 ReactiveProperty 的高级用法
开发语言·unity·c#·游戏引擎
Frank学习路上1 天前
【IOS】XCode创建firstapp并运行(成为IOS开发者)
开发语言·学习·ios·cocoa·xcode