Created
October 27, 2019 15:30
-
-
Save Josef212/2f3592294ee23e550e0653397b74780f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class ScreenHelper | |
{ | |
private static System.Reflection.MethodInfo s_getSizeOfMainGameViewMethod = null; | |
public static bool IsTablet | |
{ | |
get | |
{ | |
Vector2 windowSize = GetMainGameViewSize(); | |
float aspectRatio = windowSize.x > windowSize.y ? windowSize.x / windowSize.y : windowSize.y / windowSize.x; | |
return aspectRatio < 1.5f; | |
} | |
} | |
public static Vector2 GetMainGameViewSize() | |
{ | |
if(s_getSizeOfMainGameViewMethod == null) | |
{ | |
System.Type T = System.Type.GetType("UnityEditor.GameView,UnityEditor"); | |
s_getSizeOfMainGameViewMethod = T.GetMethod("GetSizeOfMainGameView", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static); | |
} | |
return (Vector2)s_getSizeOfMainGameViewMethod.Invoke(null, null); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment