簡體   English   中英

如何使用自定義縱橫比統一構建項目?

[英]How to build project in unity with custom aspect ratio?

我有一個使用9:16 縱橫比的游戲項目。 還有將“隨屏幕尺寸縮放”和“參考分辨率” 1080x1920 (9:16) 的畫布

當我構建項目並在“播放器設置”中進行一些設置時,如下所示:
播放器設置

游戲的結果是建立起來的,總是只使用“自由縱橫比”。 像這樣:

所有游戲組件,應與背景相配

如何僅使用我想要的縱橫比來構建項目?

謝謝

我也無法在獨立版本中獲得自定義縱橫比。

您可以在 start 方法中手動設置一次屏幕寬度和高度。

void Start()
{
    Screen.SetResolution(1080, 1920);
}

如果需要,您也可以在游戲運行時更新它

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;
}

統一文檔:
屏幕
設置分辨率()

void Start()
{
    SetRatio(3, 4);
}
void SetRatio(float w, float h)
{
    if ((((float)Screen.width) / ((float)Screen.height)) > w / h)
    {
        Screen.SetResolution((int)(((float)Screen.height) * (w / h)), Screen.height, true);
    }
    else
    {
        Screen.SetResolution(Screen.width, (int)(((float)Screen.width) * (h / w)), true);
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM