【Unity】屏幕相关Screen类中的静态属性和方法

1.静态属性

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Lesson12 : MonoBehaviour
{
    void Start()
    {
        //常用的
        //1.得到当前屏幕的分辨率
        //  得到的是显示器的分辨率
        Resolution r = Screen.currentResolution;
        print("宽:" + r.width + "高:" + r.height);

        //2.屏幕窗口当前宽高
        //  得到的是Game窗口的宽高
        print(Screen.width);
        print(Screen.height);

        //3.设置屏幕休眠模式
        Screen.sleepTimeout = SleepTimeout.NeverSleep;

        //不常用的
        //1.运行时是否全屏模式
        Screen.fullScreen = true;

        //2.设置窗口模式
        //  -独占全屏 FullScreeMode.ExclusiveFullScreen
        //  -全屏窗口 FullScreeMode.FullScreenWindow
        //  -最大化窗口 FullScreeMode.MaximizedWindow
        //  -窗口模式 FullScreeMode.Windowed
        Screen.fullScreenMode = FullScreenMode.FullScreenWindow;

        //3.移动设备屏幕转向相关
        //  允许自动旋转为左横向 (Home键在左侧 就是左横向)
        Screen.autorotateToLandscapeLeft = true;
        //  允许自动旋转为右横向 (Home键在右侧 就是右横向)
        Screen.autorotateToLandscapeRight = true;
        //  允许自动旋转为竖屏 (Home键在下 就是竖屏)
        Screen.autorotateToPortrait = true;
        //  允许自动旋转为纵向倒着 (Home键在上 就是纵向倒着)
        Screen.autorotateToPortraitUpsideDown = true;

        //4.指定屏幕显示方向
        //  定死了 只能左横向(Home键在左侧)
        Screen.orientation = ScreenOrientation.LandscapeLeft
    }
}

2.静态方法

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Lesson12 : MonoBehaviour
{
    void Start()
    {
        //设置分辨率(一般移动设备不使用)
        //参数1 宽
        //参数2 高
        //参数3 是否全屏
        Screen.SetResolution(1920, 1080, true);
    }
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值