static public Vector2 screenSize
{
get
{
int frame = Time.frameCount;
if (mSizeFrame != frame || !Application.isPlaying)
{
Profiler.BeginSample("Editor-only GC allocation (NGUITools.screenSize)");
mSizeFrame = frame;
if (s_GetSizeOfMainGameView == null && !mCheckedMainViewFunc)
{
mCheckedMainViewFunc = true;
System.Type type = System.Type.GetType("UnityEditor.GameView,UnityEditor");
// Post-Unity 5.4
var methodInfo = type.GetMethod("GetMainGameViewTargetSize",
System.Reflection.BindingFlags.Public |
System.Reflection.BindingFlags.NonPublic |
System.Reflection.BindingFlags.Static);
// Pre-Unity 5.4
if (methodInfo == null)
methodInfo = type.GetMethod("GetSizeOfMainGameView",
System.Reflection.BindingFlags.Public |
System.Reflection.BindingFlags.NonPublic |
System.Reflection.BindingFlags.Static);
// Create the delegate
if (methodInfo != null)
{
s_GetSizeOfMainGameView
= (Func
<Vector2
>)Delegate.CreateDelegate(typeof(Func
<Vector2
>), methodInfo
); }
else Debug.LogWarning("Unable to get the main game view size function");
}
if (s_GetSizeOfMainGameView != null)
{
#if UNITY_EDITOR_OSX
// There seems to be a Unity 5.4 bug that returns invalid screen size when the mouse is clicked (wtf?) on OSX
if (mGameSize.x == 1f && mGameSize.y == 1f) mGameSize = s_GetSizeOfMainGameView();
#else
mGameSize = s_GetSizeOfMainGameView();
#endif
}
else mGameSize
= new Vector2
(Screen
.width, Screen
.height); Profiler.EndSample();
}
return mGameSize;
}
}