Advertisement
WiredEarp

Unity3D Maximize to Oculus Rift on Play script (V1.20)

Feb 9th, 2015
1,221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 24.12 KB | None | 0 0
  1. /*********************************************************************************************
  2. * MaxGameWindowToRift.cs                                                                     *
  3. * Version 1.21                                                                               *
  4. * By Justin Scaniglia / WiredEarp 19/04/2015                                                 *
  5. * Moves an undocked Unity GameView window to the Rift on Play, and makes it full screen      *
  6. * Will restore GameView window to original position on Stop                                  *
  7. *                                                                                            *
  8. * Features:                                                                                  *
  9. *   -   Toggle GameView position button                                                      *
  10. *   -   Restore 'normal' layout button                                                       *
  11. *   -   Save 'normal' layout button                                                          *
  12. *   -   Automatically maximize to Rift on Play, and restore GameView position on Stop        *
  13. *   -   GUI adjusts to preferred size (wider or taller)                                      *
  14. *   -   Toggle button enables or disables depending on whether Rift is on                    *
  15. * New features in V1.21:                                                                     *
  16. *   -   Save 'normal' layout button (and associated resizing code)                           *
  17. * Bug fixes in V1.21:                                                                        *
  18. *   -   Fixed bug on dragging the controls window around (reported by p00ky, thanks!)        *
  19. * New features in V1.20:                                                                     *
  20. *   -   Unity 5 compatibility                                                                *
  21. *   -   State aware toggle button                                                            *
  22. * Bug fixes in V1.21:                                                                        *
  23. *   -   Hopefully fixed failed saving where it saves a truncated layout name                 *
  24.  * Bug fixes in V1.20:                                                                       *
  25. *   -   Hopefully fixed failed saving where it saves a truncated layout name                 *
  26. * New features in V1.15:                                                                     *
  27. *   -   Messagebox notification when 'normal' layout not set                                 *
  28. *   -   Improved Rift detection                                                              *
  29. * Bug fixes in V1.15:                                                                        *
  30. *   -   Fixed some issues with being able to toggle state to active when Rift not connected  *
  31. * USE:                                                                                       *
  32. * In Unity, select Window/Maximise GameWindow To Rift                                        *
  33. * Dock the Max To Rift window, or keep it floating - but it must be docked or visible,       *
  34. * not just an unselected tab (if you want it to work as an unselected tab, let me know)      *
  35. * Click the 'Maximize On Play' checkbox to maximize/restore. Press 'Toggle' button to        *
  36. * switch the view between the Rift and normal. Press 'Restore Normal Layout' to restore a    *
  37. * layout called 'normal'. Press 'Save Normal Layout' to save a layout called 'normal'.       *
  38. * (handy for any issues)                          *                                          *
  39. *                                                                                            *
  40. * For Feedback/bug reports, message me (WiredEarp) on reddit.com or mtbs3d.com               *
  41. **********************************************************************************************/
  42.  
  43. using UnityEditor;
  44. using UnityEngine;
  45. using System;
  46. using System.Runtime.InteropServices;
  47. using System.IO;
  48.  
  49. enum GameViewState { NORMAL, MAXIMIZED };
  50.  
  51. /********************************************************************************************
  52. * MaxGameWindowToRift                                                                       *
  53. * Main editor window class                                                                  *
  54. * Handles display of the editor window, serialization of important variables, and           *  
  55. * detecting and moving GameView to Oculus screen                                            *
  56. *********************************************************************************************/
  57. public class MaxGameWindowToRift : EditorWindow
  58. {   //MAIN CLASS
  59.     #region PInvoke Declarations
  60.     //these declarations and structs etc are from www.pinvoke.net
  61.     [DllImport("user32.dll")]
  62.     internal static extern bool EnumDisplayDevices(string lpDevice, uint iDevNum, ref DISPLAY_DEVICE lpDisplayDevice, uint dwFlags);
  63.     [DllImport("user32.dll")]
  64.     internal static extern bool EnumDisplaySettings(string deviceName, int modeNum, ref DEVMODE devMode);
  65.     public static int ENUM_CURRENT_SETTINGS = -1;
  66.  
  67.     [StructLayout(LayoutKind.Sequential)]
  68.     //public class POINTL
  69.     public struct POINTL
  70.     {
  71.         public Int32 x;
  72.         public Int32 y;
  73.     }
  74.  
  75.     [StructLayout(LayoutKind.Sequential)]
  76.     public struct DEVMODE
  77.     {
  78.         private const int CCHDEVICENAME = 0x20;
  79.         private const int CCHFORMNAME = 0x20;
  80.         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 0x20)]
  81.         public string dmDeviceName;
  82.         public short dmSpecVersion;
  83.         public short dmDriverVersion;
  84.         public short dmSize;
  85.         public short dmDriverExtra;
  86.         public int dmFields;
  87.         public int dmPositionX;
  88.         public int dmPositionY;
  89.         public Int32 dmDisplayOrientation;
  90.         public int dmDisplayFixedOutput;
  91.         public short dmColor;
  92.         public short dmDuplex;
  93.         public short dmYResolution;
  94.         public short dmTTOption;
  95.         public short dmCollate;
  96.         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 0x20)]
  97.         public string dmFormName;
  98.         public short dmLogPixels;
  99.         public int dmBitsPerPel;
  100.         public int dmPelsWidth;
  101.         public int dmPelsHeight;
  102.         public int dmDisplayFlags;
  103.         public int dmDisplayFrequency;
  104.         public int dmICMMethod;
  105.         public int dmICMIntent;
  106.         public int dmMediaType;
  107.         public int dmDitherType;
  108.         public int dmReserved1;
  109.         public int dmReserved2;
  110.         public int dmPanningWidth;
  111.         public int dmPanningHeight;
  112.     }
  113.  
  114.     [Flags()]
  115.     public enum DisplayDeviceStateFlags : int
  116.     {
  117.         /// <summary>The device is part of the desktop.</summary>
  118.         AttachedToDesktop = 0x1,
  119.         MultiDriver = 0x2,
  120.         /// <summary>The device is part of the desktop.</summary>
  121.         PrimaryDevice = 0x4,
  122.         /// <summary>Represents a pseudo device used to mirror application drawing for remoting or other purposes.</summary>
  123.         MirroringDriver = 0x8,
  124.         /// <summary>The device is VGA compatible.</summary>
  125.         VGACompatible = 0x16,
  126.         /// <summary>The device is removable; it cannot be the primary display.</summary>
  127.         Removable = 0x20,
  128.         /// <summary>The device has more display modes than its output devices support.</summary>
  129.         ModesPruned = 0x8000000,
  130.         Remote = 0x4000000,
  131.         Disconnect = 0x2000000
  132.     }
  133.  
  134.     [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
  135.     public struct DISPLAY_DEVICE
  136.     {
  137.         [MarshalAs(UnmanagedType.U4)]
  138.         public int cb;
  139.         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
  140.         public string DeviceName;
  141.         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
  142.         public string DeviceString;
  143.         [MarshalAs(UnmanagedType.U4)]
  144.         public DisplayDeviceStateFlags StateFlags;
  145.         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
  146.         public string DeviceID;
  147.         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
  148.         public string DeviceKey;
  149.     }
  150.  
  151.     [StructLayout(LayoutKind.Sequential)]
  152.     public struct WINDOWPOS
  153.     {
  154.         public IntPtr hwnd;
  155.         public IntPtr hwndInsertAfter;
  156.         public int x;
  157.         public int y;
  158.         public int cx;
  159.         public int cy;
  160.         public uint flags;
  161.     }
  162.     #endregion
  163.     #region Global Declarations
  164.     // GLOBAL DECLARATIONS
  165.     //handle to the Editor window
  166.     private static MaxGameWindowToRift _window;
  167.     private static MaxGameWindowToRift _this;
  168.     [NonSerialized]
  169.     private static bool _MaximizeOnPlay = true;
  170.     [NonSerialized]
  171.     public static int _DesiredState;
  172.     [NonSerialized]
  173.     public static int _CurrentState;
  174.     //variables used to store the old window position
  175.     private WINDOWPOS _oldGameWinPos;
  176.     private Vector2 _oldGameWinMinSize; private Vector2 _oldGameWinMaxSize;
  177.     //tabheight and osborderwidth taken from sbNewsom's script
  178.     private const int tabHeight = 22;
  179.     const string LAYOUT_NAME = "rift";
  180.     const string MonitorName = "OVR";
  181.     //const string MonitorName = "DEL"; //my Alienware 1080P monitor, used for testing
  182.  
  183. #if UNITY_STANDALONE_WIN
  184.     //Windows settings
  185.     private const int osBorderWidth = 5;
  186. #endif
  187.     #endregion
  188.  
  189.     [UnityEditor.MenuItem("Window/Maximize GameWindow to Rift")]
  190.    
  191.     private static void ShowWindow()
  192.     {
  193.         _window = (MaxGameWindowToRift)EditorWindow.GetWindow(typeof(MaxGameWindowToRift));
  194.         //set the _window title
  195.         _window.title = "Max to Rift";
  196.         _window.minSize = new Vector2(150, 50);
  197.         _window.maxSize = new Vector2(300, 300);
  198.     }
  199.      
  200.     public static void stateChange(int state)
  201.     {
  202.         if (_MaximizeOnPlay)
  203.         {
  204.             _DesiredState = state;
  205.             SaveState();
  206.         }
  207.     }
  208.     static void SaveState()
  209.     {
  210.         PlayerPrefs.SetInt("_DesiredState", _DesiredState);
  211.         PlayerPrefs.SetInt("_CurrentState", _CurrentState);
  212.         int tint = _MaximizeOnPlay ? tint = 1 : tint = 0;
  213.         PlayerPrefs.SetInt("_MaxOnPlay", tint);
  214.     }
  215.     void RestoreState()
  216.     {
  217.         _DesiredState = PlayerPrefs.GetInt("_DesiredState");
  218.         _CurrentState = PlayerPrefs.GetInt("_CurrentState");
  219.         int tint = PlayerPrefs.GetInt("_MaxOnPlay");
  220.         _MaximizeOnPlay = (tint == 1) ? true : false;
  221.     }
  222.     string strToggle = "Maximize GameView";
  223.     void OnGUI()
  224.     {
  225.         if (_window == null)
  226.             ShowWindow();
  227.         EditorGUILayout.Space();
  228.         GUILayout.BeginHorizontal();
  229.         {
  230.             if (IsMaximized())
  231.             {
  232.                 strToggle = "Restore GameView";
  233.             }
  234.             else strToggle = "Maximize GameView";
  235.         }
  236.         if (DetectActiveRift())
  237.             GUI.enabled = true;
  238.         else
  239.             GUI.enabled = false;
  240.         if (GUILayout.Button(new GUIContent(strToggle, "Press to toggle GameView to/from full screen on Rift"), GUILayout.Width(145), GUILayout.Height(20)))
  241.         {
  242.             GUI.enabled = true;
  243.             //use this opportunity to reset the _actual_ state of the Game window, just in case its gotten buggered up
  244.             if (IsMaximized())
  245.             {
  246.                 _CurrentState = (int)GameViewState.MAXIMIZED;
  247.                 strToggle = "Restore GameView";
  248.             }
  249.             else
  250.             {
  251.                 _CurrentState = (int)GameViewState.NORMAL;
  252.                 strToggle = "Maximize GameView";
  253.             }
  254.            
  255.             if (DetectActiveRift())
  256.             {
  257.                 _DesiredState = (_DesiredState == (int)GameViewState.MAXIMIZED ? _DesiredState = (int)GameViewState.NORMAL : _DesiredState = (int)GameViewState.MAXIMIZED);
  258.                 SaveState();
  259.             }
  260.         }
  261.         GUI.enabled = true;
  262.         if (position.width < 250)
  263.         {
  264.             GUILayout.EndHorizontal();
  265.             GUILayout.BeginHorizontal();
  266.         }
  267.         if (GUILayout.Button(new GUIContent("Save normal Layout", "Press to save a window layout called 'normal'"), GUILayout.Width(145), GUILayout.Height(20)))
  268.         {
  269.             SaveWindowLayout("normal");
  270.         }
  271.         GUILayout.EndHorizontal();
  272.         GUILayout.BeginHorizontal();
  273.         EditorGUIUtility.labelWidth = 140;
  274.  
  275.         _MaximizeOnPlay = EditorGUILayout.ToggleLeft("Maximize On Play", _MaximizeOnPlay,GUILayout.Width(145));
  276.        
  277.         if (position.width < 250)
  278.         {
  279.             GUILayout.EndHorizontal();
  280.         }
  281.         GUILayout.BeginHorizontal();
  282.         if (GUILayout.Button(new GUIContent("Restore normal Layout", "Press to restore the window layout named 'normal'"), GUILayout.Width(145), GUILayout.Height(20)))
  283.         {
  284.            if (!RestoreWindowLayout("normal"))
  285.             {
  286.                 EditorUtility.DisplayDialog("Layout Not Found", "Could not find a window layout called 'normal'. Please create one with this name before using this button.", "Ok");
  287.             };
  288.         }
  289.         GUILayout.EndHorizontal();
  290.     }
  291.     void OnEnable()
  292.     {
  293.         RestoreState();
  294.     }
  295.  
  296.     private void Update()
  297.     {
  298.         if (_CurrentState != _DesiredState)
  299.         {
  300.             if (_DesiredState == (int)GameViewState.MAXIMIZED)
  301.             {   // MAXIMIZED TO RIFT GAMEVIEW WINDOW
  302.                 if (IsMaximized()) return;
  303.                 _CurrentState = (int)GameViewState.MAXIMIZED;
  304.                 SaveState();
  305.                 //save the window pos    
  306.                 SaveWindowLayout(LAYOUT_NAME);
  307.                 MaximizeToRift();
  308.             }
  309.             else //playState==GameViewState.NORMAL
  310.             {   // NORMAL GAMEVIEW WINDOW
  311.                 //move the window back to the old position
  312.                 _CurrentState = (int)GameViewState.NORMAL;
  313.                 SaveState();
  314.                 RestoreGameWindow();
  315.                 RestoreWindowLayout(LAYOUT_NAME);
  316.             }
  317.             return;
  318.         }
  319.     }
  320.  
  321.     private void SaveOldPos()
  322.     {
  323.         EditorWindow tGameWindow = GetGameView();
  324.         if (!tGameWindow)
  325.         {
  326.             Debug.Log("Failed to get GameView");
  327.             return;
  328.         }
  329.         _oldGameWinPos.x = (int)tGameWindow.position.x;
  330.         _oldGameWinPos.y = (int)tGameWindow.position.y;
  331.         _oldGameWinPos.cx = (int)tGameWindow.position.width;
  332.         _oldGameWinPos.cy = (int)tGameWindow.position.height;
  333.     }
  334.     private void SaveWindowLayout(string layoutName)
  335.     {
  336.         //save the current _window layout
  337.         EditorApplication.ExecuteMenuItem("Window/Layouts/Save Layout...");
  338.         EditorApplication.ExecuteMenuItem("Window/Layouts/Save Layout...");
  339.         foreach (char tch in layoutName)
  340.         {
  341.             EditorWindow.focusedWindow.SendEvent(Event.KeyboardEvent(tch.ToString()));
  342.         }
  343.         EditorWindow.focusedWindow.SendEvent(Event.KeyboardEvent("[enter]"));
  344.     }
  345.  
  346.     private bool RestoreWindowLayout(string layoutName)
  347.     {
  348.         //restore the saved layout
  349.         return EditorApplication.ExecuteMenuItem("Window/Layouts/" + layoutName);
  350.     }
  351.     private void MaximizeToRift()
  352.     {
  353.  
  354.         SaveOldPos();
  355.         //get a handle to the game view
  356.         EditorWindow tGameWindow = GetGameView();
  357.         if (!tGameWindow)
  358.         {
  359.             Debug.Log("Failed to get GameView");
  360.             return;
  361.         }
  362.         //Get the Rift window position
  363.         WINDOWPOS winPos = new WINDOWPOS();
  364.         if (!GetRiftMonitorWindowPos(ref winPos))
  365.         {
  366.             Debug.Log("No Rift Detected");
  367.             return;
  368.         }
  369.         // When minSize and maxSize are the same, no OS border is applied to the window (this and tabheights etc taken from sbNewsom's script),
  370.         // although I use them a bit differently (seem to be more accurate on my 1080P monitor while testing)
  371.         // First, save the existing window size (we will need it when restoring the window later)
  372.         _oldGameWinMinSize = tGameWindow.minSize;
  373.         _oldGameWinMaxSize = tGameWindow.maxSize;
  374.         //modify the window min/max size before maximizing to width (to remove borders)
  375.         winPos.y += tabHeight - osBorderWidth;
  376.         winPos.cy += tabHeight;// -osBorderWidth;
  377.         //Finally, call the MoveGameViewNatively routine, twice, since the first time will potentially just undock it if docked (another way would be to check .docked)
  378.         MoveGameViewNatively(tGameWindow, winPos); //this one to simply move or undock it
  379.         //now, set the gameWindow min and max size to remove the borders
  380.         tGameWindow.minSize = new Vector2(winPos.cx, winPos.cy);
  381.         tGameWindow.maxSize = tGameWindow.minSize;
  382.         MoveGameViewNatively(tGameWindow, winPos);
  383.     }
  384.     private bool IsMaximized()
  385.     {
  386.         //get a handle to the game view
  387.         EditorWindow tGameWindow = GetGameView();
  388.         if (!tGameWindow)
  389.         {
  390.             Debug.Log("Failed to get GameView");
  391.             //return true here to restore to window, not rift by default
  392.             return true;
  393.         }
  394.         //Get the Rift window position
  395.         WINDOWPOS winPos = new WINDOWPOS();
  396.         if (!GetRiftMonitorWindowPos(ref winPos))
  397.         {
  398.             Debug.Log("No Rift Detected");
  399.             return false;
  400.         }
  401.         //CALCULATE THE MAXIMIZED SIZE
  402.         if (tGameWindow.position.width == winPos.cx)
  403.         {
  404.             return true;
  405.         }
  406.         else
  407.             return false;
  408.     }
  409.     private void RestoreGameWindow()
  410.     {
  411.         //get a handle to the game view
  412.         EditorWindow tGameWindow = GetGameView();
  413.         if (!tGameWindow)
  414.         {
  415.             Debug.Log("Failed to get GameView");
  416.             return;
  417.         }
  418.         //reset the gameWindow min and max size to remove the borders
  419.         tGameWindow.minSize = _oldGameWinMinSize;
  420.         tGameWindow.maxSize = _oldGameWinMaxSize;
  421.         //Finally, call the MoveGameViewNatively routine to return the gameWindow to the old position
  422.         MoveGameViewNatively(tGameWindow, _oldGameWinPos);
  423.     }
  424.     private void MoveGameViewNatively(EditorWindow gameWindow, WINDOWPOS winPos)
  425.     {
  426.         Rect tPos = new Rect();
  427.         tPos.x = winPos.x;
  428.         tPos.y = winPos.y;
  429.         tPos.width = winPos.cx;
  430.         tPos.height = winPos.cy;
  431.         gameWindow.position = tPos;
  432.     }
  433.     private EditorWindow GetGameView()
  434.     {   //thanks to bunny83 for this routine to get the GameView (not sure if theres a better way, but at least this doesn't require reflection)
  435.         Type ttype = Type.GetType("UnityEditor.GameView,UnityEditor");
  436.         object[] foundView = Resources.FindObjectsOfTypeAll(ttype);
  437.         if (foundView.Length > 0)
  438.         {
  439.             EditorWindow tGameView = (EditorWindow)foundView[0];
  440.             return tGameView;
  441.         }
  442.         return null;
  443.     }
  444.     public static bool DetectActiveRift()
  445.     {   //Detects a DK2 (or hopefully other Rift) by monitor
  446.         uint deviceIndex = 0;
  447.         bool foundMon = false;
  448.         do
  449.         {
  450.             var device = new DISPLAY_DEVICE();
  451.             device.cb = Marshal.SizeOf(device);
  452.             //First, enumerate through all the display devices
  453.             DISPLAY_DEVICE displayDevice = new DISPLAY_DEVICE();
  454.             displayDevice.cb = Marshal.SizeOf(displayDevice);
  455.             foundMon = EnumDisplayDevices(null, deviceIndex++, ref displayDevice, 0);
  456.             //We only care about active display devices
  457.             if ((displayDevice.StateFlags & DisplayDeviceStateFlags.AttachedToDesktop) == DisplayDeviceStateFlags.AttachedToDesktop)
  458.             {
  459.                 DISPLAY_DEVICE monitor = new DISPLAY_DEVICE();
  460.                 monitor.cb = Marshal.SizeOf(monitor);
  461.                 //now call EnumDisplayDevices again to get the device id
  462.                 EnumDisplayDevices(displayDevice.DeviceName, 0, ref monitor, 0);
  463.                 //If the display deviceID contains OVR then hopefully this is the Rift
  464.                 if (monitor.DeviceID.ToUpper().Contains(MonitorName))
  465.                     return true;
  466.             }
  467.         } while (foundMon);
  468.         return false;
  469.     }
  470.     private bool GetRiftMonitorWindowPos(ref WINDOWPOS winPos)
  471.     {   //Finds a DK2 (or hopefully other Rifts?) monitor and gets its location, width and height.
  472.         uint deviceIndex = 0;
  473.         bool foundMon = false;
  474.         do
  475.         {
  476.             var device = new DISPLAY_DEVICE();
  477.             device.cb = Marshal.SizeOf(device);
  478.             //First, enumerate through all the display devices
  479.             DISPLAY_DEVICE displayDevice = new DISPLAY_DEVICE();
  480.             displayDevice.cb = Marshal.SizeOf(displayDevice);
  481.             foundMon = EnumDisplayDevices(null, deviceIndex++, ref displayDevice, 0);
  482.             //We only care about active display devices
  483.             if ((displayDevice.StateFlags & DisplayDeviceStateFlags.AttachedToDesktop) == DisplayDeviceStateFlags.AttachedToDesktop)
  484.             {
  485.                 DISPLAY_DEVICE monitor = new DISPLAY_DEVICE();
  486.                 monitor.cb = Marshal.SizeOf(monitor);
  487.                 //now call EnumDisplayDevices again to get the device id
  488.                 EnumDisplayDevices(displayDevice.DeviceName, 0, ref monitor, 0);
  489.                 //If the display deviceID contains OVR then hopefully this is the Rift
  490.                 if (monitor.DeviceID.ToUpper().Contains(MonitorName))
  491.                 {
  492.                     DEVMODE devModeInfo = new DEVMODE();
  493.                     //Now try to get the info we need about the display and its location etc using EnumDisplaySettings
  494.                     if (EnumDisplaySettings(displayDevice.DeviceName, ENUM_CURRENT_SETTINGS, ref devModeInfo))
  495.                     {
  496.                         winPos.x = devModeInfo.dmPositionX;
  497.                         winPos.y = devModeInfo.dmPositionY;
  498.                         winPos.cx = devModeInfo.dmPelsWidth;
  499.                         winPos.cy = devModeInfo.dmPelsHeight;
  500.                     }
  501.                     return true;
  502.                 }
  503.             }
  504.         } while (foundMon);
  505.         return false;
  506.     }
  507.  
  508.     /********************************************************************************************
  509.     * UnityPlayState                                                                            *
  510.     * Static class that detects Play/Stop events and calls the main class when they occur       *
  511.     *********************************************************************************************/
  512.     [InitializeOnLoad]
  513.     public static class UnityPlayState
  514.     {   //CLASS TO SUPPORT GETTING THE UNITY PLAY STATE
  515.         static int _State;
  516.         static bool wasPaused;
  517.         static UnityPlayState()
  518.         {
  519.             //EditorApplication.update += Update;
  520. #if UNITY_EDITOR
  521.             EditorApplication.playmodeStateChanged = HandleOnPlayModeChanged;
  522. #endif
  523.         }
  524.         public static int GetPlayState()
  525.         { //DEPRECATED
  526.             return _State;
  527.         }
  528.         static void HandleOnPlayModeChanged()
  529.         {
  530.             if (!DetectActiveRift()) return; //we are not interested in state changes if the Rift cannot be found
  531.  
  532.             if (EditorApplication.isPaused)
  533.             {
  534.                 if (!wasPaused)
  535.                 {
  536.                     wasPaused = true;
  537.                 }
  538.                 else //was stopped or stop pressed
  539.                 {
  540.                     Stop();
  541.                 }
  542.             }
  543.             else if ((EditorApplication.isPlayingOrWillChangePlaymode))
  544.             {
  545.                 if (!EditorApplication.isPlaying)
  546.                 {
  547.                     Play();
  548.                 }
  549.                 if (wasPaused)
  550.                 {
  551.                     Play();
  552.                     wasPaused = false;
  553.                 }
  554.             }
  555.             else if ((!EditorApplication.isPlayingOrWillChangePlaymode && EditorApplication.isPlaying))
  556.             {
  557.                 Stop();
  558.             }
  559.         }
  560.         static void Play()
  561.         {
  562.             _State = (int)GameViewState.MAXIMIZED;
  563.             stateChange(_State);
  564.         }
  565.  
  566.         static void Stop()
  567.         {
  568.             _State = (int)GameViewState.NORMAL;
  569.             stateChange(_State);
  570.         }
  571.     }
  572. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement