Inheritance: HostView, IDropArea
示例#1
0
        internal bool ShowNextTabIfPossible()
        {
            DockArea dockArea = this.m_Parent as DockArea;
            bool     result;

            if (dockArea)
            {
                int num = dockArea.m_Panes.IndexOf(this);
                num = (num + 1) % dockArea.m_Panes.Count;
                if (dockArea.selected != num)
                {
                    dockArea.selected = num;
                    dockArea.Repaint();
                    result = true;
                    return(result);
                }
            }
            result = false;
            return(result);
        }
示例#2
0
 internal static void InitPlaymodeLayout()
 {
     EditorApplicationLayout.m_GameView = (WindowLayout.ShowAppropriateViewOnEnterExitPlaymode(true) as GameView);
     if (!(EditorApplicationLayout.m_GameView == null))
     {
         if (EditorApplicationLayout.m_GameView.maximizeOnPlay)
         {
             DockArea dockArea = EditorApplicationLayout.m_GameView.m_Parent as DockArea;
             if (dockArea != null)
             {
                 ContainerWindow window = dockArea.actualView.m_Parent.window;
                 if (!window.maximized)
                 {
                     EditorApplicationLayout.m_MaximizePending = WindowLayout.MaximizePrepare(dockArea.actualView);
                 }
             }
         }
         EditorApplicationLayout.m_GameView.m_Parent.SetAsStartView();
         Toolbar.RepaintToolbar();
     }
 }
        public static void AddSplitViewAndChildrenRecurse(View splitview, ArrayList list)
        {
            list.Add(splitview);
            DockArea dock = splitview as DockArea;

            if (dock != null)
            {
                list.AddRange(dock.m_Panes);

                HostView host = splitview as DockArea;
                if (host != null)
                {
                    list.Add(dock.actualView);
                }
            }

            foreach (View child in splitview.children)
            {
                AddSplitViewAndChildrenRecurse(child, list);
            }
        }
示例#4
0
        public static void AddSplitViewAndChildrenRecurse(View splitview, ArrayList list)
        {
            list.Add(splitview);
            DockArea dockArea = splitview as DockArea;

            if (dockArea != null)
            {
                list.AddRange(dockArea.m_Panes);
            }
            HostView x = splitview as DockArea;

            if (x != null)
            {
                list.Add(dockArea.actualView);
            }
            View[] children = splitview.children;
            for (int i = 0; i < children.Length; i++)
            {
                View splitview2 = children[i];
                WindowLayout.AddSplitViewAndChildrenRecurse(splitview2, list);
            }
        }
示例#5
0
 internal static EditorWindow TryGetLastFocusedWindowInSameDock()
 {
     System.Type type = null;
     string lastWindowTypeInSameDock = WindowFocusState.instance.m_LastWindowTypeInSameDock;
     if (lastWindowTypeInSameDock != "")
     {
         type = System.Type.GetType(lastWindowTypeInSameDock);
     }
     GameView view = FindEditorWindowOfType(typeof(GameView)) as GameView;
     if (((type != null) && (view != null)) && ((view.m_Parent != null) && (view.m_Parent is DockArea)))
     {
         object[] objArray = UnityEngine.Resources.FindObjectsOfTypeAll(type);
         DockArea parent = view.m_Parent as DockArea;
         for (int i = 0; i < objArray.Length; i++)
         {
             EditorWindow window = objArray[i] as EditorWindow;
             if ((window != null) && (window.m_Parent == parent))
             {
                 return window;
             }
         }
     }
     return null;
 }
        static internal void InitPlaymodeLayout()
        {
            m_PreviewWindow = WindowLayout.ShowAppropriateViewOnEnterExitPlaymode(true) as PreviewEditorWindow;
            if (m_PreviewWindow == null)
            {
                return;
            }

            if (m_PreviewWindow.maximizeOnPlay)
            {
                DockArea da = m_PreviewWindow.m_Parent as DockArea;

                if (da != null)
                {
                    m_MaximizePending = WindowLayout.MaximizePrepare(da.actualView);
                }
            }

            // Mark this preview window as the start preview so the backend
            // can set size and mouseoffset properly for this preview
            m_PreviewWindow.m_Parent.SetAsStartView();

            Toolbar.RepaintToolbar();
        }
