/// <summary> /// Does nothing if not called on Android. /// </summary> public static void InitLandscapeSupportAndroid() { #if UNITY_ANDROID bool allowAutorotate = false; // Check for Android lock flag. allowAutorotate = AndroidRotationLockUtil.AllowAutorotation(); Screen.autorotateToPortrait = true; Screen.autorotateToPortraitUpsideDown = allowAutorotate; Screen.autorotateToLandscapeLeft = allowAutorotate; Screen.autorotateToLandscapeRight = allowAutorotate; Screen.orientation = allowAutorotate ? ScreenOrientation.AutoRotation : ScreenOrientation.Portrait; #endif }
/*************************************** * PUBLIC METHODS **************************************/ /*************************************** * PRIVATE VARIABLES/PROPERTIES **************************************/ /*************************************** * PRIVATE METHODS **************************************/ private void InitLandscapeSupport() { bool allowAutorotate = false; #if UNITY_ANDROID // Check for Android lock flag. allowAutorotate = AndroidRotationLockUtil.AllowAutorotation(); #endif Screen.autorotateToPortrait = true; Screen.autorotateToPortraitUpsideDown = allowAutorotate; Screen.autorotateToLandscapeLeft = allowAutorotate; Screen.autorotateToLandscapeRight = allowAutorotate; }
// Update is called once per frame void Update() { if (AndroidRotationLockUtil.AllowAutorotation()) { Screen.autorotateToLandscapeLeft = true; Screen.autorotateToLandscapeRight = true; Screen.autorotateToPortrait = true; Screen.autorotateToPortraitUpsideDown = true; if (getCurrentOrientaion() != _currentOrientation) { onOrientationChange(getCurrentOrientaion()); } } else { Screen.autorotateToLandscapeLeft = false; Screen.autorotateToLandscapeRight = false; Screen.autorotateToPortrait = false; Screen.autorotateToPortraitUpsideDown = false; } }