统一设置显示分辨率限制

Set Display resolution limit in unity

所以我在几个月前发布了一个游戏。

我运行在我在家里添加的设备(galaxy note 2、galaxy tab pro、wiko)上进行了大量测试,游戏在这些设备上运行很流畅。

但最后一天,我 运行 我在 LG G3 设备上玩游戏,FPS 下降很多。

我认为这是因为游戏 运行 具有屏幕的原始显示分辨率 (2560 x 1440)。

是否可以创建一个脚本,当它检测到高于 FullHD 的显示分辨率(如 LG G3)时,它会以较低的分辨率显示游戏?

我认为它会阻止 FPS 下降。

没那么容易(质量很好)。

基本上,您可以为它使用资产包系统,并拥有标清和高清格式的双倍图形。 Unity支持它,它调用变体。请在此处找到有关资产包的更多信息: https://unity3d.com/learn/tutorials/topics/scripting/assetbundles-and-assetbundle-manager

屏幕分辨率的检测很容易。您可以使用 Screen.widthScreen.height

我知道 Screen class 有一个方法 SetResolution,这可能会在不使用 Asset Bundle 系统的情况下为您做一些事情。我从来没有单独使用过它。 以下是关于 Screen class 的更多信息: https://docs.unity3d.com/ScriptReference/Screen.html

具体SetResolution方法: https://docs.unity3d.com/ScriptReference/Screen.SetResolution.html

您也可以使用 Camera.aspect 来获取屏幕的纵横比: https://docs.unity3d.com/ScriptReference/Camera-aspect.html

在每个设备上调整相同的相机分辨率。

如果您的游戏处于纵向模式,则使用 720*1280 分辨率,如果使用横向模式,则使用 960*640,您的游戏将运行 在所有设备上完美运行。

  1. 将脚本附加到您的相机
  2. 更改值目标方面

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