Skip to content

Instantly share code, notes, and snippets.

@Josef212
Created October 27, 2019 15:30
Show Gist options
  • Save Josef212/2f3592294ee23e550e0653397b74780f to your computer and use it in GitHub Desktop.
Save Josef212/2f3592294ee23e550e0653397b74780f to your computer and use it in GitHub Desktop.
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