示例#7
0
        private bool AllowTabAction()
        {
            int mainWindowPaneCount = 0;

            ContainerWindow w = ContainerWindow.windows.FirstOrDefault(e => e.showMode == ShowMode.MainWindow);

            if (w != null)
            {
                foreach (View view in w.rootView.allChildren)
                {
                    DockArea da = view as DockArea;
                    if (da != null)
                    {
                        mainWindowPaneCount += da.m_Panes.Count;
                        if (mainWindowPaneCount > 1)
                        {
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
示例#8
0
        public void OnGUI()
        {
            this.ClearBackground();
            EditorGUIUtility.ResetGUIState();
            SplitView parent = this.parent as SplitView;

            if (Event.current.type == EventType.Repaint && (bool)((UnityEngine.Object)parent))
            {
                View child = (View)this;
                for (; (bool)((UnityEngine.Object)parent); parent = parent.parent as SplitView)
                {
                    int controlId = parent.controlID;
                    if (controlId == GUIUtility.hotControl || GUIUtility.hotControl == 0)
                    {
                        int num = parent.IndexOfChild(child);
                        if (parent.vertical)
                        {
                            if (num != 0)
                            {
                                EditorGUIUtility.AddCursorRect(new Rect(0.0f, 0.0f, this.position.width, 5f), MouseCursor.SplitResizeUpDown, controlId);
                            }
                            if (num != parent.children.Length - 1)
                            {
                                EditorGUIUtility.AddCursorRect(new Rect(0.0f, this.position.height - 5f, this.position.width, 5f), MouseCursor.SplitResizeUpDown, controlId);
                            }
                        }
                        else
                        {
                            if (num != 0)
                            {
                                EditorGUIUtility.AddCursorRect(new Rect(0.0f, 0.0f, 5f, this.position.height), MouseCursor.SplitResizeLeftRight, controlId);
                            }
                            if (num != parent.children.Length - 1)
                            {
                                EditorGUIUtility.AddCursorRect(new Rect(this.position.width - 5f, 0.0f, 5f, this.position.height), MouseCursor.SplitResizeLeftRight, controlId);
                            }
                        }
                    }
                    child = (View)parent;
                }
                parent = this.parent as SplitView;
            }
            bool flag = false;

            if (this.window.mainView.GetType() != typeof(MainWindow))
            {
                flag = true;
                if ((double)this.windowPosition.y == 0.0)
                {
                    this.background = (GUIStyle)"dockareaStandalone";
                }
                else
                {
                    this.background = (GUIStyle)"dockarea";
                }
            }
            else
            {
                this.background = (GUIStyle)"dockarea";
            }
            if ((bool)((UnityEngine.Object)parent))
            {
                Event evt = new Event(Event.current);
                evt.mousePosition += new Vector2(this.position.x, this.position.y);
                parent.SplitGUI(evt);
                if (evt.type == EventType.Used)
                {
                    Event.current.Use();
                }
            }
            GUIStyle style    = (GUIStyle)"dockareaoverlay";
            Rect     position = this.background.margin.Remove(new Rect(0.0f, 0.0f, this.position.width, this.position.height));

            position.x = (float)this.background.margin.left;
            position.y = (float)this.background.margin.top;
            Rect  windowPosition = this.windowPosition;
            float num1           = 2f;

            if ((double)windowPosition.x == 0.0)
            {
                position.x     -= num1;
                position.width += num1;
            }
            if ((double)windowPosition.xMax == (double)this.window.position.width)
            {
                position.width += num1;
            }
            if ((double)windowPosition.yMax == (double)this.window.position.height)
            {
                position.height += !flag ? 2f : 2f;
            }
            GUI.Box(position, GUIContent.none, this.background);
            if (this.tabStyle == null)
            {
                this.tabStyle = (GUIStyle)"dragtab";
            }
            this.DragTab(new Rect(position.x + 1f, position.y, position.width - 40f, 17f), this.tabStyle);
            this.tabStyle = (GUIStyle)"dragtab";
            this.ShowGenericMenu();
            this.DoWindowDecorationStart();
            if (this.m_Panes.Count > 0)
            {
                if (this.m_Panes[this.selected] is GameView)
                {
                    GUI.Box(position, GUIContent.none, style);
                }
                DockArea.BeginOffsetArea(new Rect(position.x + 2f, position.y + 17f, position.width - 4f, (float)((double)position.height - 17.0 - 2.0)), GUIContent.none, (GUIStyle)"TabWindowBackground");
                Vector2 screenPoint = GUIUtility.GUIToScreenPoint(Vector2.zero);
                Rect    rect        = this.borderSize.Remove(this.position);
                rect.x = screenPoint.x;
                rect.y = screenPoint.y;
                this.m_Panes[this.selected].m_Pos = rect;
                EditorGUIUtility.ResetGUIState();
                try
                {
                    this.Invoke("OnGUI");
                }
                catch (TargetInvocationException ex)
                {
                    throw ex.InnerException;
                }
                EditorGUIUtility.ResetGUIState();
                if ((UnityEngine.Object) this.actualView != (UnityEngine.Object)null && (double)this.actualView.m_FadeoutTime != 0.0 && (Event.current != null && Event.current.type == EventType.Repaint))
                {
                    this.actualView.DrawNotification();
                }
                DockArea.EndOffsetArea();
            }
            this.DoWindowDecorationEnd();
            GUI.Box(position, GUIContent.none, style);
            EditorGUI.ShowRepaints();
            Highlighter.ControlHighlightGUI((GUIView)this);
        }
示例#9
0
        private float DragTab(Rect tabAreaRect, float scrollOffset, GUIStyle tabStyle, GUIStyle firstTabStyle)
        {
            Event evt = Event.current;
            int   id  = GUIUtility.GetControlID(FocusType.Passive);

            // Detect if hotcontrol was cleared while dragging (happens when pressing Esc).
            // We do not listen for the Escape keydown event because it is sent to the dragged window (not this dockarea)
            if (s_DragMode != 0 && GUIUtility.hotControl == 0)
            {
                PaneDragTab.get.Close();
                ResetDragVars();
            }

            float xPos = 0f;

            switch (evt.GetTypeForControl(id))
            {
            case EventType.MouseDown:
                if (GUIUtility.hotControl == 0)
                {
                    int sel = GetTabAtMousePos(tabStyle, evt.mousePosition, scrollOffset, tabAreaRect);
                    if (sel != -1 && sel < m_Panes.Count)
                    {
                        switch (evt.button)
                        {
                        case 0:
                            if (selected != sel)
                            {
                                selected = sel;
                            }

                            GUIUtility.hotControl = id;
                            s_StartDragPosition   = evt.mousePosition;
                            s_DragMode            = 0;
                            evt.Use();
                            break;

                        case 2:
                            m_Panes[sel].Close();
                            evt.Use();
                            break;
                        }
                    }
                }
                break;

            case EventType.ContextClick:
                if (GUIUtility.hotControl == 0)
                {
                    int sel     = GetTabAtMousePos(tabStyle, evt.mousePosition, scrollOffset, tabAreaRect);
                    var menuPos = new Rect(evt.mousePosition.x, evt.mousePosition.y, 0, 0);
                    if (sel != -1 && sel < m_Panes.Count && !ContainerWindow.s_Modal)
                    {
                        PopupGenericMenu(m_Panes[sel], menuPos);
                    }
                    else if (!ContainerWindow.s_Modal && m_Panes.Count == 0)     // i.e. all panes have failed to load
                    {
                        PopupGenericMenu(null, menuPos);
                    }
                }
                break;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == id)
                {
                    Vector2 delta = evt.mousePosition - s_StartDragPosition;
                    evt.Use();
                    Rect screenRect = screenPosition;

                    // if we're not tab dragging yet, check to see if we should start

                    // If modal window exists, disable all tab behavior
                    if (ContainerWindow.s_Modal)
                    {
                        break;
                    }

                    // check if we're allowed to drag tab
                    bool dragAllowed = (window.showMode != ShowMode.MainWindow || AllowTabAction());

                    if (s_DragMode == 0 && delta.sqrMagnitude > 99 && dragAllowed)
                    {
                        s_DragMode       = 1;
                        s_PlaceholderPos = selected;
                        s_DragPane       = m_Panes[selected];

                        // If we're moving the only editorwindow in this dockarea, we'll be destroyed - so it looks silly if we can attach as children of ourselves
                        s_IgnoreDockingForView = m_Panes.Count == 1 ? this : null;

                        s_OriginalDragSource = this;
                        float tabWidth = GetTabWidth(tabStyle, selected);
                        PaneDragTab.get.Show(
                            new Rect(tabAreaRect.x + screenRect.x + tabWidth * selected, tabAreaRect.y + screenRect.y, tabWidth, tabAreaRect.height - 1f),
                            s_DragPane.titleContent,
                            position.size,
                            GUIUtility.GUIToScreenPoint(evt.mousePosition)
                            );
                        EditorApplication.update += CheckDragWindowExists;
                        Invoke("OnTabDragging", s_DragPane);

                        // We just showed a window. Exit the GUI because the window might be
                        // repainting already (esp. on Windows)
                        GUIUtility.ExitGUI();
                    }
                    if (s_DragMode == 1)
                    {
                        // Go over all container windows, ask them to dock the window.
                        DropInfo          di             = null;
                        ContainerWindow[] windows        = ContainerWindow.windows;
                        Vector2           screenMousePos = GUIUtility.GUIToScreenPoint(evt.mousePosition);
                        ContainerWindow   win            = null;
                        foreach (ContainerWindow w in windows)
                        {
                            var rootSplitView = w.rootSplitView;
                            if (rootSplitView == null)
                            {
                                continue;
                            }

                            di = rootSplitView.DragOverRootView(screenMousePos);

                            if (di == null)
                            {
                                foreach (View view in w.rootView.allChildren)
                                {
                                    IDropArea ida = view as IDropArea;
                                    if (ida != null)
                                    {
                                        di = ida.DragOver(s_DragPane, screenMousePos);
                                    }

                                    if (di != null)
                                    {
                                        break;
                                    }
                                }
                            }

                            if (di != null)
                            {
                                win = w;
                                break;
                            }
                        }
                        // Ok, we couldn't find anything, let's create a simplified DropIn
                        if (di == null)
                        {
                            di = new DropInfo(null);
                        }

                        if (di.type != DropInfo.Type.Tab)
                        {
                            s_PlaceholderPos = -1;
                        }

                        s_DropInfo = di;

                        // Handle the window getting closed mid-drag
                        if (PaneDragTab.get.m_Window)
                        {
                            PaneDragTab.get.SetDropInfo(di, screenMousePos, win);
                        }
                    }
                }
                break;

            case EventType.MouseUp:
                if (GUIUtility.hotControl == id)
                {
                    Vector2 screenMousePos = GUIUtility.GUIToScreenPoint(evt.mousePosition);
                    if (s_DragMode != 0)
                    {
                        // This is where we want to insert it.
                        s_DragMode = 0;
                        PaneDragTab.get.Close();
                        EditorApplication.update -= CheckDragWindowExists;

                        // Try to tell the current DPZ
                        if (s_DropInfo?.dropArea != null)
                        {
                            Invoke("OnTabDetached", s_DragPane);
                            s_DropInfo.dropArea.PerformDrop(s_DragPane, s_DropInfo, screenMousePos);

                            UpdateWindowTitle(s_DragPane);
                        }
                        else
                        {
                            EditorWindow w = s_DragPane;

                            ResetDragVars();

                            // The active tab that we're moving to the new window stays focused at all times.
                            // Do not remove focus from the tab being detached.
                            RemoveTab(w, killIfEmpty: true, sendEvents: false);
                            Rect wPos = w.position;
                            wPos.x = screenMousePos.x - wPos.width * .5f;
                            wPos.y = screenMousePos.y - wPos.height * .5f;

                            // don't put windows top outside of the screen, on mac OS handles this
                            if (Application.platform == RuntimePlatform.WindowsEditor)
                            {
                                wPos.y = Mathf.Max(InternalEditorUtility.GetBoundsOfDesktopAtPoint(screenMousePos).y, wPos.y);
                            }

                            // Don't call OnFocus on the tab when it is moved to the new window
                            EditorWindow.CreateNewWindowForEditorWindow(w, loadPosition: false, showImmediately: false, setFocus: false);

                            w.position = w.m_Parent.window.FitWindowRectToScreen(wPos, true, true);
                            Invoke("OnTabNewWindow", w);

                            GUIUtility.hotControl = 0;
                            GUIUtility.ExitGUI();
                        }
                        ResetDragVars();
                    }

                    GUIUtility.hotControl = 0;
                    evt.Use();
                }

                break;

            case EventType.Repaint:
                xPos = tabAreaRect.xMin;
                if (actualView)
                {
                    for (int i = 0, drawNum = 0; i < m_Panes.Count; i++)
                    {
                        // If we're dragging the tab we're about to draw, don't do that (handled by some window)
                        if (s_DragPane == m_Panes[i])
                        {
                            continue;
                        }

                        // If we need space for inserting a tab here, skip some horizontal
                        if (s_DropInfo != null && ReferenceEquals(s_DropInfo.dropArea, this) && s_PlaceholderPos == drawNum)
                        {
                            xPos += s_DropInfo.rect.width;
                        }

                        var style = i == 0 ? firstTabStyle : tabStyle;
                        xPos += DrawTab(tabAreaRect, style, i, xPos);
                        drawNum++;
                    }
                }
                else
                {
                    Rect  r      = new Rect(xPos, tabAreaRect.yMin, Styles.tabDragWidth, tabAreaRect.height);
                    float roundR = Mathf.Round(r.x);
                    Rect  r2     = new Rect(roundR, r.y, Mathf.Round(r.x + r.width) - roundR, r.height);
                    tabStyle.Draw(r2, "Failed to load", false, true, true, false);
                }
                break;
            }
            selected = Mathf.Clamp(selected, 0, m_Panes.Count - 1);

            return(xPos);
        }
示例#10
0
 private static void ResetDragVars()
 {
   DockArea.s_DragPane = (EditorWindow) null;
   DockArea.s_DropInfo = (DropInfo) null;
   DockArea.s_PlaceholderPos = -1;
   DockArea.s_DragMode = 0;
   DockArea.s_OriginalDragSource = (DockArea) null;
 }
示例#11
0
        private void DragTab(Rect pos, GUIStyle tabStyle)
        {
            int   controlID = GUIUtility.GetControlID(FocusType.Passive);
            float tabWidth  = this.GetTabWidth(pos.width);
            Event current   = Event.current;

            if ((s_DragMode != 0) && (GUIUtility.hotControl == 0))
            {
                PaneDragTab.get.Close();
                ResetDragVars();
            }
            EventType typeForControl = current.GetTypeForControl(controlID);

            switch (typeForControl)
            {
            case EventType.MouseDown:
                if (pos.Contains(current.mousePosition) && (GUIUtility.hotControl == 0))
                {
                    int tabAtMousePos = this.GetTabAtMousePos(current.mousePosition, pos);
                    if (tabAtMousePos < this.m_Panes.Count)
                    {
                        switch (current.button)
                        {
                        case 0:
                            if (tabAtMousePos != this.selected)
                            {
                                this.selected = tabAtMousePos;
                            }
                            GUIUtility.hotControl = controlID;
                            s_StartDragPosition   = current.mousePosition;
                            s_DragMode            = 0;
                            current.Use();
                            break;

                        case 2:
                            this.m_Panes[tabAtMousePos].Close();
                            current.Use();
                            break;
                        }
                    }
                }
                goto Label_06B9;

            case EventType.MouseUp:
                if (GUIUtility.hotControl == controlID)
                {
                    Vector2 vector3 = GUIUtility.GUIToScreenPoint(current.mousePosition);
                    if (s_DragMode != 0)
                    {
                        s_DragMode = 0;
                        PaneDragTab.get.Close();
                        EditorApplication.update = (EditorApplication.CallbackFunction)Delegate.Remove(EditorApplication.update, new EditorApplication.CallbackFunction(DockArea.CheckDragWindowExists));
                        if ((s_DropInfo == null) || (s_DropInfo.dropArea == null))
                        {
                            EditorWindow pane = s_DragPane;
                            ResetDragVars();
                            this.RemoveTab(pane);
                            Rect position = pane.position;
                            position.x = vector3.x - (position.width * 0.5f);
                            position.y = vector3.y - (position.height * 0.5f);
                            if (Application.platform == RuntimePlatform.WindowsEditor)
                            {
                                position.y = Mathf.Max(InternalEditorUtility.GetBoundsOfDesktopAtPoint(vector3).y, position.y);
                            }
                            EditorWindow.CreateNewWindowForEditorWindow(pane, false, false);
                            pane.position         = pane.m_Parent.window.FitWindowRectToScreen(position, true, true);
                            GUIUtility.hotControl = 0;
                            GUIUtility.ExitGUI();
                        }
                        else
                        {
                            s_DropInfo.dropArea.PerformDrop(s_DragPane, s_DropInfo, vector3);
                        }
                        ResetDragVars();
                    }
                    GUIUtility.hotControl = 0;
                    current.Use();
                }
                goto Label_06B9;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == controlID)
                {
                    Vector2 vector = current.mousePosition - s_StartDragPosition;
                    current.Use();
                    Rect screenPosition = base.screenPosition;
                    if ((s_DragMode == 0) && (vector.sqrMagnitude > 99f))
                    {
                        s_DragMode       = 1;
                        s_PlaceholderPos = this.selected;
                        s_DragPane       = this.m_Panes[this.selected];
                        if (this.m_Panes.Count != 1)
                        {
                            s_IgnoreDockingForView = null;
                        }
                        else
                        {
                            s_IgnoreDockingForView = this;
                        }
                        s_OriginalDragSource    = this;
                        PaneDragTab.get.content = s_DragPane.titleContent;
                        base.Internal_SetAsActiveWindow();
                        PaneDragTab.get.GrabThumbnail();
                        PaneDragTab.get.Show(new Rect((pos.x + screenPosition.x) + (tabWidth * this.selected), pos.y + screenPosition.y, tabWidth, pos.height), GUIUtility.GUIToScreenPoint(current.mousePosition));
                        EditorApplication.update = (EditorApplication.CallbackFunction)Delegate.Combine(EditorApplication.update, new EditorApplication.CallbackFunction(DockArea.CheckDragWindowExists));
                        GUIUtility.ExitGUI();
                    }
                    if (s_DragMode == 1)
                    {
                        DropInfo          di        = null;
                        ContainerWindow[] windows   = ContainerWindow.windows;
                        Vector2           screenPos = GUIUtility.GUIToScreenPoint(current.mousePosition);
                        ContainerWindow   inFrontOf = null;
                        foreach (ContainerWindow window2 in windows)
                        {
                            foreach (View view in window2.mainView.allChildren)
                            {
                                IDropArea area = view as IDropArea;
                                if (area != null)
                                {
                                    di = area.DragOver(s_DragPane, screenPos);
                                }
                                if (di != null)
                                {
                                    break;
                                }
                            }
                            if (di != null)
                            {
                                inFrontOf = window2;
                                break;
                            }
                        }
                        if (di == null)
                        {
                            di = new DropInfo(null);
                        }
                        if (di.type != DropInfo.Type.Tab)
                        {
                            s_PlaceholderPos = -1;
                        }
                        s_DropInfo = di;
                        if (PaneDragTab.get.m_Window != null)
                        {
                            PaneDragTab.get.SetDropInfo(di, screenPos, inFrontOf);
                        }
                    }
                }
                goto Label_06B9;

            case EventType.Repaint:
            {
                float xMin = pos.xMin;
                int   num8 = 0;
                if (base.actualView == null)
                {
                    Rect  rect5 = new Rect(xMin, pos.yMin, tabWidth, pos.height);
                    float x     = Mathf.Round(rect5.x);
                    Rect  rect6 = new Rect(x, rect5.y, Mathf.Round(rect5.x + rect5.width) - x, rect5.height);
                    tabStyle.Draw(rect6, "Failed to load", false, false, true, false);
                }
                else
                {
                    for (int i = 0; i < this.m_Panes.Count; i++)
                    {
                        if (s_DragPane != this.m_Panes[i])
                        {
                            if (((s_DropInfo != null) && object.ReferenceEquals(s_DropInfo.dropArea, this)) && (s_PlaceholderPos == num8))
                            {
                                xMin += tabWidth;
                            }
                            Rect  rect3 = new Rect(xMin, pos.yMin, tabWidth, pos.height);
                            float num10 = Mathf.Round(rect3.x);
                            Rect  rect4 = new Rect(num10, rect3.y, Mathf.Round(rect3.x + rect3.width) - num10, rect3.height);
                            tabStyle.Draw(rect4, this.m_Panes[i].titleContent, false, false, i == this.selected, base.hasFocus);
                            xMin += tabWidth;
                            num8++;
                        }
                    }
                }
                goto Label_06B9;
            }
            }
            if ((typeForControl == EventType.ContextClick) && (pos.Contains(current.mousePosition) && (GUIUtility.hotControl == 0)))
            {
                int num4 = this.GetTabAtMousePos(current.mousePosition, pos);
                if (num4 < this.m_Panes.Count)
                {
                    base.PopupGenericMenu(this.m_Panes[num4], new Rect(current.mousePosition.x, current.mousePosition.y, 0f, 0f));
                }
            }
Label_06B9:
            this.selected = Mathf.Clamp(this.selected, 0, this.m_Panes.Count - 1);
        }
示例#12
0
        public bool PerformDrop(EditorWindow w, DropInfo di, Vector2 screenPos)
        {
            int      num      = (int)di.userData;
            DockArea dockArea = ScriptableObject.CreateInstance <DockArea>();
            Rect     rect     = di.rect;

            if (num == -1 || num == -2 || num == -3)
            {
                bool flag  = num == -2;
                bool flag2 = num == -1;
                this.splitState = null;
                if (this.vertical == flag2 || base.children.Length < 2)
                {
                    this.vertical = flag2;
                    rect.x       -= base.screenPosition.x;
                    rect.y       -= base.screenPosition.y;
                    this.MakeRoomForRect(rect);
                    this.AddChild(dockArea, (!flag) ? base.children.Length : 0);
                    dockArea.position = rect;
                }
                else
                {
                    SplitView splitView = ScriptableObject.CreateInstance <SplitView>();
                    Rect      position  = base.position;
                    splitView.vertical = flag2;
                    splitView.position = new Rect(position.x, position.y, position.width, position.height);
                    if (base.window.mainView == this)
                    {
                        base.window.mainView = splitView;
                    }
                    else
                    {
                        base.parent.AddChild(splitView, base.parent.IndexOfChild(this));
                    }
                    splitView.AddChild(this);
                    base.position = new Rect(0f, 0f, position.width, position.height);
                    Rect rect2 = rect;
                    rect2.x -= base.screenPosition.x;
                    rect2.y -= base.screenPosition.y;
                    splitView.MakeRoomForRect(rect2);
                    dockArea.position = rect2;
                    splitView.AddChild(dockArea, (!flag) ? 1 : 0);
                }
            }
            else
            {
                if (num < 1000)
                {
                    Rect rect3 = rect;
                    rect3.x -= base.screenPosition.x;
                    rect3.y -= base.screenPosition.y;
                    this.MakeRoomForRect(rect3);
                    this.AddChild(dockArea, num);
                    dockArea.position = rect3;
                }
                else
                {
                    int num2 = num % 1000;
                    if (base.children.Length != 1)
                    {
                        SplitView splitView2 = ScriptableObject.CreateInstance <SplitView>();
                        splitView2.vertical = !this.vertical;
                        Rect position2 = base.children[num2].position;
                        splitView2.AddChild(base.children[num2]);
                        this.AddChild(splitView2, num2);
                        splitView2.position = position2;
                        float num3 = 0f;
                        position2.y = num3;
                        position2.x = num3;
                        splitView2.children[0].position = position2;
                        Rect rect4 = rect;
                        rect4.x -= splitView2.screenPosition.x;
                        rect4.y -= splitView2.screenPosition.y;
                        splitView2.MakeRoomForRect(rect4);
                        splitView2.AddChild(dockArea, (num >= 2000) ? 1 : 0);
                        dockArea.position = rect4;
                    }
                    else
                    {
                        this.vertical = !this.vertical;
                        Rect rect5 = rect;
                        rect5.x -= base.screenPosition.x;
                        rect5.y -= base.screenPosition.y;
                        this.MakeRoomForRect(rect5);
                        this.AddChild(dockArea, (num != 1000) ? 1 : 0);
                        dockArea.position = rect5;
                    }
                }
            }
            DockArea.s_OriginalDragSource.RemoveTab(w);
            w.m_Parent = dockArea;
            dockArea.AddTab(w);
            this.Reflow();
            SplitView.RecalcMinMaxAndReflowAll(this);
            dockArea.MakeVistaDWMHappyDance();
            return(true);
        }
        public static void Unmaximize(EditorWindow win)
        {
            HostView maximizedHostView = win.m_Parent;

            if (maximizedHostView == null)
            {
                Debug.LogError("Host view was not found");
                RevertFactorySettings();
                return;
            }

            UnityObject[] newWindows = InternalEditorUtility.LoadSerializedFileAndForget(Path.Combine(layoutsProjectPath, kMaximizeRestoreFile));

            if (newWindows.Length < 2)
            {
                Debug.Log("Maximized serialized file backup not found");
                RevertFactorySettings();
                return;
            }

            SplitView    oldRoot   = newWindows[0] as SplitView;
            EditorWindow oldWindow = newWindows[1] as EditorWindow;

            if (oldRoot == null)
            {
                Debug.Log("Maximization failed because the root split view was not found");
                RevertFactorySettings();
                return;
            }

            ContainerWindow parentWindow = win.m_Parent.window;

            if (parentWindow == null)
            {
                Debug.Log("Maximization failed because the root split view has no container window");
                RevertFactorySettings();
                return;
            }

            try
            {
                ContainerWindow.SetFreezeDisplay(true);

                // Put the loaded SplitView where the MaximizedHostView was
                if (maximizedHostView.parent)
                {
                    int  i      = maximizedHostView.parent.IndexOfChild(maximizedHostView);
                    Rect r      = maximizedHostView.position;
                    View parent = maximizedHostView.parent;
                    parent.RemoveChild(i);
                    parent.AddChild(oldRoot, i);
                    oldRoot.position = r;

                    // Move the Editor Window to the right spot in the
                    DockArea newDockArea = oldWindow.m_Parent as DockArea;

                    int oldDockAreaIndex = newDockArea.m_Panes.IndexOf(oldWindow);

                    maximizedHostView.actualView = null;
                    win.m_Parent = null;
                    newDockArea.AddTab(oldDockAreaIndex, win);
                    newDockArea.RemoveTab(oldWindow);
                    UnityObject.DestroyImmediate(oldWindow);

                    foreach (UnityObject o in newWindows)
                    {
                        EditorWindow curWin = o as EditorWindow;
                        if (curWin != null)
                        {
                            curWin.MakeParentsSettingsMatchMe();
                        }
                    }

                    parent.Initialize(parent.window);
                    //If parent window had to be resized, call this to make sure new size gets propagated
                    parent.position = parent.position;
                    oldRoot.Reflow();
                }
                else
                {
                    throw new System.Exception();
                }

                // Kill the maximizedMainView
                UnityObject.DestroyImmediate(maximizedHostView);

                win.Focus();

                parentWindow.DisplayAllViews();
                win.m_Parent.MakeVistaDWMHappyDance();
            }
            catch (System.Exception ex)
            {
                Debug.Log("Maximization failed: " + ex);
                RevertFactorySettings();
            }

            try
            {
                // Weird bug on AMD graphic cards under OSX Lion: Sometimes when unmaximizing we get stray white rectangles.
                // work around that by issueing an extra repaint (case 438764)
                if (Application.platform == RuntimePlatform.OSXEditor && SystemInfo.operatingSystem.Contains("10.7") && SystemInfo.graphicsDeviceVendor.Contains("ATI"))
                {
                    foreach (GUIView v in Resources.FindObjectsOfTypeAll(typeof(GUIView)))
                    {
                        v.Repaint();
                    }
                }
            }
            finally
            {
                ContainerWindow.SetFreezeDisplay(false);
            }
        }
示例#14
0
        public void OnGUI()
        {
            base.ClearBackground();
            EditorGUIUtility.ResetGUIState();
            SplitView splitView = base.parent as SplitView;

            if (Event.current.type == EventType.Repaint && splitView)
            {
                View child = this;
                while (splitView)
                {
                    int controlID = splitView.controlID;
                    if (controlID == GUIUtility.hotControl || GUIUtility.hotControl == 0)
                    {
                        int num = splitView.IndexOfChild(child);
                        if (splitView.vertical)
                        {
                            if (num != 0)
                            {
                                EditorGUIUtility.AddCursorRect(new Rect(0f, 0f, base.position.width, 5f), MouseCursor.SplitResizeUpDown, controlID);
                            }
                            if (num != splitView.children.Length - 1)
                            {
                                EditorGUIUtility.AddCursorRect(new Rect(0f, base.position.height - 5f, base.position.width, 5f), MouseCursor.SplitResizeUpDown, controlID);
                            }
                        }
                        else
                        {
                            if (num != 0)
                            {
                                EditorGUIUtility.AddCursorRect(new Rect(0f, 0f, 5f, base.position.height), MouseCursor.SplitResizeLeftRight, controlID);
                            }
                            if (num != splitView.children.Length - 1)
                            {
                                EditorGUIUtility.AddCursorRect(new Rect(base.position.width - 5f, 0f, 5f, base.position.height), MouseCursor.SplitResizeLeftRight, controlID);
                            }
                        }
                    }
                    child     = splitView;
                    splitView = (splitView.parent as SplitView);
                }
                splitView = (base.parent as SplitView);
            }
            bool flag = false;

            if (base.window.mainView.GetType() != typeof(MainWindow))
            {
                flag = true;
                if (base.windowPosition.y == 0f)
                {
                    this.background = "dockareaStandalone";
                }
                else
                {
                    this.background = "dockarea";
                }
            }
            else
            {
                this.background = "dockarea";
            }
            if (splitView)
            {
                Event @event = new Event(Event.current);
                @event.mousePosition += new Vector2(base.position.x, base.position.y);
                splitView.SplitGUI(@event);
                if (@event.type == EventType.Used)
                {
                    Event.current.Use();
                }
            }
            GUIStyle style    = "dockareaoverlay";
            Rect     position = this.background.margin.Remove(new Rect(0f, 0f, base.position.width, base.position.height));

            position.x = (float)this.background.margin.left;
            position.y = (float)this.background.margin.top;
            Rect  windowPosition = base.windowPosition;
            float num2           = 2f;

            if (windowPosition.x == 0f)
            {
                position.x     -= num2;
                position.width += num2;
            }
            if (windowPosition.xMax == base.window.position.width)
            {
                position.width += num2;
            }
            if (windowPosition.yMax == base.window.position.height)
            {
                position.height += ((!flag) ? 2f : 2f);
            }
            GUI.Box(position, GUIContent.none, this.background);
            if (this.tabStyle == null)
            {
                this.tabStyle = "dragtab";
            }
            this.DragTab(new Rect(position.x + 1f, position.y, position.width - 40f, 17f), this.tabStyle);
            this.tabStyle = "dragtab";
            base.ShowGenericMenu();
            base.DoWindowDecorationStart();
            if (this.m_Panes.Count > 0)
            {
                if (this.m_Panes[this.selected] is GameView)
                {
                    GUI.Box(position, GUIContent.none, style);
                }
                DockArea.BeginOffsetArea(new Rect(position.x + 2f, position.y + 17f, position.width - 4f, position.height - 17f - 2f), GUIContent.none, "TabWindowBackground");
                Vector2 vector = GUIUtility.GUIToScreenPoint(Vector2.zero);
                Rect    pos    = base.borderSize.Remove(base.position);
                pos.x = vector.x;
                pos.y = vector.y;
                this.m_Panes[this.selected].m_Pos = pos;
                EditorGUIUtility.ResetGUIState();
                try
                {
                    base.Invoke("OnGUI");
                }
                catch (TargetInvocationException ex)
                {
                    throw ex.InnerException;
                }
                EditorGUIUtility.ResetGUIState();
                if (base.actualView != null && base.actualView.m_FadeoutTime != 0f && Event.current != null && Event.current.type == EventType.Repaint)
                {
                    base.actualView.DrawNotification();
                }
                DockArea.EndOffsetArea();
            }
            base.DoWindowDecorationEnd();
            GUI.Box(position, GUIContent.none, style);
            EditorGUI.ShowRepaints();
            Highlighter.ControlHighlightGUI(this);
        }
示例#15
0
        public bool PerformDrop(EditorWindow dropWindow, DropInfo dropInfo, Vector2 screenPos)
        {
            SplitView.ExtraDropInfo extraDropInfo = dropInfo.userData as SplitView.ExtraDropInfo;
            bool rootWindow = extraDropInfo.rootWindow;

            SplitView.ViewEdge edge = extraDropInfo.edge;
            int       num           = extraDropInfo.index;
            Rect      rect          = dropInfo.rect;
            bool      flag          = (edge & SplitView.ViewEdge.TopLeft) != SplitView.ViewEdge.None;
            bool      flag2         = (edge & SplitView.ViewEdge.FitsVertical) != SplitView.ViewEdge.None;
            SplitView splitView;

            if (this.vertical == flag2 || base.children.Length < 2)
            {
                if (!flag)
                {
                    if (rootWindow)
                    {
                        num = base.children.Length;
                    }
                    else
                    {
                        num++;
                    }
                }
                splitView = this;
            }
            else if (rootWindow)
            {
                SplitView splitView2 = ScriptableObject.CreateInstance <SplitView>();
                splitView2.position = base.position;
                if (base.window.rootView == this)
                {
                    base.window.rootView = splitView2;
                }
                else
                {
                    base.parent.AddChild(splitView2, base.parent.IndexOfChild(this));
                }
                splitView2.AddChild(this);
                base.position = new Rect(Vector2.zero, base.position.size);
                num           = ((!flag) ? 1 : 0);
                splitView     = splitView2;
            }
            else
            {
                SplitView splitView3 = ScriptableObject.CreateInstance <SplitView>();
                splitView3.AddChild(base.children[num]);
                this.AddChild(splitView3, num);
                splitView3.position             = splitView3.children[0].position;
                splitView3.children[0].position = new Rect(Vector2.zero, splitView3.position.size);
                num       = ((!flag) ? 1 : 0);
                splitView = splitView3;
            }
            rect.position -= base.screenPosition.position;
            DockArea dockArea = ScriptableObject.CreateInstance <DockArea>();

            splitView.vertical = flag2;
            splitView.MakeRoomForRect(rect);
            splitView.AddChild(dockArea, num);
            dockArea.position = rect;
            DockArea.s_OriginalDragSource.RemoveTab(dropWindow);
            dropWindow.m_Parent = dockArea;
            dockArea.AddTab(dropWindow);
            this.Reflow();
            SplitView.RecalcMinMaxAndReflowAll(this);
            dockArea.MakeVistaDWMHappyDance();
            return(true);
        }
示例#16
0
        public void SplitGUI(Event evt)
        {
            if (this.splitState == null)
            {
                this.SetupSplitter();
            }
            SplitView splitView = base.parent as SplitView;

            if (splitView)
            {
                Event @event = new Event(evt);
                @event.mousePosition += new Vector2(base.position.x, base.position.y);
                splitView.SplitGUI(@event);
                if (@event.type == EventType.Used)
                {
                    evt.Use();
                }
            }
            float num  = (!this.vertical) ? evt.mousePosition.x : evt.mousePosition.y;
            int   num2 = GUIUtility.GetControlID(546739, FocusType.Passive);

            this.controlID = num2;
            EventType typeForControl = evt.GetTypeForControl(num2);

            if (typeForControl != EventType.MouseDown)
            {
                if (typeForControl != EventType.MouseDrag)
                {
                    if (typeForControl == EventType.MouseUp)
                    {
                        if (GUIUtility.hotControl == num2)
                        {
                            GUIUtility.hotControl = 0;
                        }
                    }
                }
                else if (base.children.Length > 1 && GUIUtility.hotControl == num2 && this.splitState.currentActiveSplitter >= 0)
                {
                    int num3 = (int)num - this.splitState.splitterInitialOffset;
                    if (num3 != 0)
                    {
                        this.splitState.splitterInitialOffset = (int)num;
                        this.splitState.DoSplitter(this.splitState.currentActiveSplitter, this.splitState.currentActiveSplitter + 1, num3);
                    }
                    this.SetupRectsFromSplitter();
                    evt.Use();
                }
            }
            else if (base.children.Length != 1)
            {
                int num4 = (!this.vertical) ? ((int)base.children[0].position.x) : ((int)base.children[0].position.y);
                for (int i = 0; i < base.children.Length - 1; i++)
                {
                    if (i >= this.splitState.realSizes.Length)
                    {
                        DockArea dockArea = GUIView.current as DockArea;
                        string   text     = "Non-dock area " + GUIView.current.GetType();
                        if (dockArea && dockArea.m_Selected < dockArea.m_Panes.Count && dockArea.m_Panes[dockArea.m_Selected])
                        {
                            text = dockArea.m_Panes[dockArea.m_Selected].GetType().ToString();
                        }
                        if (Unsupported.IsDeveloperBuild())
                        {
                            Debug.LogError(string.Concat(new object[]
                            {
                                "Real sizes out of bounds for: ",
                                text,
                                " index: ",
                                i,
                                " RealSizes: ",
                                this.splitState.realSizes.Length
                            }));
                        }
                        this.SetupSplitter();
                    }
                    if (((!this.vertical) ? new Rect((float)(num4 + this.splitState.realSizes[i] - this.splitState.splitSize / 2), base.children[0].position.y, (float)this.splitState.splitSize, base.children[0].position.height) : new Rect(base.children[0].position.x, (float)(num4 + this.splitState.realSizes[i] - this.splitState.splitSize / 2), base.children[0].position.width, (float)this.splitState.splitSize)).Contains(evt.mousePosition))
                    {
                        this.splitState.splitterInitialOffset = (int)num;
                        this.splitState.currentActiveSplitter = i;
                        GUIUtility.hotControl = num2;
                        evt.Use();
                        break;
                    }
                    num4 += this.splitState.realSizes[i];
                }
            }
        }
示例#17
0
        public bool PerformDrop(EditorWindow w, DropInfo di, Vector2 screenPos)
        {
            int      userData = (int)di.userData;
            DockArea child    = ScriptableObject.CreateInstance <DockArea>();
            Rect     r        = di.rect;

            switch (userData)
            {
            case -1:
            case -2:
            case -3:
            {
                bool flag  = userData == -2;
                bool flag2 = userData == -1;
                this.splitState = null;
                if ((this.vertical == flag2) || (base.children.Length < 2))
                {
                    this.vertical = flag2;
                    r.x          -= base.screenPosition.x;
                    r.y          -= base.screenPosition.y;
                    this.MakeRoomForRect(r);
                    this.AddChild(child, !flag ? base.children.Length : 0);
                    child.position = r;
                }
                else
                {
                    SplitView view     = ScriptableObject.CreateInstance <SplitView>();
                    Rect      position = base.position;
                    view.vertical = flag2;
                    view.position = new Rect(position.x, position.y, position.width, position.height);
                    if (base.window.mainView == this)
                    {
                        base.window.mainView = view;
                    }
                    else
                    {
                        base.parent.AddChild(view, base.parent.IndexOfChild(this));
                    }
                    view.AddChild(this);
                    base.position = new Rect(0f, 0f, position.width, position.height);
                    Rect rect3 = r;
                    rect3.x -= base.screenPosition.x;
                    rect3.y -= base.screenPosition.y;
                    view.MakeRoomForRect(rect3);
                    child.position = rect3;
                    view.AddChild(child, !flag ? 1 : 0);
                }
                break;
            }

            default:
                if (userData < 0x3e8)
                {
                    Rect rect4 = r;
                    rect4.x -= base.screenPosition.x;
                    rect4.y -= base.screenPosition.y;
                    this.MakeRoomForRect(rect4);
                    this.AddChild(child, userData);
                    child.position = rect4;
                }
                else
                {
                    int index = userData % 0x3e8;
                    if (base.children.Length != 1)
                    {
                        SplitView view2 = ScriptableObject.CreateInstance <SplitView>();
                        view2.vertical = !this.vertical;
                        Rect rect5 = base.children[index].position;
                        view2.AddChild(base.children[index]);
                        this.AddChild(view2, index);
                        view2.position = rect5;
                        float num3 = 0f;
                        rect5.y = num3;
                        rect5.x = num3;
                        view2.children[0].position = rect5;
                        Rect rect6 = r;
                        rect6.x -= view2.screenPosition.x;
                        rect6.y -= view2.screenPosition.y;
                        view2.MakeRoomForRect(rect6);
                        view2.AddChild(child, (userData >= 0x7d0) ? 1 : 0);
                        child.position = rect6;
                    }
                    else
                    {
                        this.vertical = !this.vertical;
                        Rect rect7 = r;
                        rect7.x -= base.screenPosition.x;
                        rect7.y -= base.screenPosition.y;
                        this.MakeRoomForRect(rect7);
                        this.AddChild(child, (userData != 0x3e8) ? 1 : 0);
                        child.position = rect7;
                    }
                }
                break;
            }
            DockArea.s_OriginalDragSource.RemoveTab(w);
            w.m_Parent = child;
            child.AddTab(w);
            this.Reflow();
            RecalcMinMaxAndReflowAll(this);
            child.MakeVistaDWMHappyDance();
            return(true);
        }
示例#18
0
 private static void ResetDragVars()
 {
     s_DragPane = null;
     s_DropInfo = null;
     s_PlaceholderPos = -1;
     s_DragMode = 0;
     s_OriginalDragSource = null;
 }
示例#19
0
        private void DragTab(Rect pos, GUIStyle tabStyle)
        {
            int controlID = GUIUtility.GetControlID(FocusType.Passive);
            float tabWidth = this.GetTabWidth(pos.width);
            Event current = Event.current;
            if ((s_DragMode != 0) && (GUIUtility.hotControl == 0))
            {
                PaneDragTab.get.Close();
                ResetDragVars();
            }
            EventType typeForControl = current.GetTypeForControl(controlID);
            switch (typeForControl)
            {
                case EventType.MouseDown:
                    if (pos.Contains(current.mousePosition) && (GUIUtility.hotControl == 0))
                    {
                        int tabAtMousePos = this.GetTabAtMousePos(current.mousePosition, pos);
                        if (tabAtMousePos < this.m_Panes.Count)
                        {
                            switch (current.button)
                            {
                                case 0:
                                    if (tabAtMousePos != this.selected)
                                    {
                                        this.selected = tabAtMousePos;
                                    }
                                    GUIUtility.hotControl = controlID;
                                    s_StartDragPosition = current.mousePosition;
                                    s_DragMode = 0;
                                    current.Use();
                                    break;

                                case 2:
                                    this.m_Panes[tabAtMousePos].Close();
                                    current.Use();
                                    break;
                            }
                        }
                    }
                    goto Label_06B9;

                case EventType.MouseUp:
                    if (GUIUtility.hotControl == controlID)
                    {
                        Vector2 vector3 = GUIUtility.GUIToScreenPoint(current.mousePosition);
                        if (s_DragMode != 0)
                        {
                            s_DragMode = 0;
                            PaneDragTab.get.Close();
                            EditorApplication.update = (EditorApplication.CallbackFunction) Delegate.Remove(EditorApplication.update, new EditorApplication.CallbackFunction(DockArea.CheckDragWindowExists));
                            if ((s_DropInfo == null) || (s_DropInfo.dropArea == null))
                            {
                                EditorWindow pane = s_DragPane;
                                ResetDragVars();
                                this.RemoveTab(pane);
                                Rect position = pane.position;
                                position.x = vector3.x - (position.width * 0.5f);
                                position.y = vector3.y - (position.height * 0.5f);
                                if (Application.platform == RuntimePlatform.WindowsEditor)
                                {
                                    position.y = Mathf.Max(InternalEditorUtility.GetBoundsOfDesktopAtPoint(vector3).y, position.y);
                                }
                                EditorWindow.CreateNewWindowForEditorWindow(pane, false, false);
                                pane.position = pane.m_Parent.window.FitWindowRectToScreen(position, true, true);
                                GUIUtility.hotControl = 0;
                                GUIUtility.ExitGUI();
                            }
                            else
                            {
                                s_DropInfo.dropArea.PerformDrop(s_DragPane, s_DropInfo, vector3);
                            }
                            ResetDragVars();
                        }
                        GUIUtility.hotControl = 0;
                        current.Use();
                    }
                    goto Label_06B9;

                case EventType.MouseDrag:
                    if (GUIUtility.hotControl == controlID)
                    {
                        Vector2 vector = current.mousePosition - s_StartDragPosition;
                        current.Use();
                        Rect screenPosition = base.screenPosition;
                        if ((s_DragMode == 0) && (vector.sqrMagnitude > 99f))
                        {
                            s_DragMode = 1;
                            s_PlaceholderPos = this.selected;
                            s_DragPane = this.m_Panes[this.selected];
                            if (this.m_Panes.Count != 1)
                            {
                                s_IgnoreDockingForView = null;
                            }
                            else
                            {
                                s_IgnoreDockingForView = this;
                            }
                            s_OriginalDragSource = this;
                            PaneDragTab.get.content = s_DragPane.titleContent;
                            base.Internal_SetAsActiveWindow();
                            PaneDragTab.get.GrabThumbnail();
                            PaneDragTab.get.Show(new Rect((pos.x + screenPosition.x) + (tabWidth * this.selected), pos.y + screenPosition.y, tabWidth, pos.height), GUIUtility.GUIToScreenPoint(current.mousePosition));
                            EditorApplication.update = (EditorApplication.CallbackFunction) Delegate.Combine(EditorApplication.update, new EditorApplication.CallbackFunction(DockArea.CheckDragWindowExists));
                            GUIUtility.ExitGUI();
                        }
                        if (s_DragMode == 1)
                        {
                            DropInfo di = null;
                            ContainerWindow[] windows = ContainerWindow.windows;
                            Vector2 screenPos = GUIUtility.GUIToScreenPoint(current.mousePosition);
                            ContainerWindow inFrontOf = null;
                            foreach (ContainerWindow window2 in windows)
                            {
                                foreach (View view in window2.mainView.allChildren)
                                {
                                    IDropArea area = view as IDropArea;
                                    if (area != null)
                                    {
                                        di = area.DragOver(s_DragPane, screenPos);
                                    }
                                    if (di != null)
                                    {
                                        break;
                                    }
                                }
                                if (di != null)
                                {
                                    inFrontOf = window2;
                                    break;
                                }
                            }
                            if (di == null)
                            {
                                di = new DropInfo(null);
                            }
                            if (di.type != DropInfo.Type.Tab)
                            {
                                s_PlaceholderPos = -1;
                            }
                            s_DropInfo = di;
                            if (PaneDragTab.get.m_Window != null)
                            {
                                PaneDragTab.get.SetDropInfo(di, screenPos, inFrontOf);
                            }
                        }
                    }
                    goto Label_06B9;

                case EventType.Repaint:
                {
                    float xMin = pos.xMin;
                    int num8 = 0;
                    if (base.actualView == null)
                    {
                        Rect rect5 = new Rect(xMin, pos.yMin, tabWidth, pos.height);
                        float x = Mathf.Round(rect5.x);
                        Rect rect6 = new Rect(x, rect5.y, Mathf.Round(rect5.x + rect5.width) - x, rect5.height);
                        tabStyle.Draw(rect6, "Failed to load", false, false, true, false);
                    }
                    else
                    {
                        for (int i = 0; i < this.m_Panes.Count; i++)
                        {
                            if (s_DragPane != this.m_Panes[i])
                            {
                                if (((s_DropInfo != null) && object.ReferenceEquals(s_DropInfo.dropArea, this)) && (s_PlaceholderPos == num8))
                                {
                                    xMin += tabWidth;
                                }
                                Rect rect3 = new Rect(xMin, pos.yMin, tabWidth, pos.height);
                                float num10 = Mathf.Round(rect3.x);
                                Rect rect4 = new Rect(num10, rect3.y, Mathf.Round(rect3.x + rect3.width) - num10, rect3.height);
                                tabStyle.Draw(rect4, this.m_Panes[i].titleContent, false, false, i == this.selected, base.hasFocus);
                                xMin += tabWidth;
                                num8++;
                            }
                        }
                    }
                    goto Label_06B9;
                }
            }
            if ((typeForControl == EventType.ContextClick) && (pos.Contains(current.mousePosition) && (GUIUtility.hotControl == 0)))
            {
                int num4 = this.GetTabAtMousePos(current.mousePosition, pos);
                if (num4 < this.m_Panes.Count)
                {
                    base.PopupGenericMenu(this.m_Panes[num4], new Rect(current.mousePosition.x, current.mousePosition.y, 0f, 0f));
                }
            }
        Label_06B9:
            this.selected = Mathf.Clamp(this.selected, 0, this.m_Panes.Count - 1);
        }
示例#20
0
        private void DragTab(Rect pos, GUIStyle tabStyle)
        {
            int   controlId = GUIUtility.GetControlID(FocusType.Passive);
            float tabWidth  = this.GetTabWidth(pos.width);
            Event current   = Event.current;

            if (DockArea.s_DragMode != 0 && GUIUtility.hotControl == 0)
            {
                PaneDragTab.get.Close();
                DockArea.ResetDragVars();
            }
            EventType typeForControl = current.GetTypeForControl(controlId);

            switch (typeForControl)
            {
            case EventType.MouseDown:
                if (pos.Contains(current.mousePosition) && GUIUtility.hotControl == 0)
                {
                    int tabAtMousePos = this.GetTabAtMousePos(current.mousePosition, pos);
                    if (tabAtMousePos < this.m_Panes.Count)
                    {
                        switch (current.button)
                        {
                        case 0:
                            if (tabAtMousePos != this.selected)
                            {
                                this.selected = tabAtMousePos;
                            }
                            GUIUtility.hotControl        = controlId;
                            DockArea.s_StartDragPosition = current.mousePosition;
                            DockArea.s_DragMode          = 0;
                            current.Use();
                            break;

                        case 2:
                            this.m_Panes[tabAtMousePos].Close();
                            current.Use();
                            break;
                        }
                    }
                    else
                    {
                        break;
                    }
                }
                else
                {
                    break;
                }

            case EventType.MouseUp:
                if (GUIUtility.hotControl == controlId)
                {
                    Vector2 screenPoint = GUIUtility.GUIToScreenPoint(current.mousePosition);
                    if (DockArea.s_DragMode != 0)
                    {
                        DockArea.s_DragMode = 0;
                        PaneDragTab.get.Close();
                        EditorApplication.update -= new EditorApplication.CallbackFunction(DockArea.CheckDragWindowExists);
                        if (DockArea.s_DropInfo != null && DockArea.s_DropInfo.dropArea != null)
                        {
                            DockArea.s_DropInfo.dropArea.PerformDrop(DockArea.s_DragPane, DockArea.s_DropInfo, screenPoint);
                        }
                        else
                        {
                            EditorWindow dragPane = DockArea.s_DragPane;
                            DockArea.ResetDragVars();
                            this.RemoveTab(dragPane);
                            Rect position = dragPane.position;
                            position.x = screenPoint.x - position.width * 0.5f;
                            position.y = screenPoint.y - position.height * 0.5f;
                            if (Application.platform == RuntimePlatform.WindowsEditor)
                            {
                                position.y = Mathf.Max(InternalEditorUtility.GetBoundsOfDesktopAtPoint(screenPoint).y, position.y);
                            }
                            EditorWindow.CreateNewWindowForEditorWindow(dragPane, false, false);
                            dragPane.position     = dragPane.m_Parent.window.FitWindowRectToScreen(position, true, true);
                            GUIUtility.hotControl = 0;
                            GUIUtility.ExitGUI();
                        }
                        DockArea.ResetDragVars();
                    }
                    GUIUtility.hotControl = 0;
                    current.Use();
                    break;
                }
                break;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == controlId)
                {
                    Vector2 vector2 = current.mousePosition - DockArea.s_StartDragPosition;
                    current.Use();
                    Rect screenPosition = this.screenPosition;
                    if (DockArea.s_DragMode == 0 && (double)vector2.sqrMagnitude > 99.0)
                    {
                        DockArea.s_DragMode             = 1;
                        DockArea.s_PlaceholderPos       = this.selected;
                        DockArea.s_DragPane             = this.m_Panes[this.selected];
                        DockArea.s_IgnoreDockingForView = this.m_Panes.Count != 1 ? (View)null : (View)this;
                        DockArea.s_OriginalDragSource   = this;
                        PaneDragTab.get.content         = DockArea.s_DragPane.titleContent;
                        this.Internal_SetAsActiveWindow();
                        PaneDragTab.get.GrabThumbnail();
                        PaneDragTab.get.Show(new Rect((float)((double)pos.x + (double)screenPosition.x + (double)tabWidth * (double)this.selected), pos.y + screenPosition.y, tabWidth, pos.height), GUIUtility.GUIToScreenPoint(current.mousePosition));
                        EditorApplication.update += new EditorApplication.CallbackFunction(DockArea.CheckDragWindowExists);
                        GUIUtility.ExitGUI();
                    }
                    if (DockArea.s_DragMode == 1)
                    {
                        DropInfo          di          = (DropInfo)null;
                        ContainerWindow[] windows     = ContainerWindow.windows;
                        Vector2           screenPoint = GUIUtility.GUIToScreenPoint(current.mousePosition);
                        ContainerWindow   inFrontOf   = (ContainerWindow)null;
                        foreach (ContainerWindow containerWindow in windows)
                        {
                            foreach (View allChild in containerWindow.mainView.allChildren)
                            {
                                IDropArea dropArea = allChild as IDropArea;
                                if (dropArea != null)
                                {
                                    di = dropArea.DragOver(DockArea.s_DragPane, screenPoint);
                                }
                                if (di != null)
                                {
                                    break;
                                }
                            }
                            if (di != null)
                            {
                                inFrontOf = containerWindow;
                                break;
                            }
                        }
                        if (di == null)
                        {
                            di = new DropInfo((IDropArea)null);
                        }
                        if (di.type != DropInfo.Type.Tab)
                        {
                            DockArea.s_PlaceholderPos = -1;
                        }
                        DockArea.s_DropInfo = di;
                        if ((bool)((UnityEngine.Object)PaneDragTab.get.m_Window))
                        {
                            PaneDragTab.get.SetDropInfo(di, screenPoint, inFrontOf);
                            break;
                        }
                        break;
                    }
                    break;
                }
                break;

            case EventType.Repaint:
                float xMin = pos.xMin;
                int   num  = 0;
                if ((bool)((UnityEngine.Object) this.actualView))
                {
                    for (int index = 0; index < this.m_Panes.Count; ++index)
                    {
                        if (!((UnityEngine.Object)DockArea.s_DragPane == (UnityEngine.Object) this.m_Panes[index]))
                        {
                            if (DockArea.s_DropInfo != null && object.ReferenceEquals((object)DockArea.s_DropInfo.dropArea, (object)this) && DockArea.s_PlaceholderPos == num)
                            {
                                xMin += tabWidth;
                            }
                            Rect  rect     = new Rect(xMin, pos.yMin, tabWidth, pos.height);
                            float x        = Mathf.Round(rect.x);
                            Rect  position = new Rect(x, rect.y, Mathf.Round(rect.x + rect.width) - x, rect.height);
                            tabStyle.Draw(position, this.m_Panes[index].titleContent, false, false, index == this.selected, this.hasFocus);
                            xMin += tabWidth;
                            ++num;
                        }
                    }
                    break;
                }
                Rect  rect1     = new Rect(xMin, pos.yMin, tabWidth, pos.height);
                float x1        = Mathf.Round(rect1.x);
                Rect  position1 = new Rect(x1, rect1.y, Mathf.Round(rect1.x + rect1.width) - x1, rect1.height);
                tabStyle.Draw(position1, "Failed to load", false, false, true, false);
                break;

            default:
                if (typeForControl == EventType.ContextClick && pos.Contains(current.mousePosition) && GUIUtility.hotControl == 0)
                {
                    int tabAtMousePos = this.GetTabAtMousePos(current.mousePosition, pos);
                    if (tabAtMousePos < this.m_Panes.Count)
                    {
                        this.PopupGenericMenu(this.m_Panes[tabAtMousePos], new Rect(current.mousePosition.x, current.mousePosition.y, 0.0f, 0.0f));
                        break;
                    }
                    break;
                }
                break;
            }
            this.selected = Mathf.Clamp(this.selected, 0, this.m_Panes.Count - 1);
        }
        public static bool LoadWindowLayout(string path, bool newProjectLayoutWasCreated)
        {
            Rect mainWindowPosition = new Rect();

            UnityObject[] containers = Resources.FindObjectsOfTypeAll(typeof(ContainerWindow));
            foreach (ContainerWindow window in containers)
            {
                if (window.showMode == ShowMode.MainWindow)
                {
                    mainWindowPosition = window.position;
                }
            }

            bool layoutLoadingIssue = false;

            // Load new windows and show them
            try
            {
                ContainerWindow.SetFreezeDisplay(true);

                CloseWindows();

                // Load data
                UnityObject[] loadedWindows = InternalEditorUtility.LoadSerializedFileAndForget(path);

                if (loadedWindows == null || loadedWindows.Length == 0)
                {
                    throw new ArgumentException("Window layout at '" + path + "' could not be loaded.");
                }

                List <UnityObject> newWindows = new List <UnityObject>();

                // At this point, unparented editor windows are neither desired nor desirable.
                // This can be caused by (legacy) serialization of FallbackEditorWindows or
                // other serialization hiccups (note that unparented editor windows should not exist in theory).
                // Same goes for empty DockAreas (no panes).  Leave them behind.
                for (int i = 0; i < loadedWindows.Length; i++)
                {
                    UnityObject o = loadedWindows[i];

                    EditorWindow editorWin = o as EditorWindow;
                    if (editorWin != null)
                    {
                        if (editorWin.m_Parent == null)
                        {
                            UnityObject.DestroyImmediate(editorWin, true);
                            Console.WriteLine("LoadWindowLayout: Removed unparented EditorWindow while reading window layout: window #" + i + ", type=" +
                                              o.GetType().ToString() + ", instanceID=" + o.GetInstanceID());
                            layoutLoadingIssue = true;
                            continue;
                        }
                    }
                    else
                    {
                        DockArea dockArea = o as DockArea;
                        if (dockArea != null && dockArea.m_Panes.Count == 0)
                        {
                            dockArea.Close(null);
                            Console.WriteLine("LoadWindowLayout: Removed empty DockArea while reading window layout: window #" + i + ", instanceID=" +
                                              o.GetInstanceID());
                            layoutLoadingIssue = true;
                            continue;
                        }
                    }

                    newWindows.Add(o);
                }

                ContainerWindow mainWindowToSetSize = null;
                ContainerWindow mainWindow          = null;

                for (int i = 0; i < newWindows.Count; i++)
                {
                    ContainerWindow cur = newWindows[i] as ContainerWindow;
                    if (cur != null && cur.showMode == ShowMode.MainWindow)
                    {
                        mainWindow = cur;
                        if (mainWindowPosition.width != 0.0)
                        {
                            mainWindowToSetSize          = cur;
                            mainWindowToSetSize.position = mainWindowPosition;
                        }
                    }
                }

                for (int i = 0; i < newWindows.Count; i++)
                {
                    UnityObject o = newWindows[i];
                    if (o == null)
                    {
                        Console.WriteLine("LoadWindowLayout: Error while reading window layout: window #" + i + " is null");
                        layoutLoadingIssue = true;
                        // Keep going
                    }
                    else if (o.GetType() == null)
                    {
                        Console.WriteLine("LoadWindowLayout: Error while reading window layout: window #" + i + " type is null, instanceID=" + o.GetInstanceID());
                        layoutLoadingIssue = true;
                        // Keep going
                    }
                    else
                    {
                        if (newProjectLayoutWasCreated)
                        {
                            MethodInfo method = o.GetType().GetMethod("OnNewProjectLayoutWasCreated", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
                            if (method != null)
                            {
                                method.Invoke(o, null);
                            }
                        }
                    }
                }

                if (mainWindowToSetSize)
                {
                    mainWindowToSetSize.position = mainWindowPosition;
                    mainWindowToSetSize.OnResize();
                }

                // Always show main window before other windows. So that other windows can
                // get their parent/owner.
                if (mainWindow == null)
                {
                    Debug.LogError("Error while reading window layout: no main window found");
                    throw new System.Exception();
                }
                mainWindow.Show(mainWindow.showMode, true, true);

                // Show other windows
                for (int i = 0; i < newWindows.Count; i++)
                {
                    EditorWindow win = newWindows[i] as EditorWindow;
                    if (win)
                    {
                        win.minSize = win.minSize; // Causes minSize to be propagated upwards to parents!
                    }
                    ContainerWindow containerWindow = newWindows[i] as ContainerWindow;
                    if (containerWindow && containerWindow != mainWindow)
                    {
                        containerWindow.Show(containerWindow.showMode, true, true);
                    }
                }

                // Unmaximize maximized GameView if maximize on play is enabled
                GameView gameView = GetMaximizedWindow() as GameView;
                if (gameView != null && gameView.maximizeOnPlay)
                {
                    Unmaximize(gameView);
                }

                // For new projects, show services window if and only if online and logged in
                if (newProjectLayoutWasCreated)
                {
                    if (UnityConnect.instance.online && UnityConnect.instance.loggedIn && UnityConnect.instance.shouldShowServicesWindow)
                    {
                        UnityConnectServiceCollection.instance.ShowService(HubAccess.kServiceName, true, "new_project_created");
                    }
                    else
                    {
                        UnityConnectServiceCollection.instance.CloseServices();
                    }
                }
            }
            catch (System.Exception ex)
            {
                Debug.LogError("Failed to load window layout: " + ex);

                int option = 0;


                UnityObject[] containerWindows = Resources.FindObjectsOfTypeAll(typeof(ContainerWindow));

                // Only show dialog if an actual window is present. If not, revert to default immediately
                if (!Application.isTestRun && containerWindows.Length > 0)
                {
                    option = 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");
                }

                switch (option)
                {
                case 0:
                    LoadDefaultLayout();
                    break;

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

                case 2:
                    RevertFactorySettings();
                    break;
                }

                return(false);
            }
            finally
            {
                ContainerWindow.SetFreezeDisplay(false);

                if (Path.GetExtension(path) == ".wlt")
                {
                    Toolbar.lastLoadedLayoutName = Path.GetFileNameWithoutExtension(path);
                }
                else
                {
                    Toolbar.lastLoadedLayoutName = null;
                }
            }

            if (layoutLoadingIssue)
            {
                Debug.Log("The editor layout could not be fully loaded, this can happen when the layout contains EditorWindows not available in this project");
            }

            return(true);
        }
示例#22
0
        public void SplitGUI(Event evt)
        {
            if (splitState == null)
            {
                SetupSplitter();
            }

            SplitView sp = parent as SplitView;

            if (sp)
            {
                Event e = new Event(evt);
                e.mousePosition += new Vector2(position.x, position.y);
                sp.SplitGUI(e);
                if (e.type == EventType.Used)
                {
                    evt.Use();
                }
            }

            float pos = vertical ? evt.mousePosition.y : evt.mousePosition.x;
            int   id  = GUIUtility.GetControlID(546739, FocusType.Passive);

            controlID = id;

            switch (evt.GetTypeForControl(id))
            {
            case EventType.MouseDown:
                if (children.Length != 1)     // is there a splitter
                {
                    int cursor = vertical ? (int)children[0].position.y : (int)children[0].position.x;

                    for (int i = 0; i < children.Length - 1; i++)
                    {
                        if (i >= splitState.realSizes.Length)
                        {
                            DockArea dock = GUIView.current as DockArea;
                            string   name = "Non-dock area " + GUIView.current.GetType();
                            if (dock && dock.m_Selected < dock.m_Panes.Count && dock.m_Panes[dock.m_Selected])
                            {
                                name = dock.m_Panes[dock.m_Selected].GetType().ToString();
                            }

                            if (Unsupported.IsDeveloperMode())
                            {
                                Debug.LogError("Real sizes out of bounds for: " + name + " index: " + i + " RealSizes: " + splitState.realSizes.Length);
                            }

                            SetupSplitter();
                        }
                        Rect splitterRect = vertical ?
                                            new Rect(children[0].position.x, cursor + splitState.realSizes[i] - splitState.splitSize / 2, children[0].position.width, splitState.splitSize) :
                                            new Rect(cursor + splitState.realSizes[i] - splitState.splitSize / 2, children[0].position.y, splitState.splitSize, children[0].position.height);

                        if (splitterRect.Contains(evt.mousePosition))
                        {
                            splitState.splitterInitialOffset = (int)pos;
                            splitState.currentActiveSplitter = i;
                            GUIUtility.hotControl            = id;
                            evt.Use();
                            break;
                        }

                        cursor += splitState.realSizes[i];
                    }
                }
                break;

            case EventType.MouseDrag:
                if (children.Length > 1 && (GUIUtility.hotControl == id) && (splitState.currentActiveSplitter >= 0))
                {
                    int diff = (int)pos - splitState.splitterInitialOffset;

                    if (diff != 0)
                    {
                        splitState.splitterInitialOffset = (int)pos;
                        splitState.DoSplitter(splitState.currentActiveSplitter, splitState.currentActiveSplitter + 1, diff);
                    }

                    SetupRectsFromSplitter();


                    evt.Use();
                }
                break;

            case EventType.MouseUp:
                if (GUIUtility.hotControl == id)
                {
                    GUIUtility.hotControl = 0;
                }
                break;
            }
        }
示例#23
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);
                            }
                        }
                    }
                }
            }
        }
