U1L9——Screen屏幕相关
Screen
访问显示信息。Screen 类可用于获取支持的分辨率列表、切换当前分辨率、 隐藏或显示系统鼠标指针。
本章代码关键字
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| Resolution .wideh .height Screen.currentResolution Screen.width Screen.height Screen.sleepTimeout SleepTimeout.NeverSleep SleepTimeout.SystemSetting Screen.fullScreen Screen.fullScreenMode FullScreenMode.ExclusiveFullScreen FullScreenMode.FullScreenWindow FullScreenMode.MaximizedWindow FullScreenMode.Windowed Screen.autorotateToLandscapeLeft Screen.autorotateToLandscapeRight Screen.autorotateToPortrait Screen.autorotateToPortraitUpsideDown Screen.orientation ScreenOrientation Screen.SetResolution(, , )
|
静态属性
当前屏幕分辨率
1 2 3
| Resolution r = Screen.currentResolution; print("当前屏幕分辨率的宽" + r.width + "高" + r.height);
|
屏幕窗口当前宽高
这里得到的是 当前窗口的宽高 不是设备分辨率的宽高
一般写代码要用窗口宽高 做计算时就用它们
1 2
| print(Screen.width); print(Screen.height);
|
屏幕休眠模式
1 2
| Screen.sleepTimeout = SleepTimeout.SystemSetting; Screen.sleppTImeout = SleepTimeout.NeverSleep
|
运行时是否全屏模式
1
| Screen.fullScreen = true;
|
窗口模式
有四种模式:
- 独占全屏:
FullScreenMode.ExclusiveFullScreen
- 全屏窗口:
FullScreenMode.FullScreenWindow
- 最大化窗口:
FullScreenMode.MaximizedWindow
- 窗口模式:
FullScreenMode.Windowed
1
| Screen.fullScreenMode = FullScreenMode.Windowed;
|
移动设备屏幕转向相关
允许自动旋转为左横向 Home键在左
1
| Screen.autorotateToLandscapeLeft = true;
|
允许自动选择为右横向 Home键在右
1
| Screen.autorotateToLandscapeRight = true;
|
允许自动选择为纵向 Home键在下
1
| Screen.autorotateToPortrait = true;
|
允许自动选择为纵向倒放 Home键在上
1
| Screen.autorotateToPortraitUpsideDown = true;
|
指定屏幕显示方向
1
| Screen.orientation = ScreenOrientation.LandscapeLeft;
|
静态方法
设置分辨率
一般PC游戏用的比较多
1
| Screen.SetResolution(1920, 1080, false);
|