Screen.SetResolution 设置分辨率
static function SetResolution (width : int, height : int, fullscreen : bool, preferredRefreshRate : int = 0) : void
Description描述
Switches the screen resolution.
切换屏幕分辨率。
A width by height resolution will be used. If no matching resolution is supported, the closest one will be used.
一个有宽高的分辨率被使用,如果没有匹配的分辨率被支持,将使用最接近的分辨率。
If preferredRefreshRate is 0 (default) Unity will switch to the highest refresh rate supported by the monitor. If preferredRefreshRate is not 0 Unity will use it if the monitor supports it, otherwise will choose the highest supported one.
如果preferredRefreshRate为0(默认),Unity将切换到显示器支持的最高刷新率。如果preferredRefreshRate不是0,如果显示器支持,Unity将使用它,否则将选择支持的最高的一个。
In the web player you may only switch resolutions after the user has clicked on the content. The recommended way of doing it is to switch resolutions only when the user clicks on a designated button.
在网络播放器,你只可以在用户点击内容之后切换分辨率。推荐的方法是只在用户点击一个指定的按钮时切换分辨率。
A resolution switch does not happen immediately; it will actually happen when the current frame is finished.
全屏开关不会立即发生,它实际发生是在当前帧完成时。
using UnityEngine;
using System.Collections;
public class example : MonoBehaviour {
public void Awake() {
Screen.SetResolution(640, 480, true);
}
}
// Switch to 640 x 480 fullscreen
//切换到640 x 480全屏
Screen.SetResolution (640, 480, true);
另一个例子:
using UnityEngine;
using System.Collections;
public class example : MonoBehaviour {
public void Awake() {
Screen.SetResolution(640, 480, true, 60);
}
}
// Switch to 640 x 480 fullscreen at 60 hz
//切换到640 x 480全屏,刷新率为60赫兹
Screen.SetResolution (640, 480, true, 60);
另一个例子:
using UnityEngine;
using System.Collections;
public class example : MonoBehaviour {
public void Awake() {
Screen.SetResolution(800, 600, false);
}
}
// Switch to 800 x 600 windowed
//切换到800 x 600窗口模式
Screen.SetResolution (800, 600, false);
参考: resolutions 属性.