示例#24
0
        private void DragTab(Rect pos, GUIStyle tabStyle)
        {
            int   controlID = GUIUtility.GetControlID(FocusType.Passive);
            float tabWidth  = this.GetTabWidth(pos.width);
            Event current   = Event.current;

            if (DockArea.s_DragMode != 0 && GUIUtility.hotControl == 0)
            {
                PaneDragTab.get.Close();
                DockArea.ResetDragVars();
            }
            EventType typeForControl = current.GetTypeForControl(controlID);

            switch (typeForControl)
            {
            case EventType.MouseDown:
                if (pos.Contains(current.mousePosition) && GUIUtility.hotControl == 0)
                {
                    int tabAtMousePos = this.GetTabAtMousePos(current.mousePosition, pos);
                    if (tabAtMousePos < this.m_Panes.Count)
                    {
                        switch (current.button)
                        {
                        case 0:
                            if (tabAtMousePos != this.selected)
                            {
                                this.selected = tabAtMousePos;
                            }
                            GUIUtility.hotControl        = controlID;
                            DockArea.s_StartDragPosition = current.mousePosition;
                            DockArea.s_DragMode          = 0;
                            current.Use();
                            break;

                        case 2:
                            this.m_Panes[tabAtMousePos].Close();
                            current.Use();
                            break;
                        }
                    }
                }
                goto IL_6B9;

            case EventType.MouseUp:
                if (GUIUtility.hotControl == controlID)
                {
                    Vector2 vector = GUIUtility.GUIToScreenPoint(current.mousePosition);
                    if (DockArea.s_DragMode != 0)
                    {
                        DockArea.s_DragMode = 0;
                        PaneDragTab.get.Close();
                        EditorApplication.update = (EditorApplication.CallbackFunction)Delegate.Remove(EditorApplication.update, new EditorApplication.CallbackFunction(DockArea.CheckDragWindowExists));
                        if (DockArea.s_DropInfo != null && DockArea.s_DropInfo.dropArea != null)
                        {
                            DockArea.s_DropInfo.dropArea.PerformDrop(DockArea.s_DragPane, DockArea.s_DropInfo, vector);
                        }
                        else
                        {
                            EditorWindow editorWindow = DockArea.s_DragPane;
                            DockArea.ResetDragVars();
                            this.RemoveTab(editorWindow);
                            Rect position = editorWindow.position;
                            position.x = vector.x - position.width * 0.5f;
                            position.y = vector.y - position.height * 0.5f;
                            if (Application.platform == RuntimePlatform.WindowsEditor)
                            {
                                position.y = Mathf.Max(InternalEditorUtility.GetBoundsOfDesktopAtPoint(vector).y, position.y);
                            }
                            EditorWindow.CreateNewWindowForEditorWindow(editorWindow, false, false);
                            editorWindow.position = editorWindow.m_Parent.window.FitWindowRectToScreen(position, true, true);
                            GUIUtility.hotControl = 0;
                            GUIUtility.ExitGUI();
                        }
                        DockArea.ResetDragVars();
                    }
                    GUIUtility.hotControl = 0;
                    current.Use();
                }
                goto IL_6B9;

            case EventType.MouseMove:
            case EventType.KeyDown:
            case EventType.KeyUp:
            case EventType.ScrollWheel:
IL_6E:
                if (typeForControl != EventType.ContextClick)
                {
                    goto IL_6B9;
                }
                if (pos.Contains(current.mousePosition) && GUIUtility.hotControl == 0)
                {
                    int tabAtMousePos2 = this.GetTabAtMousePos(current.mousePosition, pos);
                    if (tabAtMousePos2 < this.m_Panes.Count)
                    {
                        base.PopupGenericMenu(this.m_Panes[tabAtMousePos2], new Rect(current.mousePosition.x, current.mousePosition.y, 0f, 0f));
                    }
                }
                goto IL_6B9;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == controlID)
                {
                    Vector2 vector2 = current.mousePosition - DockArea.s_StartDragPosition;
                    current.Use();
                    Rect screenPosition = base.screenPosition;
                    if (DockArea.s_DragMode == 0 && vector2.sqrMagnitude > 99f)
                    {
                        DockArea.s_DragMode       = 1;
                        DockArea.s_PlaceholderPos = this.selected;
                        DockArea.s_DragPane       = this.m_Panes[this.selected];
                        if (this.m_Panes.Count == 1)
                        {
                            DockArea.s_IgnoreDockingForView = this;
                        }
                        else
                        {
                            DockArea.s_IgnoreDockingForView = null;
                        }
                        DockArea.s_OriginalDragSource = this;
                        PaneDragTab.get.content       = DockArea.s_DragPane.cachedTitleContent;
                        base.Internal_SetAsActiveWindow();
                        PaneDragTab.get.GrabThumbnail();
                        PaneDragTab.get.Show(new Rect(pos.x + screenPosition.x + tabWidth * (float)this.selected, pos.y + screenPosition.y, tabWidth, pos.height), GUIUtility.GUIToScreenPoint(current.mousePosition));
                        EditorApplication.update = (EditorApplication.CallbackFunction)Delegate.Combine(EditorApplication.update, new EditorApplication.CallbackFunction(DockArea.CheckDragWindowExists));
                        GUIUtility.ExitGUI();
                    }
                    if (DockArea.s_DragMode == 1)
                    {
                        DropInfo          dropInfo  = null;
                        ContainerWindow[] windows   = ContainerWindow.windows;
                        Vector2           vector3   = GUIUtility.GUIToScreenPoint(current.mousePosition);
                        ContainerWindow   inFrontOf = null;
                        ContainerWindow[] array     = windows;
                        for (int i = 0; i < array.Length; i++)
                        {
                            ContainerWindow containerWindow = array[i];
                            View[]          allChildren     = containerWindow.mainView.allChildren;
                            for (int j = 0; j < allChildren.Length; j++)
                            {
                                View      view     = allChildren[j];
                                IDropArea dropArea = view as IDropArea;
                                if (dropArea != null)
                                {
                                    dropInfo = dropArea.DragOver(DockArea.s_DragPane, vector3);
                                }
                                if (dropInfo != null)
                                {
                                    break;
                                }
                            }
                            if (dropInfo != null)
                            {
                                inFrontOf = containerWindow;
                                break;
                            }
                        }
                        if (dropInfo == null)
                        {
                            dropInfo = new DropInfo(null);
                        }
                        if (dropInfo.type != DropInfo.Type.Tab)
                        {
                            DockArea.s_PlaceholderPos = -1;
                        }
                        DockArea.s_DropInfo = dropInfo;
                        if (PaneDragTab.get.m_Window)
                        {
                            PaneDragTab.get.SetDropInfo(dropInfo, vector3, inFrontOf);
                        }
                    }
                }
                goto IL_6B9;

            case EventType.Repaint:
            {
                float num  = pos.xMin;
                int   num2 = 0;
                if (base.actualView)
                {
                    for (int k = 0; k < this.m_Panes.Count; k++)
                    {
                        if (!(DockArea.s_DragPane == this.m_Panes[k]))
                        {
                            if (DockArea.s_DropInfo != null && object.ReferenceEquals(DockArea.s_DropInfo.dropArea, this) && DockArea.s_PlaceholderPos == num2)
                            {
                                num += tabWidth;
                            }
                            Rect  rect      = new Rect(num, pos.yMin, tabWidth, pos.height);
                            float num3      = Mathf.Round(rect.x);
                            Rect  position2 = new Rect(num3, rect.y, Mathf.Round(rect.x + rect.width) - num3, rect.height);
                            tabStyle.Draw(position2, this.m_Panes[k].cachedTitleContent, false, false, k == this.selected, base.hasFocus);
                            num += tabWidth;
                            num2++;
                        }
                    }
                }
                else
                {
                    Rect  rect2     = new Rect(num, pos.yMin, tabWidth, pos.height);
                    float num4      = Mathf.Round(rect2.x);
                    Rect  position3 = new Rect(num4, rect2.y, Mathf.Round(rect2.x + rect2.width) - num4, rect2.height);
                    tabStyle.Draw(position3, "Failed to load", false, false, true, false);
                }
                goto IL_6B9;
            }
            }
            goto IL_6E;
