Last active
July 30, 2019 07:59
-
-
Save yKimisaki/598c167f8a1b4df20b1065cc525c1b62 to your computer and use it in GitHub Desktop.
This file contains 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
using System; | |
using System.Reflection; | |
using UnityEngine; | |
#if UNITY_EDITOR | |
using UnityEditor; | |
#endif | |
namespace Tonari.Unity | |
{ | |
public static class GameScreen | |
{ | |
#if UNITY_EDITOR | |
private static Vector2 _sizeOfMainGameView; | |
static GameScreen() | |
{ | |
var type = Type.GetType("UnityEditor.GameView, UnityEditor"); | |
if (type != null) | |
{ | |
var method = type.GetMethod("GetSizeOfMainGameView", BindingFlags.NonPublic | BindingFlags.Static); | |
var getSizeOfMainGameView = Delegate.CreateDelegate(typeof(Func<Vector2>), method) as Func<Vector2>; | |
if (getSizeOfMainGameView == null) | |
throw new InvalidOperationException("GetSizeOfMainGameViewを取得できません"); | |
_sizeOfMainGameView = getSizeOfMainGameView(); | |
} | |
} | |
#endif | |
public static Vector2 Size | |
{ | |
get | |
{ | |
#if UNITY_EDITOR | |
return _sizeOfMainGameView; | |
#else | |
return new Vector2(Width, Height); | |
#endif | |
} | |
} | |
public static float Width | |
{ | |
get | |
{ | |
#if UNITY_EDITOR | |
return _sizeOfMainGameView.x; | |
#else | |
return Screen.width; | |
#endif | |
} | |
} | |
public static float Height | |
{ | |
get | |
{ | |
#if UNITY_EDITOR | |
return _sizeOfMainGameView.y; | |
#else | |
return Screen.height; | |
#endif | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment