关于打包之前Player设置中的一些问题:
Resolution and Presentation选项
Default Is Full Screen:勾选之后默认启动程序的是全屏模式,未勾选时下面的值为运行时默认的宽和高
Run In Background:是否后台运行(默认是不勾选,需要主动勾选)
Display Resolution Dialog:显示分辨率设置窗口
Disabled:不显示
Enabled:显示
Hidden by default:默认不显示,在游戏开始时按“Alt”可以显示
Resizable Window:可调整窗口大小(默认是不勾选,需要主动勾选)
Splash Image选项
Show Unity Splash Screen:是否显示官方启动画面
using UnityEngine;
public class Work : MonoBehaviour {
//设定屏幕分辨率的最大值和最小
const float resolutionMin = 2f / 3f;
const float resolutionMax = 16f / 9f;
void Update() {
//当前不是在全屏模式下设置屏幕分辨率
if (!Screen.fullScreen) {
ScreenSize();
}
}
void ScreenSize() {
//获取当前窗口的宽和高,并限制到当前显示器的最大值内
float width = Screen.width;
width = Mathf.Clamp(width, 1, Screen.currentResolution.width);
float height = Screen.height;
height = Mathf.Clamp(height, 1, Screen.currentResolution.height);
//得出当前窗口的分辨率
float resolutionNow = width / height;
if (resolutionNow > resolutionMax) {
//若当前分辨率大于设定的最大屏幕分辨率,则限定宽度的最大值
Screen.SetResolution((int)(height * resolutionMax), (int)(height), false);
}
else if (resolutionNow < resolutionMin) {
//若当前分辨率小于设定的最小屏幕分辨率,则限定高度的最大值
Screen.SetResolution((int)(width), (int)(width / resolutionMin), false);
}
}