IL_6B9:
            this.selected = Mathf.Clamp(this.selected, 0, this.m_Panes.Count - 1);
        }
示例#25
0
        public static bool MaximizePrepare(EditorWindow win)
        {
            View parent = win.m_Parent.parent;
            View view   = parent;

            while (parent != null && parent is SplitView)
            {
                view   = parent;
                parent = parent.parent;
            }
            DockArea dockArea = win.m_Parent as DockArea;
            bool     result;

            if (dockArea == null)
            {
                result = false;
            }
            else if (parent == null)
            {
                result = false;
            }
            else
            {
                MainView x = view.parent as MainView;
                if (x == null)
                {
                    result = false;
                }
                else
                {
                    ContainerWindow window = win.m_Parent.window;
                    if (window == null)
                    {
                        result = false;
                    }
                    else
                    {
                        int num = dockArea.m_Panes.IndexOf(win);
                        if (num == -1)
                        {
                            result = false;
                        }
                        else
                        {
                            dockArea.selected = num;
                            WindowLayout.SaveSplitViewAndChildren(view, win, Path.Combine(WindowLayout.layoutsProjectPath, "CurrentMaximizeLayout.dwlt"));
                            dockArea.actualView   = null;
                            dockArea.m_Panes[num] = null;
                            MaximizedHostView maximizedHostView = ScriptableObject.CreateInstance <MaximizedHostView>();
                            int  idx      = parent.IndexOfChild(view);
                            Rect position = view.position;
                            parent.RemoveChild(view);
                            parent.AddChild(maximizedHostView, idx);
                            maximizedHostView.actualView = win;
                            maximizedHostView.position   = position;
                            UnityEngine.Object.DestroyImmediate(view, true);
                            result = true;
                        }
                    }
                }
            }
            return(result);
        }
        static internal EditorWindow ShowAppropriateViewOnEnterExitPlaymode(bool entering)
        {
            // Prevent trying to go into the same state as we're already in, as it wil break things
            if (WindowFocusState.instance.m_CurrentlyInPlayMode == entering)
            {
                return(null);
            }

            WindowFocusState.instance.m_CurrentlyInPlayMode = entering;

            EditorWindow window = null;

            EditorWindow maximized = GetMaximizedWindow();

            if (entering)
            {
                WindowFocusState.instance.m_WasMaximizedBeforePlay = (maximized != null);
                // If a view is already maximized before entering play mode,
                // just keep that maximized view, no matter if it's the game view or some other.
                // Trust that user has a good reason (desire by Ethan etc.)
                if (maximized != null)
                {
                    return(maximized);
                }
            }
            else
            {
                // If a view was already maximized before entering play mode,
                // then it was kept when switching to play mode, and can simply still be kept when exiting
                if (WindowFocusState.instance.m_WasMaximizedBeforePlay)
                {
                    return(maximized);
                }
            }

            // Unmaximize if maximized
            if (maximized)
            {
                Unmaximize(maximized);
            }

            // Try finding and focusing appropriate window/tab
            window = TryFocusAppropriateWindow(entering);
            if (window)
            {
                return(window);
            }

            // If we are entering Play more and no Game View was found, create one
            if (entering)
            {
                // Try to create and focus a Game View tab docked together with the Scene View tab
                EditorWindow sceneView = FindEditorWindowOfType(typeof(SceneView));
                GameView     gameView;
                if (sceneView && sceneView.m_Parent is DockArea)
                {
                    DockArea dock = sceneView.m_Parent as DockArea;
                    if (dock)
                    {
                        WindowFocusState.instance.m_LastWindowTypeInSameDock = sceneView.GetType().ToString();
                        gameView = ScriptableObject.CreateInstance <GameView>();
                        dock.AddTab(gameView);
                        return(gameView);
                    }
                }

                // If no Scene View was found at all, just create a floating Game View
                gameView = ScriptableObject.CreateInstance <GameView>();
                gameView.Show(true);
                gameView.Focus();

                return(gameView);
            }

            return(window);
        }
