Skip to content

Commit

Permalink
Fix screen rotation
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmfinol committed Feb 8, 2018
1 parent 2c72193 commit 59e59c1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 16 deletions.
4 changes: 2 additions & 2 deletions Assets/Scripts/DeckEditor/CardSearchMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ void LateUpdate()
Search();
Hide();
}
else if (Input.GetButtonDown(CardIn.FocusName) || Input.GetButtonDown(CardIn.FocusText))
else if (Input.GetButtonDown(CardIn.FocusNameInput) || Input.GetButtonDown(CardIn.FocusTextInput))
FocusInputField();
else if (Input.GetButtonDown(CardIn.Vertical) || Input.GetButtonDown(CardIn.Horizontal))
else if (Input.GetButtonDown(CardIn.VerticalInput) || Input.GetButtonDown(CardIn.HorizontalInput))
FocusToggle();
else if (Input.GetButtonDown(CardIn.NewInput) && ActiveToggle != null)
ToggleEnum();
Expand Down
30 changes: 16 additions & 14 deletions Assets/Scripts/ScreenRotationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,28 @@ void OnApplicationFocus(bool haveFocus)
ToggleAutoRotation();
}

static void ToggleAutoRotation()
public static void ToggleAutoRotation()
{
AutoRotationOn = DeviceAutoRotationIsOn();
Screen.autorotateToPortrait = AutoRotationOn;
Screen.autorotateToPortraitUpsideDown = AutoRotationOn;
Screen.autorotateToLandscapeLeft = AutoRotationOn;
Screen.autorotateToLandscapeRight = AutoRotationOn;
bool autoRotationOn = IsAutoRotationOn;
Screen.autorotateToPortrait = autoRotationOn;
Screen.autorotateToPortraitUpsideDown = autoRotationOn;
Screen.autorotateToLandscapeLeft = autoRotationOn;
Screen.autorotateToLandscapeRight = autoRotationOn;
Screen.orientation = ScreenOrientation.AutoRotation;
}

static bool DeviceAutoRotationIsOn()
public static bool IsAutoRotationOn
{
get {
#if UNITY_ANDROID && !UNITY_EDITOR
using (AndroidJavaClass actClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer")) {
AndroidJavaObject context = actClass.GetStatic<AndroidJavaObject>("currentActivity");
AndroidJavaClass systemGlobal = new AndroidJavaClass("android.provider.Settings$System");
int rotationOn = systemGlobal.CallStatic<int>("getInt", context.Call<AndroidJavaObject>("getContentResolver"), "accelerometer_rotation");
return rotationOn==1;
}
using (AndroidJavaClass actClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer")) {
AndroidJavaObject context = actClass.GetStatic<AndroidJavaObject>("currentActivity");
AndroidJavaClass systemGlobal = new AndroidJavaClass("android.provider.Settings$System");
int rotationOn = systemGlobal.CallStatic<int>("getInt", context.Call<AndroidJavaObject>("getContentResolver"), "accelerometer_rotation");
return rotationOn==1;
}
#endif
return true;
return true;
}
}
}
13 changes: 13 additions & 0 deletions Assets/Scripts/ScreenRotationManager.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 59e59c1

Please sign in to comment.