2017-01-02 81 views
1

所以我幾個月前發佈了一款遊戲。設置統一顯示分辨率限制

我對家中添加的設備(galaxy note 2,galaxy tab pro,wiko)進行了大量測試,並且遊戲在這些設備上順利運行。

但是最後一天,我在LG G3設備上運行我的遊戲,並且有很多FPS丟失。

我認爲這是因爲遊戲以屏幕原始顯示分辨率(2560 x 1440)運行。

是否有可能創建一個腳本,當它檢測到高於FullHD的顯示分辨率(如LG G3)時,它會以較低的分辨率顯示遊戲?

我認爲這會阻止FPS下降。

回答

2

調整相同的攝像頭分辨率在每臺設備上。

如果你的遊戲是在肖像模式下,然後使用720 * 1280分辨率,如果使用橫向模式使用960 * 640,你的遊戲將在每個設備上運行完美。

  1. 附着腳本到您的相機
  2. 變化值targetaspect

using UnityEngine; 
using System.Collections; 

public class CameraResolution : MonoBehaviour { 

void Start() { 
    // set the desired aspect ratio (the values in this example are 
    // hard-coded for 16:9, but you could make them into public 
    // variables instead so you can set them at design time) 
    float targetaspect = 720.0f/1280.0f; 

    // determine the game window's current aspect ratio 
    float windowaspect = (float)Screen.width/(float)Screen.height; 

    // current viewport height should be scaled by this amount 
    float scaleheight = windowaspect/targetaspect; 

    // obtain camera component so we can modify its viewport 
    Camera camera = GetComponent<Camera>(); 

    // if scaled height is less than current height, add letterbox 
    if (scaleheight < 1.0f) { 
     Rect rect = camera.rect; 

     rect.width = 1.0f; 
     rect.height = scaleheight; 
     rect.x = 0; 
     rect.y = (1.0f - scaleheight)/2.0f; 

     camera.rect = rect; 
    } else { // add pillarbox 
     float scalewidth = 1.0f/scaleheight; 

     Rect rect = camera.rect; 

     rect.width = scalewidth; 
     rect.height = 1.0f; 
     rect.x = (1.0f - scalewidth)/2.0f; 
     rect.y = 0; 

     camera.rect = rect; 
    } 
    } 
} 
+0

你知道嗎,腳本不會更改分辨率? – Vancete

+0

是的,但適用於不同的分辨率。它的編寫爲1280/720,但你可以看到它的規模較高和較低的分辨率相應的代碼。 –

+0

嘿,謝謝你的回答,但我不明白如果設備屏幕顯示有QHD或4k屏幕,我怎麼能縮小我的遊戲的分辨率到全高清? (因爲統一以屏幕顯示分辨率運行遊戲,並且如果設備具有2k或更多顯示器,則功耗很高)。 –

1

不是那麼容易(具有良好的質量效果)。

基本上,你可以使用它的資產捆綁系統,並有SD和HD格式的圖形的兩倍。 Unity支持它,它稱爲變體。請在這裏找到關於資產包的更多信息: https://unity3d.com/learn/tutorials/topics/scripting/assetbundles-and-assetbundle-manager

檢測屏幕分辨率很容易。您可以使用Screen.widthScreen.height

我知道Screen類有一個方法SetResolution,這可能會爲你做一件事情,而不使用資產捆綁系統。我從來沒有使用過它。 這裏更多的是Screen類: https://docs.unity3d.com/ScriptReference/Screen.html

和混凝土SetResolution方法: https://docs.unity3d.com/ScriptReference/Screen.SetResolution.html

您可以使用​​得到屏幕的長寬比以及: https://docs.unity3d.com/ScriptReference/Camera-aspect.html