收藏
回答

unity小游戏如何动态转屏?

框架类型 问题类型 API/组件名称 终端类型 微信版本 基础库版本
小游戏 Bug SetDeviceOrientation 工具 8.0.56 3.5.1

设置 启动竖屏的情况,通过调用 SetDeviceOrientation,动态转横屏会出现这样的效果。

设置 启动横屏的情况,通过调用 SetDeviceOrientation,动态转竖屏会出现这样的效果。

    public void SetLandscapeMode()
    {
        #if UNITY_WEBGL && !UNITY_EDITOR
        // 微信小游戏环境
        SetDeviceOrientationOption option = new SetDeviceOrientationOption
        {
            value = "landscape",
            success = (res) =>
            {
            },
            fail = (res) =>
            {
            }
        };
        WX.SetDeviceOrientation(option);
        #else
        Screen.orientation = ScreenOrientation.LandscapeLeft;
        #endif
        mainCanvasScaler.referenceResolution = new Vector2(1280, 720);
        mainCanvasScaler.matchWidthOrHeight = 1;
    }


    public void SetPortraitMode()
    {
        #if UNITY_WEBGL && !UNITY_EDITOR
        // 微信小游戏环境
        SetDeviceOrientationOption option = new SetDeviceOrientationOption
        {
            value = "portrait",
            success = (res) =>
            {
            },
            fail = (res) =>
            {
            }
        };
        WX.SetDeviceOrientation(option);
        #else
        Screen.orientation = ScreenOrientation.Portrait;
        #endif
        mainCanvasScaler.referenceResolution = new Vector2(720, 1280);
        mainCanvasScaler.matchWidthOrHeight = 0;
    }


以上的具体代码片段,是我的调用有问题还是微信小游戏unity插件的bug?

回答关注问题邀请回答
收藏

1 个回答

登录 后发表内容