示例#27
0
		private void DragTab(Rect pos, GUIStyle tabStyle)
		{
			int controlID = GUIUtility.GetControlID(FocusType.Passive);
			float tabWidth = this.GetTabWidth(pos.width);
			Event current = Event.current;
			if (DockArea.s_DragMode != 0 && GUIUtility.hotControl == 0)
			{
				PaneDragTab.get.Close();
				DockArea.ResetDragVars();
			}
			EventType typeForControl = current.GetTypeForControl(controlID);
			switch (typeForControl)
			{
			case EventType.MouseDown:
				if (pos.Contains(current.mousePosition) && GUIUtility.hotControl == 0)
				{
					int tabAtMousePos = this.GetTabAtMousePos(current.mousePosition, pos);
					if (tabAtMousePos < this.m_Panes.Count)
					{
						switch (current.button)
						{
						case 0:
							if (tabAtMousePos != this.selected)
							{
								this.selected = tabAtMousePos;
							}
							GUIUtility.hotControl = controlID;
							DockArea.s_StartDragPosition = current.mousePosition;
							DockArea.s_DragMode = 0;
							current.Use();
							break;
						case 2:
							this.m_Panes[tabAtMousePos].Close();
							current.Use();
							break;
						}
					}
				}
				goto IL_6B9;
			case EventType.MouseUp:
				if (GUIUtility.hotControl == controlID)
				{
					Vector2 vector = GUIUtility.GUIToScreenPoint(current.mousePosition);
					if (DockArea.s_DragMode != 0)
					{
						DockArea.s_DragMode = 0;
						PaneDragTab.get.Close();
						EditorApplication.update = (EditorApplication.CallbackFunction)Delegate.Remove(EditorApplication.update, new EditorApplication.CallbackFunction(DockArea.CheckDragWindowExists));
						if (DockArea.s_DropInfo != null && DockArea.s_DropInfo.dropArea != null)
						{
							DockArea.s_DropInfo.dropArea.PerformDrop(DockArea.s_DragPane, DockArea.s_DropInfo, vector);
						}
						else
						{
							EditorWindow editorWindow = DockArea.s_DragPane;
							DockArea.ResetDragVars();
							this.RemoveTab(editorWindow);
							Rect position = editorWindow.position;
							position.x = vector.x - position.width * 0.5f;
							position.y = vector.y - position.height * 0.5f;
							if (Application.platform == RuntimePlatform.WindowsEditor)
							{
								position.y = Mathf.Max(InternalEditorUtility.GetBoundsOfDesktopAtPoint(vector).y, position.y);
							}
							EditorWindow.CreateNewWindowForEditorWindow(editorWindow, false, false);
							editorWindow.position = editorWindow.m_Parent.window.FitWindowRectToScreen(position, true, true);
							GUIUtility.hotControl = 0;
							GUIUtility.ExitGUI();
						}
						DockArea.ResetDragVars();
					}
					GUIUtility.hotControl = 0;
					current.Use();
				}
				goto IL_6B9;
			case EventType.MouseMove:
			case EventType.KeyDown:
			case EventType.KeyUp:
			case EventType.ScrollWheel:
				IL_6E:
				if (typeForControl != EventType.ContextClick)
				{
					goto IL_6B9;
				}
				if (pos.Contains(current.mousePosition) && GUIUtility.hotControl == 0)
				{
					int tabAtMousePos2 = this.GetTabAtMousePos(current.mousePosition, pos);
					if (tabAtMousePos2 < this.m_Panes.Count)
					{
						base.PopupGenericMenu(this.m_Panes[tabAtMousePos2], new Rect(current.mousePosition.x, current.mousePosition.y, 0f, 0f));
					}
				}
				goto IL_6B9;
			case EventType.MouseDrag:
				if (GUIUtility.hotControl == controlID)
				{
					Vector2 vector2 = current.mousePosition - DockArea.s_StartDragPosition;
					current.Use();
					Rect screenPosition = base.screenPosition;
					if (DockArea.s_DragMode == 0 && vector2.sqrMagnitude > 99f)
					{
						DockArea.s_DragMode = 1;
						DockArea.s_PlaceholderPos = this.selected;
						DockArea.s_DragPane = this.m_Panes[this.selected];
						if (this.m_Panes.Count == 1)
						{
							DockArea.s_IgnoreDockingForView = this;
						}
						else
						{
							DockArea.s_IgnoreDockingForView = null;
						}
						DockArea.s_OriginalDragSource = this;
						PaneDragTab.get.content = DockArea.s_DragPane.cachedTitleContent;
						base.Internal_SetAsActiveWindow();
						PaneDragTab.get.GrabThumbnail();
						PaneDragTab.get.Show(new Rect(pos.x + screenPosition.x + tabWidth * (float)this.selected, pos.y + screenPosition.y, tabWidth, pos.height), GUIUtility.GUIToScreenPoint(current.mousePosition));
						EditorApplication.update = (EditorApplication.CallbackFunction)Delegate.Combine(EditorApplication.update, new EditorApplication.CallbackFunction(DockArea.CheckDragWindowExists));
						GUIUtility.ExitGUI();
					}
					if (DockArea.s_DragMode == 1)
					{
						DropInfo dropInfo = null;
						ContainerWindow[] windows = ContainerWindow.windows;
						Vector2 vector3 = GUIUtility.GUIToScreenPoint(current.mousePosition);
						ContainerWindow inFrontOf = null;
						ContainerWindow[] array = windows;
						for (int i = 0; i < array.Length; i++)
						{
							ContainerWindow containerWindow = array[i];
							View[] allChildren = containerWindow.mainView.allChildren;
							for (int j = 0; j < allChildren.Length; j++)
							{
								View view = allChildren[j];
								IDropArea dropArea = view as IDropArea;
								if (dropArea != null)
								{
									dropInfo = dropArea.DragOver(DockArea.s_DragPane, vector3);
								}
								if (dropInfo != null)
								{
									break;
								}
							}
							if (dropInfo != null)
							{
								inFrontOf = containerWindow;
								break;
							}
						}
						if (dropInfo == null)
						{
							dropInfo = new DropInfo(null);
						}
						if (dropInfo.type != DropInfo.Type.Tab)
						{
							DockArea.s_PlaceholderPos = -1;
						}
						DockArea.s_DropInfo = dropInfo;
						if (PaneDragTab.get.m_Window)
						{
							PaneDragTab.get.SetDropInfo(dropInfo, vector3, inFrontOf);
						}
					}
				}
				goto IL_6B9;
			case EventType.Repaint:
			{
				float num = pos.xMin;
				int num2 = 0;
				if (base.actualView)
				{
					for (int k = 0; k < this.m_Panes.Count; k++)
					{
						if (!(DockArea.s_DragPane == this.m_Panes[k]))
						{
							if (DockArea.s_DropInfo != null && object.ReferenceEquals(DockArea.s_DropInfo.dropArea, this) && DockArea.s_PlaceholderPos == num2)
							{
								num += tabWidth;
							}
							Rect rect = new Rect(num, pos.yMin, tabWidth, pos.height);
							float num3 = Mathf.Round(rect.x);
							Rect position2 = new Rect(num3, rect.y, Mathf.Round(rect.x + rect.width) - num3, rect.height);
							tabStyle.Draw(position2, this.m_Panes[k].cachedTitleContent, false, false, k == this.selected, base.hasFocus);
							num += tabWidth;
							num2++;
						}
					}
				}
				else
				{
					Rect rect2 = new Rect(num, pos.yMin, tabWidth, pos.height);
					float num4 = Mathf.Round(rect2.x);
					Rect position3 = new Rect(num4, rect2.y, Mathf.Round(rect2.x + rect2.width) - num4, rect2.height);
					tabStyle.Draw(position3, "Failed to load", false, false, true, false);
				}
				goto IL_6B9;
			}
			}
			goto IL_6E;
			IL_6B9:
			this.selected = Mathf.Clamp(this.selected, 0, this.m_Panes.Count - 1);
		}
        public static bool MaximizePrepare(EditorWindow win)
        {
            // Find Root SplitView
            View itor      = win.m_Parent.parent;
            View rootSplit = itor;

            while (itor != null && itor is SplitView)
            {
                rootSplit = itor;
                itor      = itor.parent;
            }

            // Make sure it has a dockarea
            DockArea dockArea = win.m_Parent as DockArea;

            if (dockArea == null)
            {
                return(false);
            }

            if (itor == null)
            {
                return(false);
            }

            var mainView = rootSplit.parent as MainView;

            if (mainView == null)
            {
                return(false);
            }

            ContainerWindow parentWindow = win.m_Parent.window;

            if (parentWindow == null)
            {
                return(false);
            }

            int oldDockIndex = dockArea.m_Panes.IndexOf(win);

            if (oldDockIndex == -1)
            {
                return(false);
            }

            dockArea.selected = oldDockIndex;

            // Save current state to disk
            SaveSplitViewAndChildren(rootSplit, win, Path.Combine(layoutsProjectPath, kMaximizeRestoreFile));

            // Remove the window from the HostView now in order to invoke OnBecameInvisible before OnBecameVisible
            dockArea.actualView = null;

            dockArea.m_Panes[oldDockIndex] = null;

            MaximizedHostView maximizedHostView = ScriptableObject.CreateInstance <MaximizedHostView>();

            int  i = itor.IndexOfChild(rootSplit);
            Rect p = rootSplit.position;

            itor.RemoveChild(rootSplit);
            itor.AddChild(maximizedHostView, i);

            maximizedHostView.actualView = win;
            maximizedHostView.position   = p; // Must be set after actualView so that value is propagated

            UnityObject.DestroyImmediate(rootSplit, true);

            return(true);
        }
