Exemplo n.º 1
0
        public static bool LoadWindowLayout(string path, bool newProjectLayoutWasCreated)
        {
            Rect position = default(Rect);

            UnityEngine.Object[] array  = Resources.FindObjectsOfTypeAll(typeof(ContainerWindow));
            UnityEngine.Object[] array2 = array;
            for (int i = 0; i < array2.Length; i++)
            {
                ContainerWindow containerWindow = (ContainerWindow)array2[i];
                if (containerWindow.showMode == ShowMode.MainWindow)
                {
                    position = containerWindow.position;
                }
            }
            bool result;

            try
            {
                ContainerWindow.SetFreezeDisplay(true);
                WindowLayout.CloseWindows();
                UnityEngine.Object[]      array3 = InternalEditorUtility.LoadSerializedFileAndForget(path);
                List <UnityEngine.Object> list   = new List <UnityEngine.Object>();
                int j = 0;
                while (j < array3.Length)
                {
                    UnityEngine.Object @object      = array3[j];
                    EditorWindow       editorWindow = @object as EditorWindow;
                    if (editorWindow != null)
                    {
                        if (!(editorWindow.m_Parent == null))
                        {
                            goto IL_17D;
                        }
                        UnityEngine.Object.DestroyImmediate(editorWindow, true);
                        UnityEngine.Debug.LogError(string.Concat(new object[]
                        {
                            "Removed unparented EditorWindow while reading window layout: window #",
                            j,
                            ", type=",
                            @object.GetType().ToString(),
                            ", instanceID=",
                            @object.GetInstanceID()
                        }));
                    }
                    else
                    {
                        DockArea dockArea = @object as DockArea;
                        if (!(dockArea != null) || dockArea.m_Panes.Count != 0)
                        {
                            goto IL_17D;
                        }
                        dockArea.Close(null);
                        UnityEngine.Debug.LogError(string.Concat(new object[]
                        {
                            "Removed empty DockArea while reading window layout: window #",
                            j,
                            ", instanceID=",
                            @object.GetInstanceID()
                        }));
                    }
IL_187:
                    j++;
                    continue;
IL_17D:
                    list.Add(@object);
                    goto IL_187;
                }
                ContainerWindow containerWindow2 = null;
                ContainerWindow containerWindow3 = null;
                for (int k = 0; k < list.Count; k++)
                {
                    ContainerWindow containerWindow4 = list[k] as ContainerWindow;
                    if (containerWindow4 != null && containerWindow4.showMode == ShowMode.MainWindow)
                    {
                        containerWindow3 = containerWindow4;
                        if ((double)position.width != 0.0)
                        {
                            containerWindow2          = containerWindow4;
                            containerWindow2.position = position;
                        }
                    }
                }
                for (int l = 0; l < list.Count; l++)
                {
                    UnityEngine.Object object2 = list[l];
                    if (object2 == null)
                    {
                        UnityEngine.Debug.LogError("Error while reading window layout: window #" + l + " is null");
                    }
                    else if (object2.GetType() == null)
                    {
                        UnityEngine.Debug.LogError(string.Concat(new object[]
                        {
                            "Error while reading window layout: window #",
                            l,
                            " type is null, instanceID=",
                            object2.GetInstanceID()
                        }));
                    }
                    else if (newProjectLayoutWasCreated)
                    {
                        MethodInfo method = object2.GetType().GetMethod("OnNewProjectLayoutWasCreated", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
                        if (method != null)
                        {
                            method.Invoke(object2, null);
                        }
                    }
                }
                if (containerWindow2)
                {
                    containerWindow2.position = position;
                    containerWindow2.OnResize();
                }
                if (containerWindow3 == null)
                {
                    UnityEngine.Debug.LogError("Error while reading window layout: no main window found");
                    throw new Exception();
                }
                containerWindow3.Show(containerWindow3.showMode, true, true);
                for (int m = 0; m < list.Count; m++)
                {
                    EditorWindow editorWindow2 = list[m] as EditorWindow;
                    if (editorWindow2)
                    {
                        editorWindow2.minSize = editorWindow2.minSize;
                    }
                    ContainerWindow containerWindow5 = list[m] as ContainerWindow;
                    if (containerWindow5 && containerWindow5 != containerWindow3)
                    {
                        containerWindow5.Show(containerWindow5.showMode, true, true);
                    }
                }
                GameView gameView = WindowLayout.GetMaximizedWindow() as GameView;
                if (gameView != null && gameView.maximizeOnPlay)
                {
                    WindowLayout.Unmaximize(gameView);
                }
                if (newProjectLayoutWasCreated)
                {
                    if (UnityConnect.instance.online && UnityConnect.instance.loggedIn && UnityConnect.instance.shouldShowServicesWindow)
                    {
                        UnityConnectServiceCollection.instance.ShowService("Hub", true);
                    }
                    else
                    {
                        UnityConnectServiceCollection.instance.CloseServices();
                    }
                }
            }
            catch (Exception arg)
            {
                UnityEngine.Debug.LogError("Failed to load window layout: " + arg);
                int num = 0;
                if (!Application.isTestRun)
                {
                    num = EditorUtility.DisplayDialogComplex("Failed to load window layout", "This can happen if layout contains custom windows and there are compile errors in the project.", "Load Default Layout", "Quit", "Revert Factory Settings");
                }
                if (num != 0)
                {
                    if (num != 1)
                    {
                        if (num == 2)
                        {
                            WindowLayout.RevertFactorySettings();
                        }
                    }
                    else
                    {
                        EditorApplication.Exit(0);
                    }
                }
                else
                {
                    WindowLayout.LoadDefaultLayout();
                }
                result = false;
                return(result);
            }
            finally
            {
                ContainerWindow.SetFreezeDisplay(false);
                if (Path.GetExtension(path) == ".wlt")
                {
                    Toolbar.lastLoadedLayoutName = Path.GetFileNameWithoutExtension(path);
                }
                else
                {
                    Toolbar.lastLoadedLayoutName = null;
                }
            }
            result = true;
            return(result);
        }
Exemplo n.º 2
0
        public static void Unmaximize(EditorWindow win)
        {
            HostView parent = win.m_Parent;

            if (parent == null)
            {
                UnityEngine.Debug.LogError("Host view was not found");
                WindowLayout.RevertFactorySettings();
            }
            else
            {
                UnityEngine.Object[] array = InternalEditorUtility.LoadSerializedFileAndForget(Path.Combine(WindowLayout.layoutsProjectPath, "CurrentMaximizeLayout.dwlt"));
                if (array.Length < 2)
                {
                    UnityEngine.Debug.Log("Maximized serialized file backup not found");
                    WindowLayout.RevertFactorySettings();
                }
                else
                {
                    SplitView    splitView    = array[0] as SplitView;
                    EditorWindow editorWindow = array[1] as EditorWindow;
                    if (splitView == null)
                    {
                        UnityEngine.Debug.Log("Maximization failed because the root split view was not found");
                        WindowLayout.RevertFactorySettings();
                    }
                    else
                    {
                        ContainerWindow window = win.m_Parent.window;
                        if (window == null)
                        {
                            UnityEngine.Debug.Log("Maximization failed because the root split view has no container window");
                            WindowLayout.RevertFactorySettings();
                        }
                        else
                        {
                            try
                            {
                                ContainerWindow.SetFreezeDisplay(true);
                                if (!parent.parent)
                                {
                                    throw new Exception();
                                }
                                int  idx      = parent.parent.IndexOfChild(parent);
                                Rect position = parent.position;
                                View parent2  = parent.parent;
                                parent2.RemoveChild(idx);
                                parent2.AddChild(splitView, idx);
                                splitView.position = position;
                                DockArea dockArea = editorWindow.m_Parent as DockArea;
                                int      idx2     = dockArea.m_Panes.IndexOf(editorWindow);
                                parent.actualView = null;
                                win.m_Parent      = null;
                                dockArea.AddTab(idx2, win);
                                dockArea.RemoveTab(editorWindow);
                                UnityEngine.Object.DestroyImmediate(editorWindow);
                                UnityEngine.Object[] array2 = array;
                                for (int i = 0; i < array2.Length; i++)
                                {
                                    UnityEngine.Object @object       = array2[i];
                                    EditorWindow       editorWindow2 = @object as EditorWindow;
                                    if (editorWindow2 != null)
                                    {
                                        editorWindow2.MakeParentsSettingsMatchMe();
                                    }
                                }
                                parent2.Initialize(parent2.window);
                                parent2.position = parent2.position;
                                splitView.Reflow();
                                UnityEngine.Object.DestroyImmediate(parent);
                                win.Focus();
                                window.DisplayAllViews();
                                win.m_Parent.MakeVistaDWMHappyDance();
                            }
                            catch (Exception arg)
                            {
                                UnityEngine.Debug.Log("Maximization failed: " + arg);
                                WindowLayout.RevertFactorySettings();
                            }
                            try
                            {
                                if (Application.platform == RuntimePlatform.OSXEditor && SystemInfo.operatingSystem.Contains("10.7") && SystemInfo.graphicsDeviceVendor.Contains("ATI"))
                                {
                                    UnityEngine.Object[] array3 = Resources.FindObjectsOfTypeAll(typeof(GUIView));
                                    for (int j = 0; j < array3.Length; j++)
                                    {
                                        GUIView gUIView = (GUIView)array3[j];
                                        gUIView.Repaint();
                                    }
                                }
                            }
                            finally
                            {
                                ContainerWindow.SetFreezeDisplay(false);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        public static bool LoadWindowLayout(string path, bool newProjectLayoutWasCreated)
        {
            Rect rect = new Rect();

            foreach (ContainerWindow containerWindow in Resources.FindObjectsOfTypeAll(typeof(ContainerWindow)))
            {
                if (containerWindow.showMode == ShowMode.MainWindow)
                {
                    rect = containerWindow.position;
                }
            }
            try
            {
                ContainerWindow.SetFreezeDisplay(true);
                WindowLayout.CloseWindows();
                UnityEngine.Object[] objectArray      = InternalEditorUtility.LoadSerializedFileAndForget(path);
                ContainerWindow      containerWindow1 = (ContainerWindow)null;
                ContainerWindow      containerWindow2 = (ContainerWindow)null;
                foreach (UnityEngine.Object @object in objectArray)
                {
                    ContainerWindow containerWindow3 = @object as ContainerWindow;
                    if ((UnityEngine.Object)containerWindow3 != (UnityEngine.Object)null && containerWindow3.showMode == ShowMode.MainWindow)
                    {
                        containerWindow2 = containerWindow3;
                        if ((double)rect.width != 0.0)
                        {
                            containerWindow1          = containerWindow3;
                            containerWindow1.position = rect;
                        }
                    }
                }
                int num = 0;
                foreach (UnityEngine.Object @object in objectArray)
                {
                    if (@object == (UnityEngine.Object)null)
                    {
                        UnityEngine.Debug.LogError((object)("Error while reading window layout: window #" + (object)num + " is null"));
                        throw new Exception();
                    }
                    if (@object.GetType() == null)
                    {
                        UnityEngine.Debug.LogError((object)("Error while reading window layout: window #" + (object)num + " type is null, instanceID=" + (object)@object.GetInstanceID()));
                        throw new Exception();
                    }
                    if (newProjectLayoutWasCreated)
                    {
                        MethodInfo method = @object.GetType().GetMethod("OnNewProjectLayoutWasCreated", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
                        if (method != null)
                        {
                            method.Invoke((object)@object, (object[])null);
                        }
                    }
                    ++num;
                }
                if ((bool)((UnityEngine.Object)containerWindow1))
                {
                    containerWindow1.position = rect;
                    containerWindow1.OnResize();
                }
                if ((UnityEngine.Object)containerWindow2 == (UnityEngine.Object)null)
                {
                    UnityEngine.Debug.LogError((object)"Error while reading window layout: no main window found");
                    throw new Exception();
                }
                containerWindow2.Show(containerWindow2.showMode, true, true);
                foreach (UnityEngine.Object @object in objectArray)
                {
                    EditorWindow editorWindow = @object as EditorWindow;
                    if ((bool)((UnityEngine.Object)editorWindow))
                    {
                        editorWindow.minSize = editorWindow.minSize;
                    }
                    ContainerWindow containerWindow3 = @object as ContainerWindow;
                    if ((bool)((UnityEngine.Object)containerWindow3) && (UnityEngine.Object)containerWindow3 != (UnityEngine.Object)containerWindow2)
                    {
                        containerWindow3.Show(containerWindow3.showMode, true, true);
                    }
                }
                GameView maximizedWindow = WindowLayout.GetMaximizedWindow() as GameView;
                if ((UnityEngine.Object)maximizedWindow != (UnityEngine.Object)null)
                {
                    if (maximizedWindow.maximizeOnPlay)
                    {
                        WindowLayout.Unmaximize((EditorWindow)maximizedWindow);
                    }
                }
            }
            catch (Exception ex)
            {
                UnityEngine.Debug.LogError((object)("Failed to load window layout: " + (object)ex));
                switch (EditorUtility.DisplayDialogComplex("Failed to load window layout", "This can happen if layout contains custom windows and there are compile errors in the project.", "Load Default Layout", "Quit", "Revert Factory Settings"))
                {
                case 0:
                    WindowLayout.LoadDefaultLayout();
                    break;

                case 1:
                    EditorApplication.Exit(0);
                    break;

                case 2:
                    WindowLayout.RevertFactorySettings();
                    break;
                }
                return(false);
            }
            finally
            {
                ContainerWindow.SetFreezeDisplay(false);
                Toolbar.lastLoadedLayoutName = !(Path.GetExtension(path) == ".wlt") ? (string)null : Path.GetFileNameWithoutExtension(path);
            }
            return(true);
        }
Exemplo n.º 4
0
        public static bool LoadWindowLayout(string path, bool newProjectLayoutWasCreated)
        {
            Rect position = default(Rect);

            UnityEngine.Object[] array  = Resources.FindObjectsOfTypeAll(typeof(ContainerWindow));
            UnityEngine.Object[] array2 = array;
            for (int i = 0; i < array2.Length; i++)
            {
                ContainerWindow containerWindow = (ContainerWindow)array2[i];
                if (containerWindow.showMode == ShowMode.MainWindow)
                {
                    position = containerWindow.position;
                }
            }
            try
            {
                ContainerWindow.SetFreezeDisplay(true);
                WindowLayout.CloseWindows();
                UnityEngine.Object[] array3           = InternalEditorUtility.LoadSerializedFileAndForget(path);
                ContainerWindow      containerWindow2 = null;
                ContainerWindow      containerWindow3 = null;
                UnityEngine.Object[] array4           = array3;
                for (int j = 0; j < array4.Length; j++)
                {
                    UnityEngine.Object @object          = array4[j];
                    ContainerWindow    containerWindow4 = @object as ContainerWindow;
                    if (containerWindow4 != null && containerWindow4.showMode == ShowMode.MainWindow)
                    {
                        containerWindow3 = containerWindow4;
                        if ((double)position.width != 0.0)
                        {
                            containerWindow2          = containerWindow4;
                            containerWindow2.position = position;
                        }
                    }
                }
                int num = 0;
                UnityEngine.Object[] array5 = array3;
                for (int k = 0; k < array5.Length; k++)
                {
                    UnityEngine.Object object2 = array5[k];
                    if (object2 == null)
                    {
                        UnityEngine.Debug.LogError("Error while reading window layout: window #" + num + " is null");
                        throw new Exception();
                    }
                    if (object2.GetType() == null)
                    {
                        UnityEngine.Debug.LogError(string.Concat(new object[]
                        {
                            "Error while reading window layout: window #",
                            num,
                            " type is null, instanceID=",
                            object2.GetInstanceID()
                        }));
                        throw new Exception();
                    }
                    if (newProjectLayoutWasCreated)
                    {
                        MethodInfo method = object2.GetType().GetMethod("OnNewProjectLayoutWasCreated", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
                        if (method != null)
                        {
                            method.Invoke(object2, null);
                        }
                    }
                    num++;
                }
                if (containerWindow2)
                {
                    containerWindow2.position = position;
                    containerWindow2.OnResize();
                }
                if (containerWindow3 == null)
                {
                    UnityEngine.Debug.LogError("Error while reading window layout: no main window found");
                    throw new Exception();
                }
                containerWindow3.Show(containerWindow3.showMode, true, true);
                UnityEngine.Object[] array6 = array3;
                for (int l = 0; l < array6.Length; l++)
                {
                    UnityEngine.Object object3      = array6[l];
                    EditorWindow       editorWindow = object3 as EditorWindow;
                    if (editorWindow)
                    {
                        editorWindow.minSize = editorWindow.minSize;
                    }
                    ContainerWindow containerWindow5 = object3 as ContainerWindow;
                    if (containerWindow5 && containerWindow5 != containerWindow3)
                    {
                        containerWindow5.Show(containerWindow5.showMode, true, true);
                    }
                }
                GameView gameView = WindowLayout.GetMaximizedWindow() as GameView;
                if (gameView != null && gameView.maximizeOnPlay)
                {
                    WindowLayout.Unmaximize(gameView);
                }
            }
            catch (Exception arg)
            {
                UnityEngine.Debug.LogError("Failed to load window layout: " + arg);
                switch (EditorUtility.DisplayDialogComplex("Failed to load window layout", "This can happen if layout contains custom windows and there are compile errors in the project.", "Load Default Layout", "Quit", "Revert Factory Settings"))
                {
                case 0:
                    WindowLayout.LoadDefaultLayout();
                    break;

                case 1:
                    EditorApplication.Exit(0);
                    break;

                case 2:
                    WindowLayout.RevertFactorySettings();
                    break;
                }
                return(false);
            }
            finally
            {
                ContainerWindow.SetFreezeDisplay(false);
                if (Path.GetExtension(path) == ".wlt")
                {
                    Toolbar.lastLoadedLayoutName = Path.GetFileNameWithoutExtension(path);
                }
                else
                {
                    Toolbar.lastLoadedLayoutName = null;
                }
            }
            return(true);
        }
Exemplo n.º 5
0
        public static void Unmaximize(EditorWindow win)
        {
            HostView parent1 = win.m_Parent;

            if ((UnityEngine.Object)parent1 == (UnityEngine.Object)null)
            {
                UnityEngine.Debug.LogError((object)"Host view was not found");
                WindowLayout.RevertFactorySettings();
            }
            else
            {
                UnityEngine.Object[] objectArray = InternalEditorUtility.LoadSerializedFileAndForget(Path.Combine(WindowLayout.layoutsProjectPath, "CurrentMaximizeLayout.dwlt"));
                if (objectArray.Length < 2)
                {
                    UnityEngine.Debug.Log((object)"Maximized serialized file backup not found");
                    WindowLayout.RevertFactorySettings();
                }
                else
                {
                    SplitView    splitView = objectArray[0] as SplitView;
                    EditorWindow pane      = objectArray[1] as EditorWindow;
                    if ((UnityEngine.Object)splitView == (UnityEngine.Object)null)
                    {
                        UnityEngine.Debug.Log((object)"Maximization failed because the root split view was not found");
                        WindowLayout.RevertFactorySettings();
                    }
                    else
                    {
                        ContainerWindow window = win.m_Parent.window;
                        if ((UnityEngine.Object)window == (UnityEngine.Object)null)
                        {
                            UnityEngine.Debug.Log((object)"Maximization failed because the root split view has no container window");
                            WindowLayout.RevertFactorySettings();
                        }
                        else
                        {
                            try
                            {
                                ContainerWindow.SetFreezeDisplay(true);
                                if (!(bool)((UnityEngine.Object)parent1.parent))
                                {
                                    throw new Exception();
                                }
                                int  idx1     = parent1.parent.IndexOfChild((View)parent1);
                                Rect position = parent1.position;
                                View parent2  = parent1.parent;
                                parent2.RemoveChild(idx1);
                                parent2.AddChild((View)splitView, idx1);
                                splitView.position = position;
                                DockArea parent3 = pane.m_Parent as DockArea;
                                int      idx2    = parent3.m_Panes.IndexOf(pane);
                                parent1.actualView = (EditorWindow)null;
                                win.m_Parent       = (HostView)null;
                                parent3.AddTab(idx2, win);
                                parent3.RemoveTab(pane);
                                UnityEngine.Object.DestroyImmediate((UnityEngine.Object)pane);
                                foreach (UnityEngine.Object @object in objectArray)
                                {
                                    EditorWindow editorWindow = @object as EditorWindow;
                                    if ((UnityEngine.Object)editorWindow != (UnityEngine.Object)null)
                                    {
                                        editorWindow.MakeParentsSettingsMatchMe();
                                    }
                                }
                                parent2.Initialize(parent2.window);
                                parent2.position = parent2.position;
                                splitView.Reflow();
                                UnityEngine.Object.DestroyImmediate((UnityEngine.Object)parent1);
                                win.Focus();
                                window.DisplayAllViews();
                                win.m_Parent.MakeVistaDWMHappyDance();
                            }
                            catch (Exception ex)
                            {
                                UnityEngine.Debug.Log((object)("Maximization failed: " + (object)ex));
                                WindowLayout.RevertFactorySettings();
                            }
                            try
                            {
                                if (Application.platform != RuntimePlatform.OSXEditor || !SystemInfo.operatingSystem.Contains("10.7") || !SystemInfo.graphicsDeviceVendor.Contains("ATI"))
                                {
                                    return;
                                }
                                foreach (GUIView guiView in Resources.FindObjectsOfTypeAll(typeof(GUIView)))
                                {
                                    guiView.Repaint();
                                }
                            }
                            finally
                            {
                                ContainerWindow.SetFreezeDisplay(false);
                            }
                        }
                    }
                }
            }
        }