Advertisement
Guest User

FocusOnPlayDummyWindow

a guest
Jan 9th, 2018
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.12 KB | None | 0 0
  1. using UnityEditor;
  2.  
  3. [InitializeOnLoad]
  4. public class FocusOnPlayDummyWindow : EditorWindow {
  5.     static FocusOnPlayDummyWindow _instance;
  6.     static bool IsOpen { get { return _instance != null; } }
  7.  
  8.     [MenuItem("Window/Focus on Play Dummy Window")]
  9.     static FocusOnPlayDummyWindow GetFocusOnPlayDummyWindow() {
  10.         FocusOnPlayDummyWindow window = GetWindow<FocusOnPlayDummyWindow>("Dummy");
  11.  
  12.         window.Show();
  13.  
  14.         return window;
  15.     }
  16.  
  17.     void OnEnable() {
  18.         _instance = this;
  19.     }
  20.  
  21.     void OnDisable() {
  22.         _instance = null;
  23.     }
  24.  
  25.     static FocusOnPlayDummyWindow() {
  26.         EditorApplication.playModeStateChanged += OnPlayModeChanged;
  27.     }
  28.  
  29.     static void OnPlayModeChanged(PlayModeStateChange playModeStateChange) {
  30.         if (!IsOpen) { return; }
  31.  
  32.         switch (playModeStateChange) {
  33.             case PlayModeStateChange.ExitingEditMode:
  34.                 GetFocusOnPlayDummyWindow().Focus();
  35.                 break;
  36.             case PlayModeStateChange.EnteredEditMode:
  37.                 GetWindow<SceneView>().Focus();
  38.                 break;
  39.         }
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement