Unity入门之重要组件和API(4) : Screen

Screen类主要处理屏幕相关的操作。

1.静态属性

1.1常用属性

cs 复制代码
【设备分辨率】
Resolution resolution = Screen.currentResolution;
print("设备分辨率宽:" + resolution.width + " 高:" + resolution.height);

【屏幕窗口的宽高】
这里得到的是当前窗口的宽高,不是设备分辨率的宽高
print("当前屏幕宽:" + Screen.width + " 高:" + Screen.height);

【屏幕休眠模式】
Screen.sleepTimeout = SleepTimeout.NeverSleep;

1.2不常用属性

cs 复制代码
【运行时是否全屏模式】
Screen.fullScreen = true;
【窗口模式】
独占全屏:FullScreenMode.ExclusiveFullScreen
全屏窗口:FullScreenMode.FullScreenWindow
最大化窗口:FullScreenMode.MaximizedWindow
窗口模式:FullScreenMode.Windowed
Screen.fullScreenMode = FullScreenMode.Windowed;

【移动设备屏幕旋转相关】
自动旋转为左横向:Home键在左
Screen.autorotateToLandscapeLeft = true;
自动旋转为右横向:Home键在右
Screen.autorotateToLandscapeRight = true;
自动旋转为竖屏:Home键在下
Screen.autorotateToPortrait = true;
自动旋转为倒放竖屏:Home键在上
Screen.autorotateToPortraitUpsideDown = true;

【指定屏幕显示方向】
Screen.orientation = ScreenOrientation.LandscapeLeft;

2.静态方法

cs 复制代码
【设置分辨率】
一般移动设备不使用
Screen.SetResolution(1920, 1080, false);
相关推荐
唐青枫7 小时前
别再乱用 StartNew:C#.NET TaskFactory 任务调度实战详解
c#·.net
Artech15 小时前
[MAF预定义的AIContextProvider-03]ChatHistoryMemoryProvider——赋予Agent从经验中学习的能力
ai·c#·agent·memory·maf
Scout-leaf2 天前
C#摸鱼实录——IoC与DI案例详解
c#
咕白m6252 天前
使用 C# 在 Excel 中应用多种字体样式
后端·c#
Artech3 天前
[MAF预定义的AIContextProvider-02]AgentSkillsProvider——将Agent Skills引入MAF
ai·c#·agent·agent skills·maf
2601_962072553 天前
李梦娇常识4600问|题库|打印版
sql·华为od·华为·c#·华为云·.net·harmonyos
m0_547486663 天前
《C#语言程序设计与实践》 全套PPT课件
c语言·c#·c语言程序设计
叶帆3 天前
【YFIOs】用C#开发硬件之设备上云
开发语言·unity·c#
IT方大同4 天前
(嵌入式操作系统)信号量
嵌入式硬件·c#
z落落4 天前
C# FileStream文件流读取文件
开发语言·c#