示例#29
0
        public bool PerformDrop(EditorWindow dropWindow, DropInfo dropInfo, Vector2 screenPos)
        {
            ExtraDropInfo userData   = dropInfo.userData as ExtraDropInfo;
            bool          rootWindow = userData.rootWindow;
            ViewEdge      edge       = userData.edge;
            int           index      = userData.index;
            Rect          r          = dropInfo.rect;
            bool          flag2      = (edge & ViewEdge.Before) != ViewEdge.None;
            bool          flag3      = (edge & ViewEdge.FitsVertical) != ViewEdge.None;
            SplitView     view       = null;

            if ((this.vertical == flag3) || (base.children.Length < 2))
            {
                if (!flag2)
                {
                    if (rootWindow)
                    {
                        index = base.children.Length;
                    }
                    else
                    {
                        index++;
                    }
                }
                view = this;
            }
            else if (rootWindow)
            {
                SplitView view2 = ScriptableObject.CreateInstance <SplitView>();
                view2.position = base.position;
                if (base.window.rootView == this)
                {
                    base.window.rootView = view2;
                }
                else
                {
                    base.parent.AddChild(view2, base.parent.IndexOfChild(this));
                }
                view2.AddChild(this);
                base.position = new Rect(Vector2.zero, base.position.size);
                index         = !flag2 ? 1 : 0;
                view          = view2;
            }
            else
            {
                SplitView view3 = ScriptableObject.CreateInstance <SplitView>();
                view3.AddChild(base.children[index]);
                this.AddChild(view3, index);
                view3.position             = view3.children[0].position;
                view3.children[0].position = new Rect(Vector2.zero, view3.position.size);
                index = !flag2 ? 1 : 0;
                view  = view3;
            }
            r.position -= base.screenPosition.position;
            DockArea child = ScriptableObject.CreateInstance <DockArea>();

            view.vertical = flag3;
            view.MakeRoomForRect(r);
            view.AddChild(child, index);
            child.position = r;
            DockArea.s_OriginalDragSource.RemoveTab(dropWindow);
            dropWindow.m_Parent = child;
            child.AddTab(dropWindow);
            this.Reflow();
            RecalcMinMaxAndReflowAll(this);
            child.MakeVistaDWMHappyDance();
            return(true);
        }
