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 改变且手机屏幕已实际旋转后才会改变。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值