如何使用自定义纵横比统一构建项目?

Yun*_*dil 5 c# unity-game-engine

我有一个使用9:16 纵横比的游戏项目。还有将“随屏幕尺寸缩放”和“参考分辨率” 1080x1920 (9:16) 的画布

当我构建项目并在“播放器设置”中进行一些设置时,如下所示:
播放器设置

游戏的结果是建立起来的,总是只使用“自由纵横比”。像这样:

所有游戏组件,应与背景相配

如何仅使用我想要的纵横比来构建项目?

谢谢

Sav*_*ria 4

我在独立构建中也无法获得自定义纵横比。

您可以在启动方法中手动设置屏幕宽度和高度。

void Start()
{
    Screen.SetResolution(1080, 1920);
}
Run Code Online (Sandbox Code Playgroud)

如果需要,您也可以在游戏运行时更新它

private float lastWidth;
private float lastHeight;

void Update()
{
    if(lastWidth != Screen.width)
    {
        Screen.SetResolution(Screen.width, Screen.width * (16f / 9f));
    }
    else if(lastHeight != Screen.height)
    {
        Screen.SetResolution(Screen.height * (9f / 16f), Screen.height);
    }

    lastWidth = Screen.width;
    lastHeight = Screen.height;
}
Run Code Online (Sandbox Code Playgroud)

Unity 文档:
屏幕
SetResolution()