示例#30
0
        internal static EditorWindow ShowAppropriateViewOnEnterExitPlaymode(bool entering)
        {
            EditorWindow result;

            if (WindowFocusState.instance.m_CurrentlyInPlayMode == entering)
            {
                result = null;
            }
            else
            {
                WindowFocusState.instance.m_CurrentlyInPlayMode = entering;
                EditorWindow maximizedWindow = WindowLayout.GetMaximizedWindow();
                if (entering)
                {
                    WindowFocusState.instance.m_WasMaximizedBeforePlay = (maximizedWindow != null);
                    if (maximizedWindow != null)
                    {
                        result = maximizedWindow;
                        return(result);
                    }
                }
                else if (WindowFocusState.instance.m_WasMaximizedBeforePlay)
                {
                    result = maximizedWindow;
                    return(result);
                }
                if (maximizedWindow)
                {
                    WindowLayout.Unmaximize(maximizedWindow);
                }
                EditorWindow editorWindow = WindowLayout.TryFocusAppropriateWindow(entering);
                if (editorWindow)
                {
                    result = editorWindow;
                }
                else if (entering)
                {
                    EditorWindow editorWindow2 = WindowLayout.FindEditorWindowOfType(typeof(SceneView));
                    GameView     gameView;
                    if (editorWindow2 && editorWindow2.m_Parent is DockArea)
                    {
                        DockArea dockArea = editorWindow2.m_Parent as DockArea;
                        if (dockArea)
                        {
                            WindowFocusState.instance.m_LastWindowTypeInSameDock = editorWindow2.GetType().ToString();
                            gameView = ScriptableObject.CreateInstance <GameView>();
                            dockArea.AddTab(gameView);
                            result = gameView;
                            return(result);
                        }
                    }
                    gameView = ScriptableObject.CreateInstance <GameView>();
                    gameView.Show(true);
                    gameView.Focus();
                    result = gameView;
                }
                else
                {
                    result = editorWindow;
                }
            }
            return(result);
        }
示例#31
0
        public void SplitGUI(Event evt)
        {
            if (this.splitState == null)
            {
                this.SetupSplitter();
            }
            SplitView parent = base.parent as SplitView;

            if (parent != null)
            {
                Event event2 = new Event(evt);
                event2.mousePosition += new Vector2(base.position.x, base.position.y);
                parent.SplitGUI(event2);
                if (event2.type == EventType.Used)
                {
                    evt.Use();
                }
            }
            float num       = !this.vertical ? evt.mousePosition.x : evt.mousePosition.y;
            int   controlID = GUIUtility.GetControlID(0x857b3, FocusType.Passive);

            this.controlID = controlID;
            EventType typeForControl = evt.GetTypeForControl(controlID);

            if (typeForControl == EventType.MouseDown)
            {
                if (base.children.Length != 1)
                {
                    int num3 = !this.vertical ? ((int)base.children[0].position.x) : ((int)base.children[0].position.y);
                    for (int i = 0; i < (base.children.Length - 1); i++)
                    {
                        if (i >= this.splitState.realSizes.Length)
                        {
                            DockArea current = GUIView.current as DockArea;
                            string   str     = "Non-dock area " + GUIView.current.GetType();
                            if (((current != null) && (current.m_Selected < current.m_Panes.Count)) && (current.m_Panes[current.m_Selected] != null))
                            {
                                str = current.m_Panes[current.m_Selected].GetType().ToString();
                            }
                            if (Unsupported.IsDeveloperBuild())
                            {
                                Debug.LogError(string.Concat(new object[] { "Real sizes out of bounds for: ", str, " index: ", i, " RealSizes: ", this.splitState.realSizes.Length }));
                            }
                            this.SetupSplitter();
                        }
                        Rect rect5 = !this.vertical ? new Rect((float)((num3 + this.splitState.realSizes[i]) - (this.splitState.splitSize / 2)), base.children[0].position.y, (float)this.splitState.splitSize, base.children[0].position.height) : new Rect(base.children[0].position.x, (float)((num3 + this.splitState.realSizes[i]) - (this.splitState.splitSize / 2)), base.children[0].position.width, (float)this.splitState.splitSize);
                        if (rect5.Contains(evt.mousePosition))
                        {
                            this.splitState.splitterInitialOffset = (int)num;
                            this.splitState.currentActiveSplitter = i;
                            GUIUtility.hotControl = controlID;
                            evt.Use();
                            break;
                        }
                        num3 += this.splitState.realSizes[i];
                    }
                }
            }
            else if (typeForControl == EventType.MouseDrag)
            {
                if (((base.children.Length > 1) && (GUIUtility.hotControl == controlID)) && (this.splitState.currentActiveSplitter >= 0))
                {
                    int diff = ((int)num) - this.splitState.splitterInitialOffset;
                    if (diff != 0)
                    {
                        this.splitState.splitterInitialOffset = (int)num;
                        this.splitState.DoSplitter(this.splitState.currentActiveSplitter, this.splitState.currentActiveSplitter + 1, diff);
                    }
                    this.SetupRectsFromSplitter();
                    evt.Use();
                }
            }
            else if ((typeForControl == EventType.MouseUp) && (GUIUtility.hotControl == controlID))
            {
                GUIUtility.hotControl = 0;
            }
        }
示例#32
0
        public bool PerformDrop(EditorWindow w, DropInfo di, Vector2 screenPos)
        {
            int      userData  = (int)di.userData;
            DockArea instance1 = ScriptableObject.CreateInstance <DockArea>();
            Rect     rect      = di.rect;

            if (userData == -1 || userData == -2 || userData == -3)
            {
                bool flag1 = userData == -2;
                bool flag2 = userData == -1;
                this.splitState = (SplitterState)null;
                if (this.vertical == flag2 || this.children.Length < 2)
                {
                    this.vertical = flag2;
                    rect.x       -= this.screenPosition.x;
                    rect.y       -= this.screenPosition.y;
                    this.MakeRoomForRect(rect);
                    this.AddChild((View)instance1, !flag1 ? this.children.Length : 0);
                    instance1.position = rect;
                }
                else
                {
                    SplitView instance2 = ScriptableObject.CreateInstance <SplitView>();
                    Rect      position  = this.position;
                    instance2.vertical = flag2;
                    instance2.position = new Rect(position.x, position.y, position.width, position.height);
                    if ((Object)this.window.mainView == (Object)this)
                    {
                        this.window.mainView = (View)instance2;
                    }
                    else
                    {
                        this.parent.AddChild((View)instance2, this.parent.IndexOfChild((View)this));
                    }
                    instance2.AddChild((View)this);
                    this.position = new Rect(0.0f, 0.0f, position.width, position.height);
                    Rect r = rect;
                    r.x -= this.screenPosition.x;
                    r.y -= this.screenPosition.y;
                    instance2.MakeRoomForRect(r);
                    instance1.position = r;
                    instance2.AddChild((View)instance1, !flag1 ? 1 : 0);
                }
            }
            else if (userData < 1000)
            {
                Rect r = rect;
                r.x -= this.screenPosition.x;
                r.y -= this.screenPosition.y;
                this.MakeRoomForRect(r);
                this.AddChild((View)instance1, userData);
                instance1.position = r;
            }
            else
            {
                int idx = userData % 1000;
                if (this.children.Length != 1)
                {
                    SplitView instance2 = ScriptableObject.CreateInstance <SplitView>();
                    instance2.vertical = !this.vertical;
                    Rect position = this.children[idx].position;
                    instance2.AddChild(this.children[idx]);
                    this.AddChild((View)instance2, idx);
                    instance2.position = position;
                    // ISSUE: explicit reference operation
                    // ISSUE: variable of a reference type
                    Rect& local = @position;
                    float num1  = 0.0f;
                    position.y = num1;
                    double num2 = (double)num1;
                    // ISSUE: explicit reference operation
                    (^ local).x = (float)num2;
                    instance2.children[0].position = position;
                    Rect r = rect;
                    r.x -= instance2.screenPosition.x;
                    r.y -= instance2.screenPosition.y;
                    instance2.MakeRoomForRect(r);
                    instance2.AddChild((View)instance1, userData >= 2000 ? 1 : 0);
                    instance1.position = r;
                }
                else
                {
                    this.vertical = !this.vertical;
                    Rect r = rect;
                    r.x -= this.screenPosition.x;
                    r.y -= this.screenPosition.y;
                    this.MakeRoomForRect(r);
                    this.AddChild((View)instance1, userData != 1000 ? 1 : 0);
                    instance1.position = r;
                }
            }
            DockArea.s_OriginalDragSource.RemoveTab(w);
            w.m_Parent = (HostView)instance1;
            instance1.AddTab(w);
            this.Reflow();
            SplitView.RecalcMinMaxAndReflowAll(this);
            instance1.MakeVistaDWMHappyDance();
            return(true);
        }
示例#33
0
        public void SplitGUI(Event evt)
        {
            if (this.splitState == null)
            {
                this.SetupSplitter();
            }
            SplitView parent = this.parent as SplitView;

            if ((bool)((Object)parent))
            {
                Event evt1 = new Event(evt);
                evt1.mousePosition += new Vector2(this.position.x, this.position.y);
                parent.SplitGUI(evt1);
                if (evt1.type == EventType.Used)
                {
                    evt.Use();
                }
            }
            float num1      = !this.vertical ? evt.mousePosition.x : evt.mousePosition.y;
            int   controlId = GUIUtility.GetControlID(546739, FocusType.Passive);

            this.controlID = controlId;
            switch (evt.GetTypeForControl(controlId))
            {
            case EventType.MouseDown:
                if (this.children.Length == 1)
                {
                    break;
                }
                int num2 = !this.vertical ? (int)this.children[0].position.x : (int)this.children[0].position.y;
                for (int index = 0; index < this.children.Length - 1; ++index)
                {
                    if (index >= this.splitState.realSizes.Length)
                    {
                        DockArea current = GUIView.current as DockArea;
                        string   str     = "Non-dock area " + (object)GUIView.current.GetType();
                        if ((bool)((Object)current) && current.m_Selected < current.m_Panes.Count && (bool)((Object)current.m_Panes[current.m_Selected]))
                        {
                            str = current.m_Panes[current.m_Selected].GetType().ToString();
                        }
                        if (Unsupported.IsDeveloperBuild())
                        {
                            Debug.LogError((object)("Real sizes out of bounds for: " + str + " index: " + (object)index + " RealSizes: " + (object)this.splitState.realSizes.Length));
                        }
                        this.SetupSplitter();
                    }
                    if ((!this.vertical ? new Rect((float)(num2 + this.splitState.realSizes[index] - this.splitState.splitSize / 2), this.children[0].position.y, (float)this.splitState.splitSize, this.children[0].position.height) : new Rect(this.children[0].position.x, (float)(num2 + this.splitState.realSizes[index] - this.splitState.splitSize / 2), this.children[0].position.width, (float)this.splitState.splitSize)).Contains(evt.mousePosition))
                    {
                        this.splitState.splitterInitialOffset = (int)num1;
                        this.splitState.currentActiveSplitter = index;
                        GUIUtility.hotControl = controlId;
                        evt.Use();
                        break;
                    }
                    num2 += this.splitState.realSizes[index];
                }
                break;

            case EventType.MouseUp:
                if (GUIUtility.hotControl != controlId)
                {
                    break;
                }
                GUIUtility.hotControl = 0;
                break;

            case EventType.MouseDrag:
                if (this.children.Length <= 1 || GUIUtility.hotControl != controlId || this.splitState.currentActiveSplitter < 0)
                {
                    break;
                }
                int diff = (int)num1 - this.splitState.splitterInitialOffset;
                if (diff != 0)
                {
                    this.splitState.splitterInitialOffset = (int)num1;
                    this.splitState.DoSplitter(this.splitState.currentActiveSplitter, this.splitState.currentActiveSplitter + 1, diff);
                }
                this.SetupRectsFromSplitter();
                evt.Use();
                break;
            }
        }
示例#34
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);
        }
示例#35
0
 private void DragTab(Rect pos, GUIStyle tabStyle)
 {
   int controlId = GUIUtility.GetControlID(FocusType.Passive);
   float tabWidth = this.GetTabWidth(pos.width);
   Event current = Event.current;
   if (DockArea.s_DragMode != 0 && GUIUtility.hotControl == 0)
   {
     PaneDragTab.get.Close();
     DockArea.ResetDragVars();
   }
   EventType typeForControl = current.GetTypeForControl(controlId);
   switch (typeForControl)
   {
     case EventType.MouseDown:
       if (pos.Contains(current.mousePosition) && GUIUtility.hotControl == 0)
       {
         int tabAtMousePos = this.GetTabAtMousePos(current.mousePosition, pos);
         if (tabAtMousePos < this.m_Panes.Count)
         {
           switch (current.button)
           {
             case 0:
               if (tabAtMousePos != this.selected)
                 this.selected = tabAtMousePos;
               GUIUtility.hotControl = controlId;
               DockArea.s_StartDragPosition = current.mousePosition;
               DockArea.s_DragMode = 0;
               current.Use();
               break;
             case 2:
               this.m_Panes[tabAtMousePos].Close();
               current.Use();
               break;
           }
         }
         else
           break;
       }
       else
         break;
     case EventType.MouseUp:
       if (GUIUtility.hotControl == controlId)
       {
         Vector2 screenPoint = GUIUtility.GUIToScreenPoint(current.mousePosition);
         if (DockArea.s_DragMode != 0)
         {
           DockArea.s_DragMode = 0;
           PaneDragTab.get.Close();
           EditorApplication.update -= new EditorApplication.CallbackFunction(DockArea.CheckDragWindowExists);
           if (DockArea.s_DropInfo != null && DockArea.s_DropInfo.dropArea != null)
           {
             DockArea.s_DropInfo.dropArea.PerformDrop(DockArea.s_DragPane, DockArea.s_DropInfo, screenPoint);
           }
           else
           {
             EditorWindow dragPane = DockArea.s_DragPane;
             DockArea.ResetDragVars();
             this.RemoveTab(dragPane);
             Rect position = dragPane.position;
             position.x = screenPoint.x - position.width * 0.5f;
             position.y = screenPoint.y - position.height * 0.5f;
             if (Application.platform == RuntimePlatform.WindowsEditor)
               position.y = Mathf.Max(InternalEditorUtility.GetBoundsOfDesktopAtPoint(screenPoint).y, position.y);
             EditorWindow.CreateNewWindowForEditorWindow(dragPane, false, false);
             dragPane.position = dragPane.m_Parent.window.FitWindowRectToScreen(position, true, true);
             GUIUtility.hotControl = 0;
             GUIUtility.ExitGUI();
           }
           DockArea.ResetDragVars();
         }
         GUIUtility.hotControl = 0;
         current.Use();
         break;
       }
       break;
     case EventType.MouseDrag:
       if (GUIUtility.hotControl == controlId)
       {
         Vector2 vector2 = current.mousePosition - DockArea.s_StartDragPosition;
         current.Use();
         Rect screenPosition = this.screenPosition;
         if (DockArea.s_DragMode == 0 && (double) vector2.sqrMagnitude > 99.0)
         {
           DockArea.s_DragMode = 1;
           DockArea.s_PlaceholderPos = this.selected;
           DockArea.s_DragPane = this.m_Panes[this.selected];
           DockArea.s_IgnoreDockingForView = this.m_Panes.Count != 1 ? (View) null : (View) this;
           DockArea.s_OriginalDragSource = this;
           PaneDragTab.get.content = DockArea.s_DragPane.titleContent;
           this.Internal_SetAsActiveWindow();
           PaneDragTab.get.GrabThumbnail();
           PaneDragTab.get.Show(new Rect((float) ((double) pos.x + (double) screenPosition.x + (double) tabWidth * (double) this.selected), pos.y + screenPosition.y, tabWidth, pos.height), GUIUtility.GUIToScreenPoint(current.mousePosition));
           EditorApplication.update += new EditorApplication.CallbackFunction(DockArea.CheckDragWindowExists);
           GUIUtility.ExitGUI();
         }
         if (DockArea.s_DragMode == 1)
         {
           DropInfo di = (DropInfo) null;
           ContainerWindow[] windows = ContainerWindow.windows;
           Vector2 screenPoint = GUIUtility.GUIToScreenPoint(current.mousePosition);
           ContainerWindow inFrontOf = (ContainerWindow) null;
           foreach (ContainerWindow containerWindow in windows)
           {
             foreach (View allChild in containerWindow.mainView.allChildren)
             {
               IDropArea dropArea = allChild as IDropArea;
               if (dropArea != null)
                 di = dropArea.DragOver(DockArea.s_DragPane, screenPoint);
               if (di != null)
                 break;
             }
             if (di != null)
             {
               inFrontOf = containerWindow;
               break;
             }
           }
           if (di == null)
             di = new DropInfo((IDropArea) null);
           if (di.type != DropInfo.Type.Tab)
             DockArea.s_PlaceholderPos = -1;
           DockArea.s_DropInfo = di;
           if ((bool) ((UnityEngine.Object) PaneDragTab.get.m_Window))
           {
             PaneDragTab.get.SetDropInfo(di, screenPoint, inFrontOf);
             break;
           }
           break;
         }
         break;
       }
       break;
     case EventType.Repaint:
       float xMin = pos.xMin;
       int num = 0;
       if ((bool) ((UnityEngine.Object) this.actualView))
       {
         for (int index = 0; index < this.m_Panes.Count; ++index)
         {
           if (!((UnityEngine.Object) DockArea.s_DragPane == (UnityEngine.Object) this.m_Panes[index]))
           {
             if (DockArea.s_DropInfo != null && object.ReferenceEquals((object) DockArea.s_DropInfo.dropArea, (object) this) && DockArea.s_PlaceholderPos == num)
               xMin += tabWidth;
             Rect rect = new Rect(xMin, pos.yMin, tabWidth, pos.height);
             float x = Mathf.Round(rect.x);
             Rect position = new Rect(x, rect.y, Mathf.Round(rect.x + rect.width) - x, rect.height);
             tabStyle.Draw(position, this.m_Panes[index].titleContent, false, false, index == this.selected, this.hasFocus);
             xMin += tabWidth;
             ++num;
           }
         }
         break;
       }
       Rect rect1 = new Rect(xMin, pos.yMin, tabWidth, pos.height);
       float x1 = Mathf.Round(rect1.x);
       Rect position1 = new Rect(x1, rect1.y, Mathf.Round(rect1.x + rect1.width) - x1, rect1.height);
       tabStyle.Draw(position1, "Failed to load", false, false, true, false);
       break;
     default:
       if (typeForControl == EventType.ContextClick && pos.Contains(current.mousePosition) && GUIUtility.hotControl == 0)
       {
         int tabAtMousePos = this.GetTabAtMousePos(current.mousePosition, pos);
         if (tabAtMousePos < this.m_Panes.Count)
         {
           this.PopupGenericMenu(this.m_Panes[tabAtMousePos], new Rect(current.mousePosition.x, current.mousePosition.y, 0.0f, 0.0f));
           break;
         }
         break;
       }
       break;
   }
   this.selected = Mathf.Clamp(this.selected, 0, this.m_Panes.Count - 1);
 }