gpt4 book ai didi

android - 统一设置显示分辨率限制

转载 作者:行者123 更新时间:2023-11-29 15:03:10 25 4
gpt4 key购买 nike

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

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

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

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

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

我认为它会阻止 FPS 下降。

最佳答案

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

如果您的游戏处于纵向模式,则使用 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;
}
}
}

关于android - 统一设置显示分辨率限制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41422601/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com