当前位置:   article > 正文

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

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
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48

2.静态方法

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Lesson12 : MonoBehaviour
{
    void Start()
    {
        //设置分辨率(一般移动设备不使用)
        //参数1 宽
        //参数2 高
        //参数3 是否全屏
        Screen.SetResolution(1920, 1080, true);
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小蓝xlanll/article/detail/708373
推荐阅读
相关标签
  

闽ICP备14008679号