Guest User

FocusOnPlayDummyWindow

a guest
Jan 9th, 2018
115
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data