×

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

Kalet Kalet 发表于2023-07-28 21:42:37 浏览815 评论0

抢沙发发表评论

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);

    }

}

————————————————

版权声明:本文为CSDN博主「_ElecSheep」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。

原文链接:https://blog.csdn.net/SEA_0825/article/details/126838520


群贤毕至

访客