Advertisement
Guest User

Untitled

a guest
Aug 20th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.67 KB | None | 0 0
  1. using UnityEditor;
  2. using UnityEngine;
  3.  
  4. namespace Editor
  5. {
  6. [InitializeOnLoad]
  7. public class PlayMode : MonoBehaviour
  8. {
  9. //The size of the toolbar above the game view, excluding the OS border.
  10. private static int toolbarHeight = 22;
  11.  
  12. static PlayMode()
  13. {
  14. EditorApplication.playModeStateChanged -= PlayModeStateChanged;
  15. EditorApplication.playModeStateChanged += PlayModeStateChanged;
  16. }
  17.  
  18. static void PlayModeStateChanged(PlayModeStateChange _playModeStateChange)
  19. {
  20. if (PlayerPrefs.GetInt("PlayMode_FullScreen", 0) == 1)
  21. {
  22. // Get game editor window
  23. EditorApplication.ExecuteMenuItem("Window/Game");
  24. System.Type T = System.Type.GetType("UnityEditor.GameView,UnityEditor");
  25. System.Reflection.MethodInfo GetMainGameView = T.GetMethod("GetMainGameView", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);
  26. System.Object Res = GetMainGameView.Invoke(null, null);
  27. EditorWindow gameView = (EditorWindow)Res;
  28.  
  29. switch (_playModeStateChange)
  30. {
  31. case PlayModeStateChange.EnteredPlayMode:
  32.  
  33. Rect newPos = new Rect(0, 0 - toolbarHeight, Screen.currentResolution.width, Screen.currentResolution.height + toolbarHeight);
  34.  
  35. gameView.position = newPos;
  36. gameView.minSize = new Vector2(Screen.currentResolution.width, Screen.currentResolution.height + toolbarHeight);
  37. gameView.maxSize = gameView.minSize;
  38. gameView.position = newPos;
  39.  
  40. break;
  41.  
  42. case PlayModeStateChange.EnteredEditMode:
  43.  
  44. gameView.Close();
  45.  
  46. break;
  47. }
  48. }
  49. }
  50.  
  51. [MenuItem("Tools/Editor/Play Mode/Full Screen", false, 0)]
  52. public static void PlayModeFullScreen()
  53. {
  54. PlayerPrefs.SetInt("PlayMode_FullScreen", 1);
  55. }
  56.  
  57. [MenuItem("Tools/Editor/Play Mode/Full Screen", true, 0)]
  58. public static bool PlayModeFullScreenValidate()
  59. {
  60. return PlayerPrefs.GetInt("PlayMode_FullScreen", 0) == 0;
  61. }
  62.  
  63. [MenuItem("Tools/Editor/Play Mode/Window", false, 0)]
  64. public static void PlayModeWindow()
  65. {
  66. PlayerPrefs.SetInt("PlayMode_FullScreen", 0);
  67. }
  68.  
  69. [MenuItem("Tools/Editor/Play Mode/Window", true, 0)]
  70. public static bool PlayModeWindowValidate()
  71. {
  72. return PlayerPrefs.GetInt("PlayMode_FullScreen", 0) == 1;
  73. }
  74. }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement