kingBook

导航

unity Screen.orientation

public static ScreenOrientation orientation ;

Project Settings -> Player -> Resolution and Presentation -> Default Orientation,设置为:Auto Rotation 时,在进入应用且脚本运行Awake()函数及之后,默认会根据以下属性设置一个 ScreenOrientation,当屏幕发生旋转后也是如此。

public static bool autorotateToPortrait ;
public static bool autorotateToPortraitUpsideDown ;
public static bool autorotateToLandscapeLeft ;
public static bool autorotateToLandscapeRight ;
注意:
  • 如果代码中动态设置 Screen.orientation 实现横竖屏切换时,Screen.width、Screen.height、Screen.safeArea 等属性并不会在 Screen.orientation 赋值后立刻发生变化,想知道屏幕是否已旋转,只能每一帧通过比较 Screen.orientation 和 Screen.width、Screen.height 的值进行判断。
  • Screen.width、Screen.height、Screen.safeArea 的值是根据当前的屏幕的旋转方向来设置的,假如手机屏幕的分辨率为1280x720,那么正面横向拿手机并且屏幕已旋转那么 Screen.width 等于1280,Screen.height 等于720,竖向拿则相反。一定需要注意的是 Screen.orientation 的值并不能作为 Screen.width、Screen.height、Screen.safeArea 已改变的唯一条件,它们的值只在 Screen.orientation 改变且手机屏幕已实际旋转后才会改变。

posted on 2020-12-04 14:57  kingBook  阅读(574)  评论(1编辑  收藏  举报