zoukankan      html  css  js  c++  java
  • 游戏屏幕朝向

      Unity3D提供的代码级别的和屏幕相关的类主要是以下两个:

      (1)Screen.orientation 可以用于设置当前游戏的屏幕方向状态;

      (2)Input.deviceOrientation 可以获取设备屏幕方向状态。

      下面的代码根据设备的实际朝向设置App的屏幕方向:

      public void SetOrientation()
        {
            if (Input.deviceOrientation == DeviceOrientation.LandscapeLeft)     //处理横向两个方向旋转
            {
                if (Screen.orientation != ScreenOrientation.LandscapeLeft)
                {
                    Screen.orientation = ScreenOrientation.LandscapeLeft;
                }
            }
            else if (Input.deviceOrientation == DeviceOrientation.LandscapeRight)
            {
                if (Screen.orientation != ScreenOrientation.LandscapeRight)
                {
                    Screen.orientation = ScreenOrientation.LandscapeRight;
                }
    
            }
            else if (Input.deviceOrientation == DeviceOrientation.Portrait)     //处理纵向两个方向的旋转
            {
                if (Screen.orientation != ScreenOrientation.Portrait)
                {
                    Screen.orientation = ScreenOrientation.Portrait;
                }
            }
            else if (Input.deviceOrientation == DeviceOrientation.PortraitUpsideDown)
            {
                if (Screen.orientation != ScreenOrientation.PortraitUpsideDown)
                {
                    Screen.orientation = ScreenOrientation.PortraitUpsideDown;
                }
            }
        }

      也可以设置各个方向是否可以随意切换:

            // 当orientation为AutoRotation时,可以分别设置四个朝向的开关
            Screen.orientation = ScreenOrientation.AutoRotation;
            Screen.autorotateToLandscapeLeft = true;
            Screen.autorotateToLandscapeRight = true;
            Screen.autorotateToPortrait = false;
            Screen.autorotateToPortraitUpsideDown = false;

      注意下面四个值只有在Screen.orientation为AutoRotation时可用。

  • 相关阅读:
    DB2 导入CSV文件
    非归档模式下丢失数据文件,怎么办
    制作U盘操作系统安装盘
    Oracle 发布 NoSQL 数据库
    【转载】VMWare Workstation 支持64位操作系统
    net下多个应用之间的web.config冲突的解决办法(禁止继承)
    \r\n 的真切含义
    VMware虚拟机中调整Linux分区大小手记
    磨刀不光不误切菜功,还能强身健体
    农夫送狼羊白菜过河_题目收集
  • 原文地址:https://www.cnblogs.com/sifenkesi/p/4011902.html
Copyright © 2011-2022 走看看