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;
相关推荐
叽哥10 分钟前
flutter学习第 18 节:设备功能调用
android·flutter·ios
Swift社区6 小时前
Swift 实战:从数据流到不重叠区间的高效转换
开发语言·ios·swift
霜绛8 小时前
Unity:GUI笔记(一)——文本、按钮、多选框和单选框、输入框和拖动条、图片绘制和框绘制
笔记·学习·unity·游戏引擎
谷宇.10 小时前
【Unity3D实例-功能-移动】角色行走和奔跑的相互切换
游戏·unity·c#·unity3d·游戏开发·游戏编程
17岁的勇气11 小时前
Unity Shader unity文档学习笔记(十九):粘土效果,任意网格转化成一个球(顶点动画,曲面着色器)
笔记·学习·unity·图形渲染·顶点着色器·曲面着色器
benben0441 天前
《Unity Shader入门精要》学习笔记一
unity·shader
YF云飞1 天前
Unity图片优化与比例控制全攻略
游戏·unity·游戏引擎·游戏程序·个人开发
SmalBox1 天前
【渲染流水线】[几何阶段]-[几何着色]以UnityURP为例
unity·渲染
xixixin_1 天前
【H5】禁止IOS、安卓端长按的一些默认操作
android·css·ios·h5
叽哥1 天前
flutter学习第 17 节:项目实战:综合应用开发(下)
android·flutter·ios