设置统一显示分辨率限制
所以我几个月前发布了一款游戏。设置统一显示分辨率限制
我对家中添加的设备(galaxy note 2,galaxy tab pro,wiko)进行了大量测试,并且游戏在这些设备上顺利运行。
但是最后一天,我在LG G3设备上运行我的游戏,并且有很多FPS丢失。
我认为这是因为游戏以屏幕原始显示分辨率(2560 x 1440)运行。
是否有可能创建一个脚本,当它检测到高于FullHD的显示分辨率(如LG G3)时,它会以较低的分辨率显示游戏?
我认为这会阻止FPS下降。
调整相同的摄像头分辨率在每台设备上。
如果你的游戏是在肖像模式下,然后使用720 * 1280分辨率,如果使用横向模式使用960 * 640,你的游戏将在每个设备上运行完美。
- 附着脚本到您的相机
- 变化值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;
}
}
}
不是那么容易(具有良好的质量效果)。
基本上,你可以使用它的资产捆绑系统,并有SD和HD格式的图形的两倍。 Unity支持它,它称为变体。请在这里找到关于资产包的更多信息: https://unity3d.com/learn/tutorials/topics/scripting/assetbundles-and-assetbundle-manager
检测屏幕分辨率很容易。您可以使用Screen.width
和Screen.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
你知道吗,脚本不会更改分辨率? – Vancete
是的,但适用于不同的分辨率。它的编写为1280/720,但你可以看到它的规模较高和较低的分辨率相应的代码。 –
嘿,谢谢你的回答,但我不明白如果设备屏幕显示有QHD或4k屏幕,我怎么能缩小我的游戏的分辨率到全高清? (因为统一以屏幕显示分辨率运行游戏,并且如果设备具有2k或更多显示器,则功耗很高)。 –