예제 #1
0
    public static KeyCode KeyCodeField(Rect controlRect, KeyCode keyCode)
    {
        int controlID = GUIUtility.GetControlID(FocusType.Keyboard);

        KeyCode retVal = keyCode;

        Event evt = Event.current;

        switch (evt.GetTypeForControl(controlID))
        {
        case EventType.Repaint:
        {
            GUIStyle style = GUI.skin.GetStyle("TextField");
            if (style == GUIStyle.none)
            {
                break;
            }
            style.Draw(controlRect, new GUIContent(keyCode.ToString()), controlID);
            break;
        }

        case EventType.MouseDown:
        {
            if (controlRect.Contains(Event.current.mousePosition) && Event.current.button == 0 && GUIUtility.hotControl == 0)
            {
                GUIUtility.hotControl      = controlID;
                GUIUtility.keyboardControl = controlID;
                evt.Use();
            }
            break;
        }

        case EventType.MouseUp:
        {
            if (GUIUtility.hotControl == controlID)
            {
                GUIUtility.hotControl = 0;
                evt.Use();
            }
            break;
        }

        case EventType.KeyDown:
        {
            if (GUIUtility.keyboardControl == controlID)
            {
                retVal = Event.current.keyCode;
                GUIUtility.hotControl      = 0;
                GUIUtility.keyboardControl = 0;
                evt.Use();
            }
            break;
        }

        case EventType.KeyUp:
        {
            break;
        }
        }
        return(retVal);
    }
예제 #2
0
        /// <summary> Main GUI Function </summary>
        /// <param name="position">Rect to draw this property in</param>
        /// <param name="property">Property to edit</param>
        /// <param name="label">Display GUIContent of Property</param>
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            bool hasChanged          = false;
            int  originalIndentLevel = EditorGUI.indentLevel;

            EditorGUI.indentLevel = 0;

            EditorGUI.BeginProperty(position, label, property);
            GUISkin editorSkin = null;

            if (Event.current.type == EventType.Repaint)
            {
                editorSkin = EditorGUIUtility.GetBuiltinSkin(EditorSkin.Inspector);
            }

            SerializedProperty nameProp         = property.FindPropertyRelative("m_name");
            SerializedProperty startProp        = property.FindPropertyRelative("m_min");
            SerializedProperty endProp          = property.FindPropertyRelative("m_max");
            SerializedProperty startFalloffProp = property.FindPropertyRelative("m_minFalloff");
            SerializedProperty endFalloffProp   = property.FindPropertyRelative("m_maxFalloff");
            SerializedProperty invertProp       = property.FindPropertyRelative("m_invert");

            Vector2 nameSize = new Vector2(EditorGUIUtility.labelWidth, EditorGUIUtility.singleLineHeight);
            Rect    nameRect = new Rect(position.position, nameSize);

            nameRect.xMin += originalIndentLevel * 15f;
            float minMaxWidth = Mathf.Min(80f, ((position.width - nameRect.width) * 0.3f + 10f) * 0.5f);
            Rect  minRect     = new Rect(nameRect.xMax, position.y, minMaxWidth, nameSize.y);
            Rect  maxRect     = new Rect(position.xMax - minMaxWidth, position.y, minMaxWidth, nameSize.y);

            EditorGUI.BeginChangeCheck();
            string newName = EditorGUI.TextField(nameRect, nameProp.stringValue);

            if (string.IsNullOrEmpty(newName))
            {
                EditorGUI.LabelField(nameRect, "Name", EditorStyles.centeredGreyMiniLabel);
            }
            if (EditorGUI.EndChangeCheck())
            {
                hasChanged           = true;
                nameProp.stringValue = newName;
            }
            float start = startProp.floatValue, end = endProp.floatValue;

            EditorGUI.BeginChangeCheck();
            start = EditorGUI.FloatField(minRect, start);
            if (EditorGUI.EndChangeCheck())
            {
                hasChanged = true;
                if (start > end)
                {
                    start = end;
                }
                startProp.floatValue = Mathf.Clamp01(start);
            }
            EditorGUI.BeginChangeCheck();
            end = EditorGUI.FloatField(maxRect, end);
            if (EditorGUI.EndChangeCheck())
            {
                hasChanged = true;
                if (end < start)
                {
                    end = start;
                }
                endProp.floatValue = Mathf.Clamp01(end);
            }
            #region Slider
            Rect  barRect     = new Rect(minRect.xMax + 5f, position.y, maxRect.xMin - minRect.xMax - 10f, nameSize.y);
            float totalWidth  = barRect.width - 11f;
            float totalHeight = barRect.height;
            Rect  drawRect    = new Rect(barRect.x + totalWidth * startProp.floatValue, barRect.y + totalHeight * 0.165f, totalWidth * (endProp.floatValue - startProp.floatValue) + 10f, totalHeight * 0.67f);
            //Check for Events
            Rect sliderPanRect   = new Rect(drawRect.xMin + 5f, drawRect.y, drawRect.width - 10f, totalHeight * 0.67f);
            Rect sliderEndRect   = new Rect(drawRect.xMax - 5f, drawRect.y, 5f, totalHeight * 0.67f);
            Rect sliderBeginRect = new Rect(drawRect.xMin, drawRect.y, 5f, totalHeight * 0.67f);
            #region Mouse Events
            EditorGUIUtility.AddCursorRect(sliderEndRect, MouseCursor.SplitResizeLeftRight);
            EditorGUIUtility.AddCursorRect(sliderBeginRect, MouseCursor.SplitResizeLeftRight);
            //check for drag of either ends or slider
            if (Event.current.type == EventType.MouseDown && Event.current.button == 0)
            {
                if (sliderEndRect.Contains(Event.current.mousePosition))
                {
                    isDraggingThis           = true;
                    curSliderEditingStartPos = Event.current.mousePosition.x;
                    curSliderEditingStartMax = endProp.floatValue;
                    curSliderEditingType     = 3;
                    Event.current.Use();
                }
                else if (sliderBeginRect.Contains(Event.current.mousePosition))
                {
                    isDraggingThis           = true;
                    curSliderEditingStartPos = Event.current.mousePosition.x;
                    curSliderEditingStartMin = startProp.floatValue;
                    curSliderEditingType     = 2;
                    Event.current.Use();
                }
                else if (sliderPanRect.Contains(Event.current.mousePosition))
                {
                    isDraggingThis           = true;
                    curSliderEditingStartPos = Event.current.mousePosition.x;
                    curSliderEditingStartMin = startProp.floatValue;
                    curSliderEditingStartMax = endProp.floatValue;
                    curSliderEditingType     = 1;
                    Event.current.Use();
                }
            }
            else if (Event.current.type == EventType.MouseDrag && isDraggingThis)
            {
                hasChanged = true;
                float moveAmount = (Event.current.mousePosition.x - curSliderEditingStartPos) / totalWidth;
                switch (curSliderEditingType)
                {
                case 1:
                    moveAmount           = Mathf.Clamp(moveAmount, -curSliderEditingStartMin, 1f - curSliderEditingStartMax);
                    startProp.floatValue = Mathf.Clamp(curSliderEditingStartMin + moveAmount, 0f, 1f);
                    endProp.floatValue   = Mathf.Clamp(curSliderEditingStartMax + moveAmount, 0f, 1f);
                    break;

                case 2:
                    startProp.floatValue = Mathf.Clamp(curSliderEditingStartMin + moveAmount, 0f, endProp.floatValue);
                    break;

                case 3:
                    endProp.floatValue = Mathf.Clamp(curSliderEditingStartMax + moveAmount, startProp.floatValue, 1f);
                    break;

                default:
                    break;
                }
                Event.current.Use();
            }
            else if (Event.current.type == EventType.MouseUp)
            {
                isDraggingThis           = false;
                curSliderEditingType     = 0;
                curSliderEditingStartPos = 0f;
                curSliderEditingStartMin = 0f;
                curSliderEditingStartMax = 0f;
            }
            #endregion
            //Draw slider (Repaint event only)
            if (Event.current.type == EventType.Repaint)
            {
                editorSkin.horizontalSlider.Draw(barRect, false, false, false, false);
                if (!invertProp.boolValue)   //normal display
                {
                    editorSkin.button.Draw(drawRect, false, false, false, false);
                }
                else     //invert display
                {
                    GUIStyle leftButton  = editorSkin.GetStyle("ButtonLeft") ?? editorSkin.button;
                    GUIStyle rightButton = editorSkin.GetStyle("ButtonRight") ?? editorSkin.button;
                    Rect     drawRect2   = drawRect;
                    drawRect2.xMin = drawRect.xMax - 5f;
                    drawRect2.xMax = barRect.xMax + 4f;
                    drawRect.xMax  = drawRect.xMin + 5f;
                    drawRect.xMin  = barRect.xMin - 5f;
                    if (startProp.floatValue > 0f)
                    {
                        rightButton.Draw(drawRect, false, false, false, false);
                    }
                    if (endProp.floatValue < 1f)
                    {
                        leftButton.Draw(drawRect2, false, false, false, false);
                    }
                }
            }
            #endregion

            nameRect.y += nameRect.height + EditorGUIUtility.standardVerticalSpacing;
            EditorGUI.BeginChangeCheck();
            invertProp.boolValue = EditorGUI.ToggleLeft(nameRect, invertProp.displayName, invertProp.boolValue);
            if (EditorGUI.EndChangeCheck())
            {
                hasChanged = true;
            }
            minRect.y = nameRect.y;
            GUI.Label(minRect, "Falloff");
            Rect falloffRect = new Rect(minRect.xMax, nameRect.y, (maxRect.xMax - minRect.xMax - EditorGUIUtility.standardVerticalSpacing) / 2f, nameSize.y);
            EditorGUI.BeginChangeCheck();
            startFalloffProp.floatValue = Mathf.Clamp01(EditorGUI.FloatField(falloffRect, startFalloffProp.floatValue));
            falloffRect.x            += falloffRect.width + EditorGUIUtility.standardVerticalSpacing;
            endFalloffProp.floatValue = Mathf.Clamp01(EditorGUI.FloatField(falloffRect, endFalloffProp.floatValue));
            if (EditorGUI.EndChangeCheck())
            {
                hasChanged = true;
            }
            EditorGUI.EndProperty();
            EditorGUI.indentLevel = originalIndentLevel;
            if (hasChanged && MainWindowEditor.Instance != null)
            {
                MainWindowEditor.Instance.Repaint();
            }
        }
예제 #3
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)
                    {
                        int button = current.button;
                        if (button != 0)
                        {
                            if (button == 2)
                            {
                                this.m_Panes[tabAtMousePos].Close();
                                current.Use();
                            }
                        }
                        else
                        {
                            if (tabAtMousePos != this.selected)
                            {
                                this.selected = tabAtMousePos;
                            }
                            GUIUtility.hotControl        = controlID;
                            DockArea.s_StartDragPosition = current.mousePosition;
                            DockArea.s_DragMode          = 0;
                            current.Use();
                        }
                    }
                }
                goto IL_744;

            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();
                        Delegate arg_49D_0 = EditorApplication.update;
                        if (DockArea.< > f__mg$cache1 == null)
                        {
                            DockArea.< > f__mg$cache1 = new EditorApplication.CallbackFunction(DockArea.CheckDragWindowExists);
                        }
                        EditorApplication.update = (EditorApplication.CallbackFunction)Delegate.Remove(arg_49D_0, DockArea.< > f__mg$cache1);
                        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_744;

            case EventType.MouseMove:
            case EventType.KeyDown:
            case EventType.KeyUp:
            case EventType.ScrollWheel:
IL_6F:
                if (typeForControl != EventType.ContextClick)
                {
                    goto IL_744;
                }
                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_744;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == controlID)
                {
                    Vector2 vector2 = current.mousePosition - DockArea.s_StartDragPosition;
                    current.Use();
                    Rect screenPosition = base.screenPosition;
                    bool flag           = base.window.showMode != ShowMode.MainWindow || this.GetMainWindowPaneCount() > 1;
                    if (DockArea.s_DragMode == 0 && vector2.sqrMagnitude > 99f && flag)
                    {
                        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.Show(new Rect(pos.x + screenPosition.x + tabWidth * (float)this.selected, pos.y + screenPosition.y, tabWidth, pos.height), DockArea.s_DragPane.titleContent, base.position.size, GUIUtility.GUIToScreenPoint(current.mousePosition));
                        Delegate arg_2F8_0 = EditorApplication.update;
                        if (DockArea.< > f__mg$cache0 == null)
                        {
                            DockArea.< > f__mg$cache0 = new EditorApplication.CallbackFunction(DockArea.CheckDragWindowExists);
                        }
                        EditorApplication.update = (EditorApplication.CallbackFunction)Delegate.Combine(arg_2F8_0, DockArea.< > f__mg$cache0);
                        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];
                            SplitView       rootSplitView   = containerWindow.rootSplitView;
                            if (rootSplitView != null)
                            {
                                dropInfo = rootSplitView.DragOverRootView(vector3);
                            }
                            if (dropInfo == null)
                            {
                                View[] allChildren = containerWindow.rootView.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_744;

            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].titleContent, 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_744;
            }
            }
            goto IL_6F;
IL_744:
            this.selected = Mathf.Clamp(this.selected, 0, this.m_Panes.Count - 1);
        }
예제 #4
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);
                    if (sel != -1 && sel < m_Panes.Count && !ContainerWindow.s_Modal)
                    {
                        PopupGenericMenu(m_Panes[sel], new Rect(evt.mousePosition.x, evt.mousePosition.y, 0, 0));
                    }
                }
                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

                    // 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;
                        // 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);
                        }
                        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);

                            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);
        }
        public override void OnInspectorGUI()
        {
            var editorAssembly = Assembly.GetAssembly(typeof(Editor));
            var type           = editorAssembly.GetType("UnityEditor.RectTransformEditor");

            if (mOldEditor == null)
            {
                mOldEditor = CreateEditor(target, type);
            }

            mOldEditor.OnInspectorGUI();

            var lineStyle = new GUIStyle();

            lineStyle.normal.background = EditorGUIUtility.whiteTexture;
            lineStyle.stretchWidth      = true;
            lineStyle.margin            = new RectOffset(0, 0, 7, 7);

            var c = GUI.color;
            var p = GUILayoutUtility.GetRect(GUIContent.none, lineStyle, GUILayout.Height(1));

            p.width -= 70;
            if (Event.current.type == EventType.Repaint)
            {
                GUI.color = EditorGUIUtility.isProSkin ?
                            new Color(0.157f, 0.157f, 0.157f) : new Color(0.5f, 0.5f, 0.5f);
                lineStyle.Draw(p, false, false, false, false);
            }

            EditorGUI.LabelField(new Rect(p.xMax, p.y - 7, 70, 20), "Extensions");
            GUI.color = c;

            var concertTarget = target as RectTransform;

            EditorGUILayout.BeginHorizontal(EditorStyles.helpBox);
            EditorGUILayout.LabelField("Reset");
            if (GUILayout.Button("P"))
            {
                Undo.RecordObject(concertTarget.transform, GetType().FullName);

                concertTarget.localPosition = Vector3.zero;
            }
            if (GUILayout.Button("D"))
            {
                Undo.RecordObject(concertTarget.transform, GetType().FullName);

                concertTarget.sizeDelta = Vector2.zero;
            }
            if (GUILayout.Button("R"))
            {
                Undo.RecordObject(concertTarget.transform, GetType().FullName);

                concertTarget.localRotation = Quaternion.identity;
            }
            if (GUILayout.Button("S"))
            {
                Undo.RecordObject(concertTarget.transform, GetType().FullName);

                concertTarget.localScale = Vector3.one;
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal(EditorStyles.helpBox);
            EditorGUILayout.LabelField("Locked Scaling Ratio");

            var rect = EditorGUILayout.GetControlRect(false);
            var xMax = rect.xMax;

            rect.xMin             = xMax - Mathf.Min(149, rect.width);
            mIsLockedScalingRatio = GUI.Toggle(rect, mIsLockedScalingRatio, "Locked", EditorStyles.miniButton);

            if (mIsLockedScalingRatio)
            {
                if (!mIsBoundEditorUpdate)
                {
                    EditorApplication.update -= onEditorApplicationUpdate;
                    EditorApplication.update += onEditorApplicationUpdate;

                    mCacheDeltaSizeRatio = (concertTarget.sizeDelta.y / concertTarget.sizeDelta.x + 0.00001f);
                }
            }
            else
            {
                if (mIsBoundEditorUpdate)
                {
                    EditorApplication.update -= onEditorApplicationUpdate;
                    mIsBoundEditorUpdate      = false;
                }
            }

            EditorGUILayout.EndHorizontal();
        }
예제 #6
0
    /// <summary>
    /// Draw a control dot at the specified world position.
    /// </summary>

    static public void DrawKnob(Vector3 point, bool selected, bool canResize, int id)
    {
        if (mGreyDot == null)
        {
            mGreyDot = "sv_label_0";
        }
        if (mBlueDot == null)
        {
            mBlueDot = "sv_label_1";
        }
        if (mGreenDot == null)
        {
            mGreenDot = "sv_label_3";
        }
        if (mYellowDot == null)
        {
            mYellowDot = "sv_label_4";
        }
        if (mOrangeDot == null)
        {
            mOrangeDot = "sv_label_5";
        }
        if (mRedDot == null)
        {
            mRedDot = "sv_label_6";
        }

        var screenPoint = HandleUtility.WorldToGUIPoint(point);

#if UNITY_4_3 || UNITY_4_5 || UNITY_4_6 || UNITY_4_7
        Rect rect = new Rect(screenPoint.x - 7f, screenPoint.y - 7f, 14f, 14f);
#else
        var rect = new Rect(screenPoint.x - 5f, screenPoint.y - 9f, 14f, 14f);
#endif

        if (selected)
        {
            if (NGUISettings.colorMode == NGUISettings.ColorMode.Orange)
            {
                mRedDot.Draw(rect, GUIContent.none, id);
            }
            else
            {
                mOrangeDot.Draw(rect, GUIContent.none, id);
            }
        }
        else if (canResize)
        {
            if (NGUISettings.colorMode == NGUISettings.ColorMode.Orange)
            {
                mOrangeDot.Draw(rect, GUIContent.none, id);
            }
            else if (NGUISettings.colorMode == NGUISettings.ColorMode.Green)
            {
                mGreenDot.Draw(rect, GUIContent.none, id);
            }
            else
            {
                mBlueDot.Draw(rect, GUIContent.none, id);
            }
        }
        else
        {
            mGreyDot.Draw(rect, GUIContent.none, id);
        }
    }
예제 #7
0
    public static Sprite SpriteField(Rect rect, Sprite sprite)
    {
        var id  = GUIUtility.GetControlID(FocusType.Keyboard, rect);
        var evt = Event.current;

        if (evt.type == EventType.Repaint)
        {
            EditorStyles.objectFieldThumb.Draw(rect, GUIContent.none, id, DragAndDrop.activeControlID == id);

            if (sprite)
            {
                var spriteTexture = AssetPreview.GetAssetPreview(sprite);

                if (spriteTexture)
                {
                    spriteStyle.normal.background = spriteTexture;
                    spriteStyle.Draw(rect, false, false, false, false);
                }
                else
                {
                    Resources.FindObjectsOfTypeAll <EditorWindow>().ToList().ForEach(w => w.Repaint());
                }
            }
        }

        var buttonRect = new Rect(rect);

        buttonRect.x     += buttonRect.width * 0.5f;
        buttonRect.width *= 0.5f;
        buttonRect.y     += rect.height - 16;
        buttonRect.height = 16;

        if (evt.commandName == "ObjectSelectorUpdated" &&
            id == EditorGUIUtility.GetObjectPickerControlID())
        {
            sprite = EditorGUIUtility.GetObjectPickerObject() as Sprite;
            HandleUtility.Repaint();
        }
        if (rect.Contains(evt.mousePosition))
        {
            switch (evt.type)
            {
            case EventType.DragUpdated:
            case EventType.DragPerform:
                if (DragAndDrop.objectReferences.Length == 1)
                {
                    DragAndDrop.AcceptDrag();
                }
                DragAndDrop.activeControlID = id;
                DragAndDrop.visualMode      = DragAndDropVisualMode.Generic;
                break;

            case EventType.DragExited:
                if (DragAndDrop.objectReferences.Length == 1)
                {
                    var reference = DragAndDrop.objectReferences[0] as Sprite;
                    if (reference != null)
                    {
                        sprite = reference;
                        HandleUtility.Repaint();
                    }
                }
                break;
            }
        }

        bool hitEnter = evt.type == EventType.KeyDown && (evt.keyCode == KeyCode.Return || evt.keyCode == KeyCode.KeypadEnter) && EditorGUIUtility.keyboardControl == id;

        if (GUI.Button(buttonRect, "select", EditorStyles.objectFieldThumb.name + "Overlay2") || hitEnter)
        {
            EditorGUIUtility.ShowObjectPicker <Sprite>(sprite, false, "", id);
            evt.Use();
            GUIUtility.ExitGUI();
        }

        return(sprite);
    }
예제 #8
0
        private void SelectNodes()
        {
            int controlID = GUIUtility.GetControlID(FocusType.Passive);

            switch (_currentEvent.rawType)
            {
            case EventType.MouseDown:
                GUIUtility.hotControl   = controlID;
                _selectionStartPosition = _mousePosition;

                Decorator decorator = MouseOverDecorator();
                Service   service   = MouseOverService();
                Node      node      = MouseOverNode();

                if (decorator != null)
                {
                    _selection.Clear();
                    _serviceSelection.Clear();

                    if (!_decoratorSelection.Contains(decorator))
                    {
                        _decoratorSelection.Clear();
                        _decoratorSelection.Add(decorator);
                    }

                    GUIUtility.hotControl      = 0;
                    GUIUtility.keyboardControl = 0;
                    UpdateUnitySelection();
                    return;
                }
                else if (service != null)
                {
                    _selection.Clear();
                    _decoratorSelection.Clear();

                    if (!_serviceSelection.Contains(service))
                    {
                        _serviceSelection.Clear();
                        _serviceSelection.Add(service);
                    }

                    GUIUtility.hotControl      = 0;
                    GUIUtility.keyboardControl = 0;
                    UpdateUnitySelection();
                    return;
                }
                else if (node != null)
                {
                    _decoratorSelection.Clear();
                    _serviceSelection.Clear();

                    if (_fromNode != null)
                    {
                        if (_fromNode != node)
                        {
                            if (_isTopSelect)
                            {
                                if (!ArrayUtility.Contains(node.childNodes, _fromNode) && _fromNode.parentNode != node)
                                {
                                    AddTransition(node, _fromNode);
                                }
                            }
                            else
                            {
                                if (!ArrayUtility.Contains(_fromNode.childNodes, node))
                                {
                                    AddTransition(_fromNode, node);
                                }
                            }
                        }
                        _fromNode = null;
                        _selection.Clear();
                        _selection.Add(node);
                        GUIUtility.hotControl      = 0;
                        GUIUtility.keyboardControl = 0;
                        return;
                    }

                    if (EditorGUI.actionKey || _currentEvent.shift)
                    {
                        if (!_selection.Contains(node))
                        {
                            _selection.Add(node);
                        }
                        else
                        {
                            _selection.Remove(node);
                        }
                    }
                    else if (!_selection.Contains(node))
                    {
                        _selection.Clear();
                        _selection.Add(node);
                    }

                    GUIUtility.hotControl      = 0;
                    GUIUtility.keyboardControl = 0;
                    UpdateUnitySelection();
                    return;
                }

                _fromNode      = null;
                _selectionMode = SelectionMode.Pick;
                if (!EditorGUI.actionKey && !_currentEvent.shift)
                {
                    _selection.Clear();
                    _decoratorSelection.Clear();
                    _serviceSelection.Clear();
                    UpdateUnitySelection();
                }
                _currentEvent.Use();
                break;

            case EventType.MouseUp:
                if (GUIUtility.hotControl == controlID)
                {
                    _selectionMode        = SelectionMode.None;
                    GUIUtility.hotControl = 0;
                    _currentEvent.Use();
                }
                break;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == controlID && !EditorGUI.actionKey && !_currentEvent.shift && (_selectionMode == SelectionMode.Pick || _selectionMode == SelectionMode.Rect))
                {
                    _selectionMode = SelectionMode.Rect;
                    SelectNodesInRect(FromToRect(_selectionStartPosition, _mousePosition));
                    _currentEvent.Use();
                }
                break;

            case EventType.Repaint:
                if (GUIUtility.hotControl == controlID && _selectionMode == SelectionMode.Rect)
                {
                    GUIStyle selectionStyle = "SelectionRect";
                    selectionStyle.Draw(FromToRect(_selectionStartPosition, _mousePosition), false, false, false, false);
                }
                break;
            }
        }
예제 #9
0
        public override void OnPreviewGUI(Rect r, GUIStyle background)
        {
            VideoClip clip = target as VideoClip;

            Event evt = Event.current;

            if (evt.type != EventType.Repaint &&
                evt.type != EventType.Layout &&
                evt.type != EventType.Used)
            {
                switch (evt.type)
                {
                case EventType.MouseDown:
                {
                    if (r.Contains(evt.mousePosition))
                    {
                        if (m_PlayingClip != null)
                        {
                            if (m_PreviewID.Empty() || !VideoUtil.IsPreviewPlaying(m_PreviewID))
                            {
                                PlayPreview();
                            }
                            else
                            {
                                StopPreview();
                            }
                        }
                        evt.Use();
                    }
                }
                break;
                }
                return;
            }

            bool useVideoTexture = true;

            bool needRepaint = clip != m_PlayingClip ||
                               (!m_PreviewID.Empty() &&
                                VideoUtil.IsPreviewPlaying(m_PreviewID));

            if (clip != m_PlayingClip)
            {
                StopPreview();
                m_PlayingClip = clip;
            }

            Texture image = null;

            if (!m_PreviewID.Empty())
            {
                image = VideoUtil.GetPreviewTexture(m_PreviewID);
            }

            if (image == null || image.width == 0 || image.height == 0)
            {
                image           = GetAssetPreviewTexture();
                useVideoTexture = false;
            }

            if (image == null || image.width == 0 || image.height == 0)
            {
                return;
            }

            if (Event.current.type == EventType.Repaint)
            {
                background.Draw(r, false, false, false, false);
            }

            float previewWidth  = image.width;
            float previewHeight = image.height;

            if (m_PlayingClip.pixelAspectRatioDenominator > 0)
            {
                previewWidth *= (float)m_PlayingClip.pixelAspectRatioNumerator /
                                (float)m_PlayingClip.pixelAspectRatioDenominator;
            }

            float zoomLevel = 1.0f;

            if ((r.width / previewWidth * previewHeight) > r.height)
            {
                zoomLevel = r.height / previewHeight;
            }
            else
            {
                zoomLevel = r.width / previewWidth;
            }

            zoomLevel = Mathf.Clamp01(zoomLevel);

            Rect wantedRect = useVideoTexture ? new Rect(r.x, r.y, previewWidth * zoomLevel, image.height * zoomLevel) : r;

            PreviewGUI.BeginScrollView(
                r, m_Position, wantedRect, "PreHorizontalScrollbar", "PreHorizontalScrollbarThumb");

            if (useVideoTexture)
            {
                EditorGUI.DrawTextureTransparent(wantedRect, image, ScaleMode.StretchToFill);
            }
            else
            {
                GUI.DrawTexture(wantedRect, image, ScaleMode.ScaleToFit);
            }

            m_Position = PreviewGUI.EndScrollView();

            if (needRepaint)
            {
                GUIView.current.Repaint();
            }
        }
예제 #10
0
            public bool MoveNext()
            {
                if (this.xPos > -1)
                {
                    if (ListViewShared.HasMouseDown(this.ilvState, this.rect))
                    {
                        this.ilvState.state.selectionChanged = true;
                        this.ilvState.state.row       = this.yPos;
                        this.ilvState.state.column    = this.xPos;
                        this.ilvState.state.scrollPos = ListViewShared.ListViewScrollToRow(this.ilvState, this.yPos);
                        if ((this.ilvState.wantsReordering || this.ilvState.wantsToStartCustomDrag) && (GUIUtility.hotControl == this.ilvState.state.ID))
                        {
                            DragAndDropDelay stateObject = (DragAndDropDelay)GUIUtility.GetStateObject(typeof(DragAndDropDelay), this.ilvState.state.ID);
                            stateObject.mouseDownPosition = Event.current.mousePosition;
                            this.ilvState.dragItem        = this.yPos;
                            ListViewShared.dragControlID  = this.ilvState.state.ID;
                        }
                    }
                    if (((this.ilvState.wantsReordering || this.ilvState.wantsToStartCustomDrag) && ((GUIUtility.hotControl == this.ilvState.state.ID) && (Event.current.type == EventType.MouseDrag))) && GUIClip.visibleRect.Contains(Event.current.mousePosition))
                    {
                        DragAndDropDelay delay2 = (DragAndDropDelay)GUIUtility.GetStateObject(typeof(DragAndDropDelay), this.ilvState.state.ID);
                        if (delay2.CanStartDrag())
                        {
                            DragAndDrop.PrepareStartDrag();
                            DragAndDrop.objectReferences = new UnityEngine.Object[0];
                            DragAndDrop.paths            = null;
                            if (this.ilvState.wantsReordering)
                            {
                                this.ilvState.state.dropHereRect = new Rect(this.ilvState.rect.x, 0f, this.ilvState.rect.width, (float)(this.ilvState.state.rowHeight * 2));
                                DragAndDrop.StartDrag(this.dragTitle);
                            }
                            else if (this.ilvState.wantsToStartCustomDrag)
                            {
                                DragAndDrop.SetGenericData("CustomDragID", this.ilvState.state.ID);
                                DragAndDrop.StartDrag(this.dragTitle);
                            }
                        }
                        Event.current.Use();
                    }
                }
                this.xPos++;
                if (this.xPos > this.xTo)
                {
                    this.xPos = 0;
                    this.yPos++;
                    this.rect.x     = this.firstRect.x;
                    this.rect.width = this.colWidths[0];
                    if (this.yPos > this.yTo)
                    {
                        this.quiting = true;
                    }
                    else
                    {
                        this.rect.y += this.rect.height;
                    }
                }
                else
                {
                    if (this.xPos >= 1)
                    {
                        this.rect.x += this.colWidths[this.xPos - 1];
                    }
                    this.rect.width = this.colWidths[this.xPos];
                }
                this.element.row      = this.yPos;
                this.element.column   = this.xPos;
                this.element.position = this.rect;
                if (this.element.row >= this.ilvState.state.totalRows)
                {
                    this.quiting = true;
                }
                if ((this.isLayouted && (Event.current.type == EventType.Layout)) && ((this.yFrom + 1) == this.yPos))
                {
                    this.quiting = true;
                }
                if (this.isLayouted && (this.yPos != this.yFrom))
                {
                    GUILayout.EndHorizontal();
                }
                if (!this.quiting)
                {
                    if (this.isLayouted)
                    {
                        if (this.yPos != this.yFrom)
                        {
                            this.ilvStateL.group.ResetCursor();
                            this.ilvStateL.group.AddY();
                        }
                        else
                        {
                            this.ilvStateL.group.AddY((float)(this.ilvState.invisibleRows * this.ilvState.state.rowHeight));
                        }
                    }
                }
                else
                {
                    if (this.ilvState.state.drawDropHere && (Event.current.GetTypeForControl(this.ilvState.state.ID) == EventType.Repaint))
                    {
                        GUIStyle insertion = ListViewShared.Constants.insertion;
                        insertion.Draw(insertion.margin.Remove(this.ilvState.state.dropHereRect), false, false, false, false);
                    }
                    if (ListViewShared.ListViewKeyboard(this.ilvState, this.colWidths.Length))
                    {
                        this.ilvState.state.selectionChanged = true;
                    }
                    if (Event.current.GetTypeForControl(this.ilvState.state.ID) == EventType.MouseUp)
                    {
                        GUIUtility.hotControl = 0;
                    }
                    if (!this.ilvState.wantsReordering || (GUIUtility.hotControl != this.ilvState.state.ID))
                    {
                        if (!this.ilvState.wantsExternalFiles)
                        {
                            if (this.ilvState.wantsToAcceptCustomDrag && (ListViewShared.dragControlID != this.ilvState.state.ID))
                            {
                                switch (Event.current.type)
                                {
                                case EventType.DragUpdated:
                                {
                                    object genericData = DragAndDrop.GetGenericData("CustomDragID");
                                    if (GUIClip.visibleRect.Contains(Event.current.mousePosition) && (genericData != null))
                                    {
                                        DragAndDrop.visualMode = !this.ilvState.rect.Contains(Event.current.mousePosition) ? DragAndDropVisualMode.None : DragAndDropVisualMode.Move;
                                        Event.current.Use();
                                    }
                                    break;
                                }

                                case EventType.DragPerform:
                                {
                                    object obj3 = DragAndDrop.GetGenericData("CustomDragID");
                                    if (GUIClip.visibleRect.Contains(Event.current.mousePosition) && (obj3 != null))
                                    {
                                        this.ilvState.state.customDraggedFromID = (int)obj3;
                                        DragAndDrop.AcceptDrag();
                                        Event.current.Use();
                                    }
                                    GUIUtility.hotControl = 0;
                                    break;
                                }

                                case EventType.DragExited:
                                    GUIUtility.hotControl = 0;
                                    break;
                                }
                            }
                        }
                        else
                        {
                            switch (Event.current.type)
                            {
                            case EventType.DragUpdated:
                                if ((GUIClip.visibleRect.Contains(Event.current.mousePosition) && (DragAndDrop.paths != null)) && (DragAndDrop.paths.Length != 0))
                                {
                                    DragAndDrop.visualMode = !this.ilvState.rect.Contains(Event.current.mousePosition) ? DragAndDropVisualMode.None : DragAndDropVisualMode.Copy;
                                    Event.current.Use();
                                    if (DragAndDrop.visualMode != DragAndDropVisualMode.None)
                                    {
                                        this.ilvState.state.dropHereRect = new Rect(this.ilvState.rect.x, (float)((Mathf.RoundToInt(Event.current.mousePosition.y / ((float)this.ilvState.state.rowHeight)) - 1) * this.ilvState.state.rowHeight), this.ilvState.rect.width, (float)this.ilvState.state.rowHeight);
                                        if (this.ilvState.state.dropHereRect.y >= (this.ilvState.state.rowHeight * this.ilvState.state.totalRows))
                                        {
                                            this.ilvState.state.dropHereRect.y = this.ilvState.state.rowHeight * (this.ilvState.state.totalRows - 1);
                                        }
                                        this.ilvState.state.drawDropHere = true;
                                    }
                                }
                                break;

                            case EventType.DragPerform:
                                if (GUIClip.visibleRect.Contains(Event.current.mousePosition))
                                {
                                    this.ilvState.state.fileNames = DragAndDrop.paths;
                                    DragAndDrop.AcceptDrag();
                                    Event.current.Use();
                                    this.ilvState.wantsExternalFiles = false;
                                    this.ilvState.state.drawDropHere = false;
                                    this.ilvState.state.draggedTo    = Mathf.RoundToInt(Event.current.mousePosition.y / ((float)this.ilvState.state.rowHeight));
                                    if (this.ilvState.state.draggedTo > this.ilvState.state.totalRows)
                                    {
                                        this.ilvState.state.draggedTo = this.ilvState.state.totalRows;
                                    }
                                    this.ilvState.state.row = this.ilvState.state.draggedTo;
                                }
                                GUIUtility.hotControl = 0;
                                break;

                            case EventType.DragExited:
                                this.ilvState.wantsExternalFiles = false;
                                this.ilvState.state.drawDropHere = false;
                                GUIUtility.hotControl            = 0;
                                break;
                            }
                        }
                    }
                    else
                    {
                        ListViewState state = this.ilvState.state;
                        switch (Event.current.type)
                        {
                        case EventType.DragUpdated:
                            DragAndDrop.visualMode = !this.ilvState.rect.Contains(Event.current.mousePosition) ? DragAndDropVisualMode.None : DragAndDropVisualMode.Move;
                            Event.current.Use();
                            if (DragAndDrop.visualMode != DragAndDropVisualMode.None)
                            {
                                state.dropHereRect.y = (Mathf.RoundToInt(Event.current.mousePosition.y / ((float)state.rowHeight)) - 1) * state.rowHeight;
                                if (state.dropHereRect.y >= (state.rowHeight * state.totalRows))
                                {
                                    state.dropHereRect.y = state.rowHeight * (state.totalRows - 1);
                                }
                                state.drawDropHere = true;
                            }
                            break;

                        case EventType.DragPerform:
                            if (GUIClip.visibleRect.Contains(Event.current.mousePosition))
                            {
                                this.ilvState.state.draggedFrom = this.ilvState.dragItem;
                                this.ilvState.state.draggedTo   = Mathf.RoundToInt(Event.current.mousePosition.y / ((float)state.rowHeight));
                                if (this.ilvState.state.draggedTo > this.ilvState.state.totalRows)
                                {
                                    this.ilvState.state.draggedTo = this.ilvState.state.totalRows;
                                }
                                if (this.ilvState.state.draggedTo > this.ilvState.state.draggedFrom)
                                {
                                    this.ilvState.state.row = this.ilvState.state.draggedTo - 1;
                                }
                                else
                                {
                                    this.ilvState.state.row = this.ilvState.state.draggedTo;
                                }
                                this.ilvState.state.selectionChanged = true;
                                DragAndDrop.AcceptDrag();
                                Event.current.Use();
                                this.ilvState.wantsReordering    = false;
                                this.ilvState.state.drawDropHere = false;
                            }
                            GUIUtility.hotControl = 0;
                            break;

                        case EventType.DragExited:
                            this.ilvState.wantsReordering    = false;
                            this.ilvState.state.drawDropHere = false;
                            GUIUtility.hotControl            = 0;
                            break;
                        }
                    }
                    if (this.ilvState.beganHorizontal)
                    {
                        EditorGUILayout.EndScrollView();
                        GUILayout.EndHorizontal();
                        this.ilvState.beganHorizontal = false;
                    }
                    if (this.isLayouted)
                    {
                        GUILayoutUtility.EndLayoutGroup();
                        EditorGUILayout.EndScrollView();
                    }
                    this.ilvState.wantsReordering    = false;
                    this.ilvState.wantsExternalFiles = false;
                }
                if (this.isLayouted)
                {
                    if (!this.quiting)
                    {
                        GUILayout.BeginHorizontal(GUIStyle.none, new GUILayoutOption[0]);
                    }
                    else
                    {
                        GUILayout.EndHorizontal();
                    }
                }
                return(!this.quiting);
            }
예제 #11
0
        private void List_drawElementCallback(Rect rect, SerializedProperty element, GUIContent label, int index, bool selected, bool focused)
        {
            var keyValueProp = KeysValues.GetArrayElementAtIndex(index);
            var keyProp      = KeysProp.GetArrayElementAtIndex(index);
            var valueProp    = ValuesProp.GetArrayElementAtIndex(index);

            SerializedProperty keyToUse = keyProp.propertyType == SerializedPropertyType.Generic ? keyProp : keyValueProp;

            if (keyToUse.propertyType == SerializedPropertyType.Generic)
            {
                rect.x     -= 10;
                rect.width += 10;
            }

            //Only draw the color if this entry is not selected
            if (!selected)
            {
                if (Event.current.type == EventType.Repaint)
                {
                    tooTipStyle.Draw(rect, false, false, false, false);
                }
            }

            rect.height = EditorGUIUtility.singleLineHeight;

            //Check if it contains the new attribute
            bool containsAttribute = fieldInfo.GetCustomAttributes(typeof(SD_DrawKeyAsPropertyAttribute), true).Any();

            SD_DrawKeyAsLabelAttribute keyAsLabel = fieldInfo.GetCustomAttribute <SD_DrawKeyAsLabelAttribute>(true);


            Rect keyRect   = new Rect(rect.x + 50, rect.y + 4, rect.width - 52, rect.height);
            Rect valueRect = new Rect(keyRect);

            #region Key Field

            string propName = "";
            if (containsAttribute)
            {
                var field       = fieldInfo.FieldType.BaseType.GetField("_keys", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
                var fieldType   = field.FieldType;
                var elementType = fieldType.GetGenericArguments()[0];
                foreach (var fi in elementType.GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance))
                {
                    if (IsUnitySerialized(fi))
                    {
                        propName = fi.Name;
                        break;
                    }
                }
            }

            //Draw only if its not a generic type or can be draw as property
            if ((containsAttribute && !string.IsNullOrEmpty(propName)) || keyToUse.propertyType != SerializedPropertyType.Generic)
            {
                if (containsAttribute)
                {
                    keyRect.height = EditorGUI.GetPropertyHeight(keyProp, GUIContent.none, true) - (keyProp.isExpanded ? EditorGUIUtility.singleLineHeight : 0);
                }

                keyProp.isExpanded = EditorGUI.Foldout(new Rect(rect.x + 15, keyRect.y, 20, rect.height), keyProp.isExpanded, idContent, true);
            }

            GUI.SetNextControlName("CheckGenericFocus" + index);

            if (keyAsLabel != null)//Deny Edit Key. Show only label with value text
            {
                string labelfield = GetKeyValue(keyToUse).ToString();
                if (valueProp.propertyType == SerializedPropertyType.Enum)
                {
                    string[] enumnames = valueProp.enumNames;

                    labelfield += " ( " + enumnames[valueProp.enumValueIndex] + " )";
                }
                else
                {
                    labelfield += " ( " + GetKeyValue(valueProp).ToString() + " )";
                }
                EditorGUI.LabelField(keyRect, labelfield, EditorStyles.label);
            }
            else
            {
                switch (keyToUse.propertyType)
                {
                case SerializedPropertyType.Quaternion:
                    EditorGUI.BeginChangeCheck();
                    var newV4 = EditorGUI.Vector4Field(keyRect, GUIContent.none, QuaternionToVector4(keyToUse.quaternionValue));

                    if (EditorGUI.EndChangeCheck())
                    {
                        keyToUse.quaternionValue = ConvertToQuaternion(newV4);
                    }
                    break;

                case SerializedPropertyType.Enum:
                    string[] names = keyToUse.enumDisplayNames;
                    if (names.Length <= keyToUse.enumValueIndex || keyToUse.enumValueIndex < 0)
                    {
                        list.Selected = new[] { index };
                        List_onRemoveCallback(list);
                        return;
                    }
                    var selectedVal = names[keyToUse.enumValueIndex];

                    //Draw button with dropdown style
                    if (GUI.Button(keyRect, selectedVal, EditorStyles.layerMaskField))
                    {
                        List <string> usedNames = new List <string>();
                        GenericMenu   menu      = new GenericMenu();

                        //Add all the used values
                        for (int i = 0; i < KeysValues.arraySize; i++)
                        {
                            usedNames.Add(names[KeysValues.GetArrayElementAtIndex(i).enumValueIndex]);
                        }

                        //Add all the menu items
                        for (int i = 0; i < names.Length; i++)
                        {
                            int nameIndex = i;

                            //If the value is being used, show it disabled
                            if (usedNames.Contains(names[nameIndex]) && !names[nameIndex].Equals(selectedVal))
                            {
                                menu.AddDisabledItem(new GUIContent(names[nameIndex]));
                            }
                            else
                            {
                                menu.AddItem(new GUIContent(names[nameIndex]), selectedVal == names[nameIndex], () =>
                                {
                                    keyValueProp.enumValueIndex = nameIndex;
                                    keyProp.enumValueIndex      = nameIndex;
                                    keyToUse.serializedObject.ApplyModifiedProperties();
                                });
                            }
                        }

                        //Show menu under mouse position
                        menu.ShowAsContext();

                        Event.current.Use();
                    }
                    break;

                case SerializedPropertyType.Generic:
                    //Only draw as property if values are correct
                    if (containsAttribute && !string.IsNullOrEmpty(propName))
                    {
                        EditorGUI.PropertyField(keyRect, keyToUse.FindPropertyRelative(propName), GUIContent.none, false);
                    }
                    else
                    {
                        keyRect.height = EditorGUI.GetPropertyHeight(keyToUse, idContent);
                        EditorGUI.PropertyField(new Rect(rect.x + 15, keyRect.y, keyRect.width + 35, keyRect.height), keyToUse, idContent, true);
                    }
                    break;

                default:
                    EditorGUI.PropertyField(keyRect, keyToUse, GUIContent.none, false);
                    break;
                }
            }
            //Not used for generic type
            if (keyToUse.propertyType != SerializedPropertyType.Generic)
            {
                //Old key value
                var oldId = GetKeyValue(keyProp);
                //New key value
                var newId = GetKeyValue(keyValueProp);

                //Notify if the key is empty or null
                if ((keyToUse.propertyType == SerializedPropertyType.String && string.IsNullOrEmpty(newId.ToString())) || newId == null)
                {
                    GUIContent content = EditorGUIUtility.IconContent("console.warnicon.sml");
                    content.tooltip = "ID cannot be left empty";

                    GUI.Button(new Rect(keyRect.x - 15, keyRect.y, 30, 30), content, GUIStyle.none);
                }
                //Check if the key value has been changed
                else if ((oldId == null && newId != null) || !oldId.Equals(newId))
                {
                    //Be sure that the dictionary doesn't contain an element with this key
                    if (ContainsId(newId, index))
                    {
                        //Check if this key is still focused
                        if (GUI.GetNameOfFocusedControl().Equals("CheckGenericFocus" + index))
                        {
                            //Notify the user that this key already exists
                            GUIContent content = EditorGUIUtility.IconContent("console.erroricon.sml");
                            content.tooltip = "Dictionary already has this id, this id cannot be used";

                            GUI.Button(new Rect(keyRect.x - 15, keyRect.y, 30, 30), content, GUIStyle.none);
                        }
                        else
                        {
                            //If it's not, set the correct key back. This is to avoid having multiple errors with ids
                            SetValue(keyValueProp, oldId);
                        }
                    }
                    else
                    {
                        //Set the value
                        SetGenericValue(keyProp, valueProp, newId);
                    }
                }
            }
            #endregion Fey Field

            valueRect.y      = keyRect.yMax + 3 - (containsAttribute ? 2 : 0);
            valueRect.x     -= 20;
            valueRect.width += 20;

            #region Value Field

            //Special case for generic types
            if (valueProp.propertyType == SerializedPropertyType.Generic)
            {
                if (keyToUse.propertyType != SerializedPropertyType.Generic)
                {
                    valueRect.y -= 3;
                }

                EditorGUI.BeginChangeCheck();

                //Value field
                if (keyProp.isExpanded)
                {
                    EditorGUI.BeginProperty(valueRect, GUIContent.none, valueProp);

                    if (valueProp.propertyType == SerializedPropertyType.Quaternion)
                    {
                        EditorGUI.BeginChangeCheck();
                        var newV4 = EditorGUI.Vector4Field(valueRect, GUIContent.none, QuaternionToVector4(valueProp.quaternionValue));

                        if (EditorGUI.EndChangeCheck())
                        {
                            valueProp.quaternionValue = ConvertToQuaternion(newV4);
                        }
                    }
                    else
                    {
                        EditorGUI.PropertyField(valueRect, valueProp, valueContent, true);
                    }
                    EditorGUI.EndProperty();
                }

                if (EditorGUI.EndChangeCheck())
                {
                    //This is used to apply the modified changes
                    ValuesProp.serializedObject.ApplyModifiedProperties();
                }
            }
            else
            {
                //Value field
                if (keyProp.isExpanded)
                {
                    valueRect.x     -= 10;
                    valueRect.width += 10;

                    EditorGUI.BeginProperty(valueRect, GUIContent.none, valueProp);

                    EditorGUI.PrefixLabel(valueRect, valueContent);
                    if (valueProp.propertyType == SerializedPropertyType.Quaternion)
                    {
                        EditorGUI.BeginChangeCheck();
                        var newV4 = EditorGUI.Vector4Field(new Rect(valueRect.x + 45, valueRect.y, valueRect.width - 45, valueRect.height), GUIContent.none, QuaternionToVector4(valueProp.quaternionValue));

                        if (EditorGUI.EndChangeCheck())
                        {
                            valueProp.quaternionValue = ConvertToQuaternion(newV4);
                        }
                    }
                    else
                    {
                        EditorGUI.PropertyField(new Rect(valueRect.x + 45, valueRect.y, valueRect.width - 45, valueRect.height), valueProp, GUIContent.none, true);
                    }
                    EditorGUI.EndProperty();
                }
            }

            #endregion Value Field
        }
예제 #12
0
        private int DoQualityLevelSelection(int currentQualitylevel, IList <QualitySetting> qualitySettings, Dictionary <string, int> platformDefaultQualitySettings)
        {
            GUILayout.BeginHorizontal(new GUILayoutOption[0]);
            GUILayout.FlexibleSpace();
            GUILayout.BeginVertical(new GUILayoutOption[0]);
            int num = currentQualitylevel;

            GUILayout.BeginHorizontal(new GUILayoutOption[0]);
            GUILayoutOption[] options = new GUILayoutOption[] { GUILayout.ExpandWidth(false), GUILayout.Width(80f), GUILayout.Height(20f) };
            Rect position             = GUILayoutUtility.GetRect(GUIContent.none, Styles.kToggle, options);

            position.x     += EditorGUI.indent;
            position.width -= EditorGUI.indent;
            GUI.Label(position, "Levels", EditorStyles.boldLabel);
            foreach (BuildPlayerWindow.BuildPlatform platform in this.m_ValidPlatforms)
            {
                GUILayoutOption[] optionArray2 = new GUILayoutOption[] { GUILayout.MinWidth(15f), GUILayout.MaxWidth(20f), GUILayout.Height(20f) };
                Rect       rect2   = GUILayoutUtility.GetRect(GUIContent.none, Styles.kToggle, optionArray2);
                GUIContent content = EditorGUIUtility.TempContent(platform.smallIcon);
                content.tooltip = platform.title.text;
                GUI.Label(rect2, content);
                content.tooltip = "";
            }
            GUILayoutOption[] optionArray3 = new GUILayoutOption[] { GUILayout.MinWidth(15f), GUILayout.MaxWidth(20f), GUILayout.Height(20f) };
            GUILayoutUtility.GetRect(GUIContent.none, Styles.kToggle, optionArray3);
            GUILayout.EndHorizontal();
            Event current = Event.current;

            for (int i = 0; i < qualitySettings.Count; i++)
            {
                GUILayout.BeginHorizontal(new GUILayoutOption[0]);
                GUIStyle          style        = ((i % 2) != 0) ? Styles.kListOddBg : Styles.kListEvenBg;
                bool              on           = num == i;
                GUILayoutOption[] optionArray4 = new GUILayoutOption[] { GUILayout.ExpandWidth(false), GUILayout.Width(80f) };
                Rect              rect3        = GUILayoutUtility.GetRect(GUIContent.none, Styles.kToggle, optionArray4);
                switch (current.type)
                {
                case EventType.MouseDown:
                    if (rect3.Contains(current.mousePosition))
                    {
                        num = i;
                        GUIUtility.keyboardControl = 0;
                        GUIUtility.hotControl      = this.m_QualityElementHash;
                        GUI.changed = true;
                        Dragging dragging = new Dragging {
                            m_StartPosition = i,
                            m_Position      = i
                        };
                        this.m_Dragging = dragging;
                        current.Use();
                    }
                    break;

                case EventType.MouseUp:
                    if (GUIUtility.hotControl == this.m_QualityElementHash)
                    {
                        GUIUtility.hotControl = 0;
                        current.Use();
                    }
                    break;

                case EventType.MouseDrag:
                    if ((GUIUtility.hotControl == this.m_QualityElementHash) && rect3.Contains(current.mousePosition))
                    {
                        this.m_Dragging.m_Position = i;
                        current.Use();
                    }
                    break;

                case EventType.KeyDown:
                    if ((current.keyCode == KeyCode.UpArrow) || (current.keyCode == KeyCode.DownArrow))
                    {
                        num += (current.keyCode != KeyCode.UpArrow) ? 1 : -1;
                        num  = Mathf.Clamp(num, 0, qualitySettings.Count - 1);
                        GUIUtility.keyboardControl = 0;
                        GUI.changed = true;
                        current.Use();
                    }
                    break;

                case EventType.Repaint:
                {
                    style.Draw(rect3, GUIContent.none, false, false, on, false);
                    QualitySetting setting = qualitySettings[i];
                    GUI.Label(rect3, EditorGUIUtility.TempContent(setting.m_Name));
                    break;
                }
                }
                foreach (BuildPlayerWindow.BuildPlatform platform2 in this.m_ValidPlatforms)
                {
                    bool flag2 = false;
                    if (platformDefaultQualitySettings.ContainsKey(platform2.name) && (platformDefaultQualitySettings[platform2.name] == i))
                    {
                        flag2 = true;
                    }
                    GUILayoutOption[] optionArray5 = new GUILayoutOption[] { GUILayout.MinWidth(15f), GUILayout.MaxWidth(20f) };
                    Rect rect4 = GUILayoutUtility.GetRect(Styles.kPlatformTooltip, Styles.kToggle, optionArray5);
                    if (Event.current.type == EventType.Repaint)
                    {
                        style.Draw(rect4, GUIContent.none, false, false, on, false);
                    }
                    Color backgroundColor = GUI.backgroundColor;
                    if (flag2 && !EditorApplication.isPlayingOrWillChangePlaymode)
                    {
                        GUI.backgroundColor = Color.green;
                    }
                    QualitySetting setting2 = qualitySettings[i];
                    bool           flag3    = !setting2.m_ExcludedPlatforms.Contains(platform2.name);
                    bool           flag4    = GUI.Toggle(rect4, flag3, Styles.kPlatformTooltip, !flag2 ? Styles.kToggle : Styles.kDefaultToggle);
                    if (flag3 != flag4)
                    {
                        if (flag4)
                        {
                            QualitySetting setting3 = qualitySettings[i];
                            setting3.m_ExcludedPlatforms.Remove(platform2.name);
                        }
                        else
                        {
                            QualitySetting setting4 = qualitySettings[i];
                            setting4.m_ExcludedPlatforms.Add(platform2.name);
                        }
                    }
                    GUI.backgroundColor = backgroundColor;
                }
                GUILayoutOption[] optionArray6 = new GUILayoutOption[] { GUILayout.MinWidth(15f), GUILayout.MaxWidth(20f) };
                Rect rect5 = GUILayoutUtility.GetRect(GUIContent.none, Styles.kToggle, optionArray6);
                if (Event.current.type == EventType.Repaint)
                {
                    style.Draw(rect5, GUIContent.none, false, false, on, false);
                }
                if (GUI.Button(rect5, Styles.kIconTrash, GUIStyle.none))
                {
                    this.m_DeleteLevel = i;
                }
                GUILayout.EndHorizontal();
            }
            GUILayout.BeginHorizontal(new GUILayoutOption[0]);
            GUILayoutOption[] optionArray7 = new GUILayoutOption[] { GUILayout.MinWidth(15f), GUILayout.MaxWidth(20f), GUILayout.Height(1f) };
            GUILayoutUtility.GetRect(GUIContent.none, Styles.kToggle, optionArray7);
            DrawHorizontalDivider();
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal(new GUILayoutOption[0]);
            GUILayoutOption[] optionArray8 = new GUILayoutOption[] { GUILayout.ExpandWidth(false), GUILayout.Width(80f), GUILayout.Height(20f) };
            Rect rect6 = GUILayoutUtility.GetRect(GUIContent.none, Styles.kToggle, optionArray8);

            rect6.x     += EditorGUI.indent;
            rect6.width -= EditorGUI.indent;
            GUI.Label(rect6, "Default", EditorStyles.boldLabel);
            foreach (BuildPlayerWindow.BuildPlatform platform3 in this.m_ValidPlatforms)
            {
                int num3;
                GUILayoutOption[] optionArray9 = new GUILayoutOption[] { GUILayout.MinWidth(15f), GUILayout.MaxWidth(20f), GUILayout.Height(20f) };
                Rect rect7 = GUILayoutUtility.GetRect(GUIContent.none, Styles.kToggle, optionArray9);
                if (!platformDefaultQualitySettings.TryGetValue(platform3.name, out num3))
                {
                    platformDefaultQualitySettings.Add(platform3.name, 0);
                }
                if (< > f__am$cache0 == null)
                {
예제 #13
0
        public string DrawFilterField(IInspector inspector, int id, Rect position, string text, bool setIsSelected, out bool textChanged)
        {
            var e         = Event.current;
            var eventType = e.GetTypeForControl(id);

            editor.style = style;

            bool wasSelected = isSelected;

            if (setIsSelected != isSelected)
            {
                                #if DEV_MODE && DEBUG_ENABLED
                Debug.Log(StringUtils.ToColorizedString("SearchBox.isSelected = ", setIsSelected));
                                #endif

                isSelected = setIsSelected;

                if (isSelected)
                {
                    KeyboardControlUtility.KeyboardControl = id;
                    BeginEditing(id, position, style);

                    if (eventType == EventType.MouseDown || eventType == EventType.MouseUp)
                    {
                        editor.MoveCursorToPosition(e.mousePosition);
                        if (GUI.skin.settings.cursorColor.a > 0f)
                        {
                                                        #if DEV_MODE && DEBUG_ENABLED
                            Debug.Log("SearchBox.SelectAllOnMouseUp");
                                                        #endif
                            selectAllOnMouseUp = true;
                        }
                    }
                    else
                    {
                                                #if DEV_MODE && DEBUG_ENABLED
                        Debug.Log("SearchBox.SelectAll");
                                                #endif
                        editor.SelectAll();
                    }
                }
            }

            string textInput = text;

            if (text == null)
            {
                text = "";
            }

                        #if DEV_MODE && DEBUG_ENABLED
            if (e.rawType == EventType.MouseDown || e.rawType == EventType.MouseUp || GUIUtility.hotControl == id)
            {
                Debug.Log(StringUtils.ToColorizedString("SearchBox Event=", e, ", typeForControl=", eventType, ", button=", e.button, ", pos=", position, ", mousePos=", e.mousePosition, ", pos.Contains(mousePos)=", position.Contains(e.mousePosition), ", HasKeyboardFocus=", HasKeyboardFocus(), ", isSelected=", isSelected, ", GUIUtility.hotControl=", GUIUtility.hotControl, ", id=", id));
            }
                        #endif

            if (isSelected && inspector.InspectorDrawer.HasFocus && KeyboardControlUtility.JustClickedControl == 0)
            {
                // UPDATE: When in play mode the keyboard control would have a different ID during every layout / Repaint event!
                if (Event.current.type == EventType.Layout)
                {
                    KeyboardControlUtility.KeyboardControl = id;
                }
                else
                {
                    inspector.RefreshView();
                }
            }

            if (HasKeyboardFocus() && eventType != EventType.Layout)
            {
                if (IsEditingControl())
                {
                    editor.position  = position;
                    editor.controlID = id;
                    editor.DetectFocusChange();
                }
                else if (DrawGUI.EditingTextField || eventType == EventType.ExecuteCommand && string.Equals(e.commandName, "NewKeyboardFocus"))
                {
                    BeginEditing(id, position, style);
                    if (GUI.skin.settings.cursorColor.a > 0f)
                    {
                                                #if DEV_MODE && DEBUG_ENABLED
                        Debug.Log("SearchBox.SelectAll");
                                                #endif
                        editor.SelectAll();
                    }
                    if (e.GetTypeForControl(id) == EventType.ExecuteCommand)
                    {
                        DrawGUI.Use(e);
                    }
                }
            }

            if (editor.controlID == id && !isSelected)
            {
                EndEditing();
            }

            bool   flag1 = false;
            string text1 = editor.text;
            switch (eventType)
            {
            case EventType.MouseDown:
                if (position.Contains(e.mousePosition) && e.button == 0)
                {
                    var dropdownButtonRect = position;
                    dropdownButtonRect.width = 15f;
                    if (onDropdownClicked != null && dropdownButtonRect.Contains(e.mousePosition))
                    {
                        onDropdownClicked(position);

                        if (IsEditingControl())
                        {
                            Clear();
                            EndEditing();
                            flag1 = true;
                        }
                    }
                    else if (wasSelected)
                    {
                        if (e.clickCount == 2 && GUI.skin.settings.doubleClickSelectsWord)
                        {
                            editor.MoveCursorToPosition(Event.current.mousePosition);
                            editor.SelectCurrentWord();
                            editor.MouseDragSelectsWholeWords(true);
                            editor.DblClickSnap(TextEditor.DblClickSnapping.WORDS);
                            dragToPosition = false;
                        }
                        else if (e.clickCount == 3 && GUI.skin.settings.tripleClickSelectsLine)
                        {
                            editor.MoveCursorToPosition(e.mousePosition);
                            editor.SelectCurrentParagraph();
                            editor.MouseDragSelectsWholeWords(true);
                            editor.DblClickSnap(TextEditor.DblClickSnapping.PARAGRAPHS);
                            dragToPosition = false;
                        }
                        else
                        {
                            editor.MoveCursorToPosition(e.mousePosition);
                            selectAllOnMouseUp = false;
                        }
                    }
                    else
                    {
                        if (KeyboardControlUtility.JustClickedControl == 0)
                        {
                            KeyboardControlUtility.KeyboardControl = id;
                        }
                        BeginEditing(id, position, style);
                        editor.MoveCursorToPosition(e.mousePosition);
                        if (GUI.skin.settings.cursorColor.a > 0f)
                        {
                                                                #if DEV_MODE && DEBUG_ENABLED
                            Debug.Log("SearchBox.SelectAllOnMouseUp");
                                                                #endif
                            selectAllOnMouseUp = true;
                        }
                    }
                    KeyboardControlUtility.JustClickedControl = id;
                    DrawGUI.Use(e);
                }
                break;

            case EventType.MouseUp:
                if (GUIUtility.hotControl == id)
                {
                    if (dragged && dragToPosition)
                    {
                                                        #if DEV_MODE && DEBUG_ENABLED
                        Debug.Log("SearchBox.MoveSelectionToAltCursor");
                                                        #endif
                        editor.MoveSelectionToAltCursor();
                        flag1 = true;
                    }
                    else if (postponeMove)
                    {
                        editor.MoveCursorToPosition(e.mousePosition);
                    }
                    else if (selectAllOnMouseUp)
                    {
                        if (GUI.skin.settings.cursorColor.a > 0f)
                        {
                                                                #if DEV_MODE && DEBUG_ENABLED
                            Debug.Log("SearchBox.SelectAll");
                                                                #endif
                            editor.SelectAll();
                        }
                        selectAllOnMouseUp = false;
                    }
                    editor.MouseDragSelectsWholeWords(false);
                    dragToPosition = true;
                    dragged        = false;
                    postponeMove   = false;
                    if (e.button == 0)
                    {
                        KeyboardControlUtility.JustClickedControl = 0;
                        DrawGUI.Use(e);
                    }
                }
                break;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == id)
                {
                    if (!e.shift && editor.hasSelection && dragToPosition)
                    {
                                                        #if DEV_MODE && DEBUG_ENABLED
                        Debug.Log("SearchBox.MoveAltCursorToPosition");
                                                        #endif
                        editor.MoveAltCursorToPosition(e.mousePosition);
                    }
                    else
                    {
                        if (e.shift)
                        {
                                                                #if DEV_MODE && DEBUG_ENABLED
                            Debug.Log("SearchBox.MoveCursorToPosition");
                                                                #endif
                            editor.MoveCursorToPosition(e.mousePosition);
                        }
                        else
                        {
                                                                #if DEV_MODE && DEBUG_ENABLED
                            Debug.Log("SearchBox.SelectToPosition");
                                                                #endif
                            editor.SelectToPosition(e.mousePosition);
                        }
                        dragToPosition     = false;
                        selectAllOnMouseUp = !editor.hasSelection;
                                                        #if DEV_MODE && DEBUG_ENABLED
                        Debug.Log("SearchBox.SelectAllOnMouseUp = " + selectAllOnMouseUp);
                                                        #endif
                    }
                    dragged = true;
                    DrawGUI.Use(e);
                }
                break;

            case EventType.KeyDown:
                if (!isSelected)
                {
                    break;
                }
                bool flag2     = false;
                char character = e.character;
                if (IsEditingControl() && editor.HandleKeyEvent(e))
                {
                    DrawGUI.Use(e);
                    flag1 = true;
                    break;
                }
                if (e.keyCode == KeyCode.Escape)
                {
                    if (IsEditingControl())
                    {
                        Clear();
                        EndEditing();
                        flag1 = true;
                    }
                }
                else if (character == 10 || character == 3)
                {
                    if (!IsEditingControl())
                    {
                                                        #if DEV_MODE && DEBUG_ENABLED
                        Debug.Log("SearchBox.SelectAll");
                                                        #endif
                        BeginEditing(id, position, style);
                        editor.SelectAll();
                    }
                    else
                    {
                        EndEditing();
                    }
                    DrawGUI.Use(e);
                }
                else if (character == 9 || e.keyCode == KeyCode.Tab)
                {
                    flag2 = true;
                }
                else if (character != 25 && character != 27 && IsEditingControl())
                {
                    if (character != 0)
                    {
                        editor.Insert(character);
                        flag1 = true;
                    }
                    else if (Input.compositionString.Length > 0)
                    {
                        editor.ReplaceSelection("");
                        flag1 = true;
                    }
                }
                if (IsEditingControl() && MightBePrintableKey(e) && !flag2)
                {
                    DrawGUI.Use(e);
                }
                break;

            case EventType.Repaint:
                                        #if DEV_MODE && PI_ASSERTATIONS
                Debug.Assert(string.Equals(text, editor.text), "text (" + text + ") != editor.text (" + editor.text + ")");
                                        #endif

                if (GUIUtility.hotControl == 0)
                {
                    // new test
                    if (inspector.MouseoveredPart != InspectorPart.None)
                    {
                        DrawGUI.Active.AddCursorRect(position, MouseCursor.Text);
                    }
                }

                string renderedText = !IsEditingControl() ? text : editor.text;
                if (!IsEditingControl())
                {
                    style.Draw(position, GUIContentPool.Temp(renderedText), id, false);
                    break;
                }
                editor.DrawCursor(renderedText);
                break;

            default:
                switch (eventType - 13)
                {
                case EventType.MouseDown:
                    if (KeyboardControlUtility.KeyboardControl == id)
                    {
                        switch (e.commandName)
                        {
                        case "Cut":
                        case "Copy":
                            if (editor.hasSelection)
                            {
                                DrawGUI.Use(e);
                            }
                            break;

                        case "Paste":
                            if (editor.CanPaste())
                            {
                                DrawGUI.Use(e);
                            }
                            break;

                        case "SelectAll":
                        case "Delete":
                            DrawGUI.Use(e);
                            break;

                        case "UndoRedoPerformed":
                            Text = text;
                            DrawGUI.Use(e);
                            break;
                        }
                    }
                    break;

                case EventType.MouseUp:
                    if (KeyboardControlUtility.KeyboardControl == id)
                    {
                        switch (e.commandName)
                        {
                        case "OnLostFocus":
                                                                                #if DEV_MODE && DEBUG_ENABLED
                            Debug.Log("SearchBox - MouseUp / OnLostFocus: end editing");
                                                                                #endif
                            if (nowEditingAFilterField)
                            {
                                EndEditing();
                            }
                            DrawGUI.Use(e);
                            break;

                        case "Cut":
                            BeginEditing(id, position, style);
                            editor.Cut();
                            flag1 = true;
                            break;

                        case "Copy":
                            editor.Copy();
                            DrawGUI.Use(e);
                            break;

                        case "Paste":
                            BeginEditing(id, position, style);
                            editor.Paste();
                            flag1 = true;
                            break;

                        case "SelectAll":
                                                                                #if DEV_MODE && DEBUG_ENABLED
                            Debug.Log("SearchBox.SelectAll");
                                                                                #endif
                            editor.SelectAll();
                            DrawGUI.Use(e);
                            break;

                        case "Delete":
                            BeginEditing(id, position, style);
                            if (SystemInfo.operatingSystemFamily == OperatingSystemFamily.MacOSX)
                            {
                                editor.Delete();
                            }
                            else
                            {
                                editor.Cut();
                            }
                            flag1 = true;
                            DrawGUI.Use(e);
                            break;
                        }
                    }
                    break;

                case EventType.MouseDrag:
                    if (position.Contains(e.mousePosition))
                    {
                        if (!IsEditingControl())
                        {
                            KeyboardControlUtility.KeyboardControl = id;
                            BeginEditing(id, position, style);
                            editor.MoveCursorToPosition(e.mousePosition);
                        }
                        ShowTextEditorPopupMenu(inspector);
                        DrawGUI.Use(e);
                    }
                    break;
                }
                break;
            }

            textChanged = false;
            if (flag1)
            {
                textChanged = !string.Equals(text1, editor.text);
                if (Event.current.type != EventType.Used)
                {
                    DrawGUI.Use(e);
                }
            }
            if (textChanged)
            {
                SaveCursorPositions();
                GUI.changed = true;
                return(editor.text);
            }
            return(textInput);
        }
        //内部ウィンドウ処理
        void DrawObjectFieldWindow(int id)
        {
            //IDの処理をしないとエラーが起きるので注意(デリゲートの場合はなくていい)
            int      idW   = GUIUtility.GetControlID(FocusType.Passive, _objFieldSize);
            GUIStyle style = EditorStyles.objectFieldThumb;

            style.fontSize  = 15;
            style.fontStyle = FontStyle.Bold;
            if (Event.current.type == EventType.Repaint)
            {
                if (CharacterPrefab == null)
                {
                    style.Draw(_objFieldSize, new GUIContent("  CharacterObject", EditorGUIUtility.IconContent("UnityLogo").image), idW);
                }

                else if (CharacterPrefab != null)
                {
                    style.Draw(_objFieldSize, new GUIContent("  " + CharacterPrefab.name, EditorGUIUtility.IconContent("PreMatCube").image), idW);
                }
            }

            //ドラッグアンドドロップ処理
            if (_objFieldSize.Contains(Event.current.mousePosition))
            {
                switch (Event.current.type)
                {
                //ドラッグ終了 = ドロップ
                case EventType.DragExited:
                    DragAndDrop.activeControlID = idW;
                    //ドロップしているのが参照可能なオブジェクトの場合
                    if (DragAndDrop.objectReferences.Length == 1)
                    {
                        var reference = DragAndDrop.objectReferences[0] as GameObject;
                        if (reference != null)
                        {
                            CharacterPrefab = reference;
                            HandleUtility.Repaint();
                            //ここでEv.Use()するとその後の処理が出来ずヒエラルキーに表示されないオブジェクトが作成されたので注意
                        }
                        HandleUtility.Repaint();
                    }
                    break;

                //ドラッグ中
                case EventType.DragUpdated:
                case EventType.DragPerform:

                    //ドラッグしているのが参照可能なオブジェクトの場合
                    if (DragAndDrop.objectReferences.Length == 1)
                    {
                        //オブジェクトを受け入れる
                        DragAndDrop.AcceptDrag();
                    }
                    //ドラッグしているものを現在のコントロール ID と紐付ける
                    DragAndDrop.activeControlID = idW;
                    //カーソルの見た目を変える
                    DragAndDrop.visualMode = DragAndDropVisualMode.Move;
                    Event.current.Use();    //
                    break;
                }
            }
        }
예제 #15
0
        private bool DrawProfileDataItem(ProfilerProperty property, int rowCount, bool selected, int id)
        {
            bool     flag               = false;
            Event    current            = Event.current;
            Rect     rowRect            = this.GetRowRect(rowCount);
            Rect     position           = rowRect;
            GUIStyle rowBackgroundStyle = this.GetRowBackgroundStyle(rowCount);

            if (current.type == EventType.Repaint)
            {
                rowBackgroundStyle.Draw(position, GUIContent.none, false, false, selected, false);
            }
            float x = (property.depth * 16f) + 4f;

            if (property.HasChildren)
            {
                flag        = this.IsExpanded(property.propertyPath);
                GUI.changed = false;
                x          -= 14f;
                Rect rect3 = new Rect(x, position.y, 14f, 16f);
                flag = GUI.Toggle(rect3, flag, GUIContent.none, styles.foldout);
                if (GUI.changed)
                {
                    this.SetExpanded(property, flag);
                }
                x += 16f;
            }
            string column = property.GetColumn(this.m_ColumnsToShow[0]);

            if (current.type == EventType.Repaint)
            {
                this.DrawTextColumn(ref position, column, 0, (this.m_ColumnsToShow[0] != ProfilerColumn.FunctionName) ? 4f : x, selected);
            }
            if (ProfilerInstrumentationPopup.InstrumentationEnabled && ProfilerInstrumentationPopup.FunctionHasInstrumentationPopup(column))
            {
                float num2 = ((position.x + x) + 5f) + styles.numberLabel.CalcSize(new GUIContent(column)).x;
                num2 = Mathf.Clamp(num2, 0f, (this.m_Splitter.realSizes[0] - 30f) + 2f);
                Rect rect4 = new Rect(num2, position.y, 30f, 16f);
                if (GUI.Button(rect4, styles.instrumentationIcon, styles.miniPullDown))
                {
                    ProfilerInstrumentationPopup.Show(rect4, column);
                }
            }
            if (current.type == EventType.Repaint)
            {
                styles.numberLabel.alignment = TextAnchor.MiddleRight;
                int index = 1;
                for (int i = 1; i < this.m_VisibleColumns.Length; i++)
                {
                    if (this.ColIsVisible(i))
                    {
                        position.x    += this.m_Splitter.realSizes[index - 1];
                        position.width = this.m_Splitter.realSizes[index] - 4f;
                        index++;
                        styles.numberLabel.Draw(position, property.GetColumn(this.m_ColumnsToShow[i]), false, false, false, selected);
                    }
                }
                styles.numberLabel.alignment = TextAnchor.MiddleLeft;
            }
            if ((current.type == EventType.MouseDown) && rowRect.Contains(current.mousePosition))
            {
                GUIUtility.hotControl = 0;
                if (!EditorGUI.actionKey)
                {
                    if (this.m_DetailPane)
                    {
                        if ((current.clickCount == 1) && (property.instanceIDs.Length > 0))
                        {
                            string str2 = DetailViewSelectedPropertyPath(property);
                            if (this.m_DetailViewSelectedProperty != str2)
                            {
                                this.m_DetailViewSelectedProperty = str2;
                                Object gameObject = EditorUtility.InstanceIDToObject(property.instanceIDs[0]);
                                if (gameObject is Component)
                                {
                                    gameObject = ((Component)gameObject).gameObject;
                                }
                                if (gameObject != null)
                                {
                                    EditorGUIUtility.PingObject(gameObject.GetInstanceID());
                                }
                            }
                            else
                            {
                                this.m_DetailViewSelectedProperty = string.Empty;
                            }
                        }
                        else if (current.clickCount == 2)
                        {
                            SelectObjectsInHierarchyView(property);
                            this.m_DetailViewSelectedProperty = DetailViewSelectedPropertyPath(property);
                        }
                    }
                    else
                    {
                        this.RowMouseDown(property.propertyPath);
                    }
                    this.DoScroll();
                }
                else if (!this.m_DetailPane)
                {
                    this.m_Window.ClearSelectedPropertyPath();
                }
                else
                {
                    this.m_DetailViewSelectedProperty = string.Empty;
                }
                GUIUtility.keyboardControl = id;
                current.Use();
            }
            if (((selected && (GUIUtility.keyboardControl == id)) && (current.type == EventType.KeyDown)) && ((current.keyCode == KeyCode.Return) || (current.keyCode == KeyCode.KeypadEnter)))
            {
                SelectObjectsInHierarchyView(property);
            }
            return(flag);
        }
예제 #16
0
        private void ParameterEnable()
        {
            _mainParameters                   = GetProperty("MainParameters");
            _parameterList                    = new ReorderableList(serializedObject, _mainParameters, true, false, true, true);
            _parameterList.headerHeight       = 2;
            _parameterList.elementHeight      = 65;
            _parameterList.drawHeaderCallback = (Rect rect) =>
            {
                GUI.Label(rect, "Parameter");
            };
            _parameterList.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) =>
            {
                SerializedProperty mainParameter = _mainParameters.GetArrayElementAtIndex(index);
                SerializedProperty nameProperty  = mainParameter.FindPropertyRelative("Name");
                SerializedProperty typeProperty  = mainParameter.FindPropertyRelative("Type");

                Rect subrect = rect;

                subrect.Set(rect.x, rect.y + 2, 50, 16);
                GUI.Label(subrect, "Name:");
                if (isActive)
                {
                    subrect.Set(rect.x + 50, rect.y + 2, rect.width - 50, 16);
                    nameProperty.stringValue = EditorGUI.TextField(subrect, nameProperty.stringValue);
                }
                else
                {
                    subrect.Set(rect.x + 50, rect.y + 2, rect.width - 50, 16);
                    GUI.Label(subrect, nameProperty.stringValue);
                }

                subrect.Set(rect.x, rect.y + 22, 50, 16);
                GUI.Label(subrect, "Type:");
                subrect.Set(rect.x + 50, rect.y + 22, rect.width - 50, 16);
                typeProperty.enumValueIndex = (int)(MainParameter.ParameterType)EditorGUI.EnumPopup(subrect, (MainParameter.ParameterType)typeProperty.enumValueIndex);

                subrect.Set(rect.x, rect.y + 42, 50, 16);
                GUI.Label(subrect, "Value:");
                subrect.Set(rect.x + 50, rect.y + 42, rect.width - 50, 16);
                SerializedProperty valueProperty;
                switch ((MainParameter.ParameterType)typeProperty.enumValueIndex)
                {
                case MainParameter.ParameterType.String:
                    valueProperty             = mainParameter.FindPropertyRelative("StringValue");
                    valueProperty.stringValue = EditorGUI.TextField(subrect, valueProperty.stringValue);
                    break;

                case MainParameter.ParameterType.Integer:
                    valueProperty          = mainParameter.FindPropertyRelative("IntegerValue");
                    valueProperty.intValue = EditorGUI.IntField(subrect, valueProperty.intValue);
                    break;

                case MainParameter.ParameterType.Float:
                    valueProperty            = mainParameter.FindPropertyRelative("FloatValue");
                    valueProperty.floatValue = EditorGUI.FloatField(subrect, valueProperty.floatValue);
                    break;

                case MainParameter.ParameterType.Boolean:
                    valueProperty           = mainParameter.FindPropertyRelative("BooleanValue");
                    valueProperty.boolValue = EditorGUI.Toggle(subrect, valueProperty.boolValue);
                    break;

                case MainParameter.ParameterType.Vector2:
                    valueProperty = mainParameter.FindPropertyRelative("Vector2Value");
                    valueProperty.vector2Value = EditorGUI.Vector2Field(subrect, "", valueProperty.vector2Value);
                    break;

                case MainParameter.ParameterType.Vector3:
                    valueProperty = mainParameter.FindPropertyRelative("Vector3Value");
                    valueProperty.vector3Value = EditorGUI.Vector3Field(subrect, "", valueProperty.vector3Value);
                    break;

                case MainParameter.ParameterType.Color:
                    valueProperty            = mainParameter.FindPropertyRelative("ColorValue");
                    valueProperty.colorValue = EditorGUI.ColorField(subrect, valueProperty.colorValue);
                    break;

                case MainParameter.ParameterType.DataSet:
                    valueProperty = mainParameter.FindPropertyRelative("DataSet");
                    valueProperty.objectReferenceValue = EditorGUI.ObjectField(subrect, valueProperty.objectReferenceValue, typeof(DataSetBase), false);
                    break;

                case MainParameter.ParameterType.Prefab:
                    valueProperty = mainParameter.FindPropertyRelative("PrefabValue");
                    valueProperty.objectReferenceValue = EditorGUI.ObjectField(subrect, valueProperty.objectReferenceValue, typeof(GameObject), true);
                    break;

                case MainParameter.ParameterType.Texture:
                    valueProperty = mainParameter.FindPropertyRelative("TextureValue");
                    valueProperty.objectReferenceValue = EditorGUI.ObjectField(subrect, valueProperty.objectReferenceValue, typeof(Texture), false);
                    break;

                case MainParameter.ParameterType.AudioClip:
                    valueProperty = mainParameter.FindPropertyRelative("AudioClipValue");
                    valueProperty.objectReferenceValue = EditorGUI.ObjectField(subrect, valueProperty.objectReferenceValue, typeof(AudioClip), false);
                    break;

                case MainParameter.ParameterType.Material:
                    valueProperty = mainParameter.FindPropertyRelative("MaterialValue");
                    valueProperty.objectReferenceValue = EditorGUI.ObjectField(subrect, valueProperty.objectReferenceValue, typeof(Material), false);
                    break;
                }
            };
            _parameterList.drawElementBackgroundCallback = (Rect rect, int index, bool isActive, bool isFocused) =>
            {
                if (Event.current.type == EventType.Repaint)
                {
                    GUIStyle gUIStyle = (index % 2 != 0) ? "CN EntryBackEven" : "CN EntryBackodd";
                    gUIStyle = (!isActive && !isFocused) ? gUIStyle : "RL Element";
                    gUIStyle.Draw(rect, false, isActive, isActive, isFocused);
                }
            };
        }
예제 #17
0
 public bool MoveNext()
 {
     if (this.xPos > -1)
     {
         if (ListViewShared.HasMouseDown(this.ilvState, this.rect))
         {
             this.ilvState.state.selectionChanged = true;
             this.ilvState.state.row       = this.yPos;
             this.ilvState.state.column    = this.xPos;
             this.ilvState.state.scrollPos = ListViewShared.ListViewScrollToRow(this.ilvState, this.yPos);
             if ((this.ilvState.wantsReordering || this.ilvState.wantsToStartCustomDrag) && GUIUtility.hotControl == this.ilvState.state.ID)
             {
                 DragAndDropDelay dragAndDropDelay = (DragAndDropDelay)GUIUtility.GetStateObject(typeof(DragAndDropDelay), this.ilvState.state.ID);
                 dragAndDropDelay.mouseDownPosition = Event.current.mousePosition;
                 this.ilvState.dragItem             = this.yPos;
                 ListViewShared.dragControlID       = this.ilvState.state.ID;
             }
         }
         if ((this.ilvState.wantsReordering || this.ilvState.wantsToStartCustomDrag) && GUIUtility.hotControl == this.ilvState.state.ID && Event.current.type == EventType.MouseDrag && GUIClipHelper.visibleRect.Contains(Event.current.mousePosition))
         {
             DragAndDropDelay dragAndDropDelay2 = (DragAndDropDelay)GUIUtility.GetStateObject(typeof(DragAndDropDelay), this.ilvState.state.ID);
             if (dragAndDropDelay2.CanStartDrag())
             {
                 DragAndDrop.PrepareStartDrag();
                 DragAndDrop.objectReferences = new UnityEngine.Object[0];
                 DragAndDrop.paths            = null;
                 if (this.ilvState.wantsReordering)
                 {
                     this.ilvState.state.dropHereRect = new Rect(this.ilvState.rect.x, 0f, this.ilvState.rect.width, (float)(this.ilvState.state.rowHeight * 2));
                     DragAndDrop.StartDrag(this.dragTitle);
                 }
                 else
                 {
                     if (this.ilvState.wantsToStartCustomDrag)
                     {
                         DragAndDrop.SetGenericData("CustomDragID", this.ilvState.state.ID);
                         DragAndDrop.StartDrag(this.dragTitle);
                     }
                 }
             }
             Event.current.Use();
         }
     }
     this.xPos++;
     if (this.xPos > this.xTo)
     {
         this.xPos = 0;
         this.yPos++;
         this.rect.x     = this.firstRect.x;
         this.rect.width = (float)this.colWidths[0];
         if (this.yPos > this.yTo)
         {
             this.quiting = true;
         }
         else
         {
             this.rect.y = this.rect.y + this.rect.height;
         }
     }
     else
     {
         if (this.xPos >= 1)
         {
             this.rect.x = this.rect.x + (float)this.colWidths[this.xPos - 1];
         }
         this.rect.width = (float)this.colWidths[this.xPos];
     }
     this.element.row      = this.yPos;
     this.element.column   = this.xPos;
     this.element.position = this.rect;
     if (this.element.row >= this.ilvState.state.totalRows)
     {
         this.quiting = true;
     }
     if (this.isLayouted && Event.current.type == EventType.Layout && this.yFrom + 1 == this.yPos)
     {
         this.quiting = true;
     }
     if (this.isLayouted && this.yPos != this.yFrom)
     {
         GUILayout.EndHorizontal();
     }
     if (this.quiting)
     {
         if (this.ilvState.state.drawDropHere && Event.current.GetTypeForControl(this.ilvState.state.ID) == EventType.Repaint)
         {
             GUIStyle gUIStyle = ListViewShared.Constants.insertion;
             gUIStyle.Draw(gUIStyle.margin.Remove(this.ilvState.state.dropHereRect), false, false, false, false);
         }
         if (ListViewShared.ListViewKeyboard(this.ilvState, this.colWidths.Length))
         {
             this.ilvState.state.selectionChanged = true;
         }
         if (Event.current.GetTypeForControl(this.ilvState.state.ID) == EventType.MouseUp)
         {
             GUIUtility.hotControl = 0;
         }
         if (this.ilvState.wantsReordering && GUIUtility.hotControl == this.ilvState.state.ID)
         {
             ListViewState state = this.ilvState.state;
             EventType     type  = Event.current.type;
             if (type != EventType.DragUpdated)
             {
                 if (type != EventType.DragPerform)
                 {
                     if (type == EventType.DragExited)
                     {
                         this.ilvState.wantsReordering    = false;
                         this.ilvState.state.drawDropHere = false;
                         GUIUtility.hotControl            = 0;
                     }
                 }
                 else
                 {
                     if (GUIClipHelper.visibleRect.Contains(Event.current.mousePosition))
                     {
                         this.ilvState.state.draggedFrom = this.ilvState.dragItem;
                         this.ilvState.state.draggedTo   = Mathf.RoundToInt(Event.current.mousePosition.y / (float)state.rowHeight);
                         if (this.ilvState.state.draggedTo > this.ilvState.state.totalRows)
                         {
                             this.ilvState.state.draggedTo = this.ilvState.state.totalRows;
                         }
                         if (this.ilvState.state.draggedTo > this.ilvState.state.draggedFrom)
                         {
                             this.ilvState.state.row = this.ilvState.state.draggedTo - 1;
                         }
                         else
                         {
                             this.ilvState.state.row = this.ilvState.state.draggedTo;
                         }
                         this.ilvState.state.selectionChanged = true;
                         DragAndDrop.AcceptDrag();
                         Event.current.Use();
                         this.ilvState.wantsReordering    = false;
                         this.ilvState.state.drawDropHere = false;
                     }
                     GUIUtility.hotControl = 0;
                 }
             }
             else
             {
                 DragAndDrop.visualMode = ((!this.ilvState.rect.Contains(Event.current.mousePosition)) ? DragAndDropVisualMode.None : DragAndDropVisualMode.Move);
                 Event.current.Use();
                 if (DragAndDrop.visualMode != DragAndDropVisualMode.None)
                 {
                     state.dropHereRect.y = (float)((Mathf.RoundToInt(Event.current.mousePosition.y / (float)state.rowHeight) - 1) * state.rowHeight);
                     if (state.dropHereRect.y >= (float)(state.rowHeight * state.totalRows))
                     {
                         state.dropHereRect.y = (float)(state.rowHeight * (state.totalRows - 1));
                     }
                     state.drawDropHere = true;
                 }
             }
         }
         else
         {
             if (this.ilvState.wantsExternalFiles)
             {
                 EventType type = Event.current.type;
                 if (type != EventType.DragUpdated)
                 {
                     if (type != EventType.DragPerform)
                     {
                         if (type == EventType.DragExited)
                         {
                             this.ilvState.wantsExternalFiles = false;
                             this.ilvState.state.drawDropHere = false;
                             GUIUtility.hotControl            = 0;
                         }
                     }
                     else
                     {
                         if (GUIClipHelper.visibleRect.Contains(Event.current.mousePosition))
                         {
                             this.ilvState.state.fileNames = DragAndDrop.paths;
                             DragAndDrop.AcceptDrag();
                             Event.current.Use();
                             this.ilvState.wantsExternalFiles = false;
                             this.ilvState.state.drawDropHere = false;
                             this.ilvState.state.draggedTo    = Mathf.RoundToInt(Event.current.mousePosition.y / (float)this.ilvState.state.rowHeight);
                             if (this.ilvState.state.draggedTo > this.ilvState.state.totalRows)
                             {
                                 this.ilvState.state.draggedTo = this.ilvState.state.totalRows;
                             }
                             this.ilvState.state.row = this.ilvState.state.draggedTo;
                         }
                         GUIUtility.hotControl = 0;
                     }
                 }
                 else
                 {
                     if (GUIClipHelper.visibleRect.Contains(Event.current.mousePosition) && DragAndDrop.paths != null && DragAndDrop.paths.Length != 0)
                     {
                         DragAndDrop.visualMode = ((!this.ilvState.rect.Contains(Event.current.mousePosition)) ? DragAndDropVisualMode.None : DragAndDropVisualMode.Copy);
                         Event.current.Use();
                         if (DragAndDrop.visualMode != DragAndDropVisualMode.None)
                         {
                             this.ilvState.state.dropHereRect = new Rect(this.ilvState.rect.x, (float)((Mathf.RoundToInt(Event.current.mousePosition.y / (float)this.ilvState.state.rowHeight) - 1) * this.ilvState.state.rowHeight), this.ilvState.rect.width, (float)this.ilvState.state.rowHeight);
                             if (this.ilvState.state.dropHereRect.y >= (float)(this.ilvState.state.rowHeight * this.ilvState.state.totalRows))
                             {
                                 this.ilvState.state.dropHereRect.y = (float)(this.ilvState.state.rowHeight * (this.ilvState.state.totalRows - 1));
                             }
                             this.ilvState.state.drawDropHere = true;
                         }
                     }
                 }
             }
             else
             {
                 if (this.ilvState.wantsToAcceptCustomDrag && ListViewShared.dragControlID != this.ilvState.state.ID)
                 {
                     EventType type = Event.current.type;
                     if (type != EventType.DragUpdated)
                     {
                         if (type != EventType.DragPerform)
                         {
                             if (type == EventType.DragExited)
                             {
                                 GUIUtility.hotControl = 0;
                             }
                         }
                         else
                         {
                             object genericData = DragAndDrop.GetGenericData("CustomDragID");
                             if (GUIClipHelper.visibleRect.Contains(Event.current.mousePosition) && genericData != null)
                             {
                                 this.ilvState.state.customDraggedFromID = (int)genericData;
                                 DragAndDrop.AcceptDrag();
                                 Event.current.Use();
                             }
                             GUIUtility.hotControl = 0;
                         }
                     }
                     else
                     {
                         object genericData2 = DragAndDrop.GetGenericData("CustomDragID");
                         if (GUIClipHelper.visibleRect.Contains(Event.current.mousePosition) && genericData2 != null)
                         {
                             DragAndDrop.visualMode = ((!this.ilvState.rect.Contains(Event.current.mousePosition)) ? DragAndDropVisualMode.None : DragAndDropVisualMode.Move);
                             Event.current.Use();
                         }
                     }
                 }
             }
         }
         if (this.ilvState.beganHorizontal)
         {
             EditorGUILayout.EndScrollView();
             GUILayout.EndHorizontal();
             this.ilvState.beganHorizontal = false;
         }
         if (this.isLayouted)
         {
         }
         this.ilvState.wantsReordering    = false;
         this.ilvState.wantsExternalFiles = false;
     }
     else
     {
         if (this.isLayouted)
         {
         }
     }
     if (this.isLayouted)
     {
         if (!this.quiting)
         {
             GUILayout.BeginHorizontal(GUIStyle.none, new GUILayoutOption[0]);
         }
         else
         {
             GUILayout.EndHorizontal();
         }
     }
     return(!this.quiting);
 }
예제 #18
0
    static void HierarchyWindowItem(int selectionID, Rect selectionRect)
    {
        GameObject o = (GameObject)EditorUtility.InstanceIDToObject(selectionID);

        if (!o)
        {
            return;
        }

        HierarchyStyle target = o.GetComponent <HierarchyStyle>();

        if (target && Event.current.type == EventType.Repaint)
        {
            GUIStyle style = new GUIStyle();
            style.alignment = TextAnchor.MiddleLeft;

            if (!Selection.Contains(o))
            {
                //Redraw
                if (target.nameColor.a != 0)
                {
                    Color editorBgColor = EditorGUIUtility.isProSkin
                                                                 ? new Color32(56, 56, 56, 255)
                                                                 : new Color32(194, 194, 194, 255);
                    Rect rect = selectionRect;
                    rect.width = style.CalcSize(new GUIContent(target.name)).x;
                    EditorGUI.DrawRect(rect, editorBgColor);
                }

                //Background
                EditorGUI.DrawRect(selectionRect, target.backgroundColor);

                //Name
                if (target.nameColor.a == 0 && target.backgroundColor.a != 0)
                {
                    style.normal.textColor = EditorGUIUtility.isProSkin
                                                                                         ? new Color(1, 1, 1, .5f)
                                                                                         : Color.black;
                }
                else
                {
                    style.normal.textColor = target.nameColor;
                }

                if (!o.activeInHierarchy)
                {
                    if (EditorGUIUtility.isProSkin)
                    {
                        style.normal.textColor *= .7f;
                    }
                    else
                    {
                        style.normal.textColor -= new Color(0, 0, 0, .4f);
                    }
                }
                if (target.nameColor.a != 0 || target.backgroundColor.a != 0)
                {
                    style.Draw(selectionRect, new GUIContent(o.name), selectionID);
                }
            }

            //Comment
            style.normal.textColor = target.commentColor;
            Rect commentRect = selectionRect;
            commentRect.width = style.CalcSize(new GUIContent(target.comment)).x;

            commentRect.x  = EditorGUIUtility.currentViewWidth;
            commentRect.x -= commentRect.width + 20;

            style.Draw(commentRect, new GUIContent(target.comment), selectionID);
            EditorApplication.RepaintHierarchyWindow();
        }
    }
예제 #19
0
    /// <summary>
    /// Draw the specified anchor point.
    /// </summary>

    static public void DrawAnchorHandle(UIRect.AnchorPoint anchor, Transform myTrans, Vector3[] myCorners, int side, int id)
    {
        if (!anchor.target)
        {
            return;
        }

        int i0, i1;

        if (side == 0)
        {
            // Left
            i0 = 0;
            i1 = 1;
        }
        else if (side == 1)
        {
            // Top
            i0 = 1;
            i1 = 2;
        }
        else if (side == 2)
        {
            // Right
            i0 = 3;
            i1 = 2;
        }
        else
        {
            // Bottom
            i0 = 0;
            i1 = 3;
        }

        var myPos = (myCorners[i0] + myCorners[i1]) * 0.5f;

        Vector3[] sides = null;

        if (anchor.rect != null)
        {
            sides = anchor.rect.worldCorners;
        }
        else
        {
#if UNITY_4_3 || UNITY_4_5 || UNITY_4_6 || UNITY_4_7
            Camera cam = anchor.target.camera;
#else
            var cam = anchor.target.GetComponent <Camera>();
#endif
            if (cam != null)
            {
                sides = cam.GetWorldCorners();
            }
        }

        Vector3 theirPos;

        if (sides != null)
        {
            Vector3 v0, v1;

            if (side == 0 || side == 2)
            {
                // Left or right
                v0 = Vector3.Lerp(sides[0], sides[3], anchor.relative);
                v1 = Vector3.Lerp(sides[1], sides[2], anchor.relative);
            }
            else
            {
                // Top or bottom
                v0 = Vector3.Lerp(sides[0], sides[1], anchor.relative);
                v1 = Vector3.Lerp(sides[3], sides[2], anchor.relative);
            }

            theirPos = HandleUtility.ProjectPointLine(myPos, v0, v1);
        }
        else
        {
            theirPos = anchor.target.position;
        }

        NGUIHandles.DrawShadowedLine(myCorners, myPos, theirPos, Color.yellow);

        if (Event.current.GetTypeForControl(id) == EventType.Repaint)
        {
            var screenPoint = HandleUtility.WorldToGUIPoint(theirPos);
#if UNITY_4_3 || UNITY_4_5 || UNITY_4_6 || UNITY_4_7
            Rect rect = new Rect(screenPoint.x - 7f, screenPoint.y - 7f, 14f, 14f);
#else
            var rect = new Rect(screenPoint.x - 5f, screenPoint.y - 9f, 14f, 14f);
#endif
            if (mYellowDot == null)
            {
                mYellowDot = "sv_label_4";
            }

            Vector3 v0 = HandleUtility.WorldToGUIPoint(myPos);
            Vector3 v1 = HandleUtility.WorldToGUIPoint(theirPos);

            Handles.BeginGUI();

            mYellowDot.Draw(rect, GUIContent.none, id);

            var diff         = v1 - v0;
            var isHorizontal = Mathf.Abs(diff.x) > Mathf.Abs(diff.y);
            var mag          = diff.magnitude;

            if ((isHorizontal && mag > 60f) || (!isHorizontal && mag > 30f))
            {
                var pos  = (myPos + theirPos) * 0.5f;
                var text = anchor.absolute.ToString();

                GUI.color = Color.yellow;

                if (side == 0)
                {
                    if (theirPos.x < myPos.x)
                    {
                        NGUIHandles.DrawCenteredLabel(pos, text);
                    }
                }
                else if (side == 1)
                {
                    if (theirPos.y > myPos.y)
                    {
                        NGUIHandles.DrawCenteredLabel(pos, text);
                    }
                }
                else if (side == 2)
                {
                    if (theirPos.x > myPos.x)
                    {
                        NGUIHandles.DrawCenteredLabel(pos, text);
                    }
                }
                else if (side == 3)
                {
                    if (theirPos.y < myPos.y)
                    {
                        NGUIHandles.DrawCenteredLabel(pos, text);
                    }
                }
                GUI.color = Color.white;
            }
            Handles.EndGUI();
        }
    }
 protected override void OnContentGUI(Rect rect, int row, TreeViewItem item, string label, bool selected, bool focused, bool useBoldFont, bool isPinging)
 {
     if (Event.current.type == EventType.Repaint)
     {
         GameObjectTreeViewItem gameObjectTreeViewItem = item as GameObjectTreeViewItem;
         if (gameObjectTreeViewItem != null)
         {
             if (gameObjectTreeViewItem.isSceneHeader)
             {
                 if (gameObjectTreeViewItem.scene.isDirty)
                 {
                     label += "*";
                 }
                 Scene.LoadingState loadingState = gameObjectTreeViewItem.scene.loadingState;
                 if (loadingState != Scene.LoadingState.NotLoaded)
                 {
                     if (loadingState == Scene.LoadingState.Loading)
                     {
                         label += " (is loading)";
                     }
                 }
                 else
                 {
                     label += " (not loaded)";
                 }
                 bool useBoldFont2 = gameObjectTreeViewItem.scene == SceneManager.GetActiveScene();
                 using (new EditorGUI.DisabledScope(!gameObjectTreeViewItem.scene.isLoaded))
                 {
                     base.OnContentGUI(rect, row, item, label, selected, focused, useBoldFont2, isPinging);
                 }
             }
             else
             {
                 if (!isPinging)
                 {
                     float contentIndent = this.GetContentIndent(item);
                     rect.x     += contentIndent;
                     rect.width -= contentIndent;
                 }
                 int colorCode = gameObjectTreeViewItem.colorCode;
                 if (string.IsNullOrEmpty(item.displayName))
                 {
                     if (gameObjectTreeViewItem.objectPPTR != null)
                     {
                         gameObjectTreeViewItem.displayName = gameObjectTreeViewItem.objectPPTR.name;
                     }
                     else
                     {
                         gameObjectTreeViewItem.displayName = "deleted gameobject";
                     }
                     label = gameObjectTreeViewItem.displayName;
                 }
                 GUIStyle gUIStyle = TreeViewGUI.s_Styles.lineStyle;
                 if (!gameObjectTreeViewItem.shouldDisplay)
                 {
                     gUIStyle = GameObjectTreeViewGUI.s_GOStyles.disabledLabel;
                 }
                 else if ((colorCode & 3) == 0)
                 {
                     gUIStyle = ((colorCode >= 4) ? GameObjectTreeViewGUI.s_GOStyles.disabledLabel : TreeViewGUI.s_Styles.lineStyle);
                 }
                 else if ((colorCode & 3) == 1)
                 {
                     gUIStyle = ((colorCode >= 4) ? GameObjectTreeViewGUI.s_GOStyles.disabledPrefabLabel : GameObjectTreeViewGUI.s_GOStyles.prefabLabel);
                 }
                 else if ((colorCode & 3) == 2)
                 {
                     gUIStyle = ((colorCode >= 4) ? GameObjectTreeViewGUI.s_GOStyles.disabledBrokenPrefabLabel : GameObjectTreeViewGUI.s_GOStyles.brokenPrefabLabel);
                 }
                 Texture iconForItem = this.GetIconForItem(item);
                 rect.xMin            += (float)gUIStyle.margin.left;
                 gUIStyle.padding.left = 0;
                 if (iconForItem != null)
                 {
                     gUIStyle.padding.left = (int)(base.iconTotalPadding + this.k_IconWidth + this.k_SpaceBetweenIconAndText);
                     Rect position = rect;
                     position.width = this.k_IconWidth;
                     GUI.DrawTexture(position, iconForItem, ScaleMode.ScaleToFit);
                 }
                 gUIStyle.Draw(rect, label, false, false, selected, focused);
             }
         }
     }
 }
예제 #21
0
 private void DrawTabScroller(Rect scrollRect, GUIStyle tabScroller)
 {
     tabScroller.Draw(scrollRect, scrollRect.Contains(Event.current.mousePosition), false, false, false);
 }
예제 #22
0
        void OnGUI()
        {
            Event e = Event.current;

            LoadIcons();
            LogEntries.wrapped.UpdateEntries();

            if (!m_HasUpdatedGuiStyles)
            {
                m_LineHeight   = Mathf.RoundToInt(Constants.ErrorStyle.lineHeight);
                m_BorderHeight = Constants.ErrorStyle.border.top + Constants.ErrorStyle.border.bottom;
                UpdateListView();
            }

            GUILayout.BeginHorizontal(Constants.Toolbar);

            if (LogEntries.wrapped.importWatching)
            {
                LogEntries.wrapped.importWatching = GUILayout.Toggle(LogEntries.wrapped.importWatching, Constants.ImportWatchingLabel, Constants.MiniButton);
            }

            if (GUILayout.Button(Constants.ClearLabel, Constants.MiniButton))
            {
                LogEntries.Clear();
                GUIUtility.keyboardControl = 0;
            }

            int currCount = LogEntries.wrapped.GetCount();

            if (m_ListView.totalRows != currCount && m_ListView.totalRows > 0)
            {
                // scroll bar was at the bottom?
                if (m_ListView.scrollPos.y >= m_ListView.rowHeight * m_ListView.totalRows - ms_LVHeight)
                {
                    m_ListView.scrollPos.y = currCount * RowHeight - ms_LVHeight;
                }
            }

            if (LogEntries.wrapped.searchFrame)
            {
                LogEntries.wrapped.searchFrame = false;
                int selectedIndex = LogEntries.wrapped.GetSelectedEntryIndex();
                if (selectedIndex != -1)
                {
                    int showIndex = selectedIndex + 1;
                    if (currCount > showIndex)
                    {
                        int showCount = ms_LVHeight / RowHeight;
                        showIndex = showIndex + showCount / 2;
                    }
                    m_ListView.scrollPos.y = showIndex * RowHeight - ms_LVHeight;
                }
            }

            EditorGUILayout.Space();

            bool wasCollapsed = LogEntries.wrapped.collapse;

            LogEntries.wrapped.collapse = GUILayout.Toggle(wasCollapsed, Constants.CollapseLabel, Constants.MiniButton);

            bool collapsedChanged = (wasCollapsed != LogEntries.wrapped.collapse);

            if (collapsedChanged)
            {
                // unselect if collapsed flag changed
                m_ListView.row = -1;

                // scroll to bottom
                m_ListView.scrollPos.y = LogEntries.wrapped.GetCount() * RowHeight;
            }

            SetFlag(ConsoleFlags.ClearOnPlay, GUILayout.Toggle(HasFlag(ConsoleFlags.ClearOnPlay), Constants.ClearOnPlayLabel, Constants.MiniButton));
#if UNITY_2019_1_OR_NEWER
            SetFlag(ConsoleFlags.ClearOnBuild, GUILayout.Toggle(HasFlag(ConsoleFlags.ClearOnBuild), Constants.ClearOnBuildLabel, Constants.MiniButton));
#endif
            SetFlag(ConsoleFlags.ErrorPause, GUILayout.Toggle(HasFlag(ConsoleFlags.ErrorPause), Constants.ErrorPauseLabel, Constants.MiniButton));

#if UNITY_2018_3_OR_NEWER
            ConnectionGUILayout.AttachToPlayerDropdown(m_ConsoleAttachToPlayerState, EditorStyles.toolbarDropDown);
#endif

            EditorGUILayout.Space();

            if (m_DevBuild)
            {
                GUILayout.FlexibleSpace();
                SetFlag(ConsoleFlags.StopForAssert, GUILayout.Toggle(HasFlag(ConsoleFlags.StopForAssert), Constants.StopForAssertLabel, Constants.MiniButton));
                SetFlag(ConsoleFlags.StopForError, GUILayout.Toggle(HasFlag(ConsoleFlags.StopForError), Constants.StopForErrorLabel, Constants.MiniButton));
            }

            GUILayout.FlexibleSpace();

            // Search bar
            GUILayout.Space(4f);
            SearchField(e);

            int errorCount = 0, warningCount = 0, logCount = 0;
            LogEntries.wrapped.GetCountsByType(ref errorCount, ref warningCount, ref logCount);
            EditorGUI.BeginChangeCheck();
            bool setLogFlag     = GUILayout.Toggle(LogEntries.wrapped.HasFlag((int)ConsoleFlags.LogLevelLog), new GUIContent((logCount <= 999 ? logCount.ToString() : "999+"), logCount > 0 ? iconInfoSmall : iconInfoMono), Constants.MiniButton);
            bool setWarningFlag = GUILayout.Toggle(LogEntries.wrapped.HasFlag((int)ConsoleFlags.LogLevelWarning), new GUIContent((warningCount <= 999 ? warningCount.ToString() : "999+"), warningCount > 0 ? iconWarnSmall : iconWarnMono), Constants.MiniButton);
            bool setErrorFlag   = GUILayout.Toggle(LogEntries.wrapped.HasFlag((int)ConsoleFlags.LogLevelError), new GUIContent((errorCount <= 999 ? errorCount.ToString() : "999+"), errorCount > 0 ? iconErrorSmall : iconErrorMono), Constants.MiniButton);
            // Active entry index may no longer be valid
            if (EditorGUI.EndChangeCheck())
            {
            }

            LogEntries.wrapped.SetFlag((int)ConsoleFlags.LogLevelLog, setLogFlag);
            LogEntries.wrapped.SetFlag((int)ConsoleFlags.LogLevelWarning, setWarningFlag);
            LogEntries.wrapped.SetFlag((int)ConsoleFlags.LogLevelError, setErrorFlag);

            if (GUILayout.Button(new GUIContent(errorCount > 0 ? iconFirstErrorSmall : iconFirstErrorMono, Constants.FirstErrorLabel), Constants.MiniButton))
            {
                int firstErrorIndex = LogEntries.wrapped.GetFirstErrorEntryIndex();
                if (firstErrorIndex != -1)
                {
                    SetActiveEntry(firstErrorIndex);
                    LogEntries.wrapped.searchFrame = true;
                }
            }

            GUILayout.EndHorizontal();

            SplitterGUILayout.BeginVerticalSplit(spl);
            int rowHeight = RowHeight;
            EditorGUIUtility.SetIconSize(new Vector2(rowHeight, rowHeight));
            GUIContent tempContent      = new GUIContent();
            int        id               = GUIUtility.GetControlID(0);
            int        rowDoubleClicked = -1;

            /////@TODO: Make Frame selected work with ListViewState
            using (new GettingLogEntriesScope(m_ListView))
            {
                int  selectedRow      = -1;
                bool openSelectedItem = false;
                bool collapsed        = LogEntries.wrapped.collapse;
                foreach (ListViewElement el in ListViewGUI.ListView(m_ListView, Constants.Box))
                {
                    if (e.type == EventType.MouseDown && e.button == 0 && el.position.Contains(e.mousePosition))
                    {
                        m_ListView.row = el.row;
                        selectedRow    = el.row;
                        if (e.clickCount == 2)
                        {
                            openSelectedItem = true;
                        }
                    }
                    else if (e.type == EventType.Repaint)
                    {
                        int    mode           = 0;
                        int    entryCount     = 0;
                        int    searchIndex    = 0;
                        int    searchEndIndex = 0;
                        string text           = LogEntries.wrapped.GetEntryLinesAndFlagAndCount(el.row, ref mode, ref entryCount,
                                                                                                ref searchIndex, ref searchEndIndex);
                        ConsoleFlags flag       = (ConsoleFlags)mode;
                        bool         isSelected = LogEntries.wrapped.IsEntrySelected(el.row);

                        // Draw the background
                        GUIStyle s = el.row % 2 == 0 ? Constants.OddBackground : Constants.EvenBackground;
                        s.Draw(el.position, false, false, isSelected, false);

                        // Draw the icon
#if !UNITY_2017_3_OR_NEWER
                        if (Constants.LogStyleLineCount == 1)
                        {
                            Rect rt = el.position;
                            rt.x     += 6f;
                            rt.y     += 2f;
                            rt.width  = 16f;
                            rt.height = 16f;
                            GUI.DrawTexture(rt, GetIconForErrorMode(flag, false));
                        }
                        else
#endif
                        {
                            GUIStyle iconStyle = GetStyleForErrorMode(flag, true, Constants.LogStyleLineCount == 1);
                            iconStyle.Draw(el.position, false, false, isSelected, false);
                        }

                        // Draw the text
                        tempContent.text = text;
                        GUIStyle errorModeStyle = GetStyleForErrorMode(flag, false, Constants.LogStyleLineCount == 1);

                        if (string.IsNullOrEmpty(LogEntries.wrapped.searchString) || searchIndex == -1 || searchIndex >= text.Length)
                        {
                            errorModeStyle.Draw(el.position, tempContent, id, isSelected);
                        }
                        else
                        {
                            errorModeStyle.DrawWithTextSelection(el.position, tempContent, GUIUtility.keyboardControl, searchIndex, searchEndIndex);
                        }

                        if (collapsed)
                        {
                            Rect badgeRect = el.position;
                            tempContent.text = entryCount.ToString(CultureInfo.InvariantCulture);
                            Vector2 badgeSize = Constants.CountBadge.CalcSize(tempContent);
                            badgeRect.xMin  = badgeRect.xMax - badgeSize.x;
                            badgeRect.yMin += ((badgeRect.yMax - badgeRect.yMin) - badgeSize.y) * 0.5f;
                            badgeRect.x    -= 5f;
                            GUI.Label(badgeRect, tempContent, Constants.CountBadge);
                        }
                    }
                }

                if (selectedRow != -1)
                {
                    if (m_ListView.scrollPos.y >= m_ListView.rowHeight * m_ListView.totalRows - ms_LVHeight)
                    {
                        m_ListView.scrollPos.y = m_ListView.rowHeight * m_ListView.totalRows - ms_LVHeight - 1;
                    }
                }

                // Make sure the selected entry is up to date
                if (m_ListView.totalRows == 0 || m_ListView.row >= m_ListView.totalRows || m_ListView.row < 0)
                {
                }
                else
                {
                    if (m_ListView.selectionChanged)
                    {
                        SetActiveEntry(m_ListView.row);
                    }
                }

                // Open entry using return key
                if ((GUIUtility.keyboardControl == m_ListView.ID) && (e.type == EventType.KeyDown) && (e.keyCode == KeyCode.Return) && (m_ListView.row != 0))
                {
                    selectedRow      = m_ListView.row;
                    openSelectedItem = true;
                }

                if (e.type != EventType.Layout && ListViewGUI.ilvState.rectHeight != 1)
                {
                    ms_LVHeight = ListViewGUI.ilvState.rectHeight;
                }

                if (openSelectedItem)
                {
                    rowDoubleClicked = selectedRow;
                    e.Use();
                }

                if (selectedRow != -1)
                {
                    SetActiveEntry(selectedRow);
                }
            }

            // Prevent dead locking in EditorMonoConsole by delaying callbacks (which can log to the console) until after LogEntries.EndGettingEntries() has been
            // called (this releases the mutex in EditorMonoConsole so logging again is allowed). Fix for case 1081060.
            if (rowDoubleClicked != -1)
            {
                LogEntries.wrapped.StacktraceListView_RowGotDoubleClicked();
            }

            EditorGUIUtility.SetIconSize(Vector2.zero);

            StacktraceListView(e, tempContent);

            SplitterGUILayout.EndVerticalSplit();

            // Copy & Paste selected item
            if ((e.type == EventType.ValidateCommand || e.type == EventType.ExecuteCommand) && e.commandName == "Copy")
            {
                if (e.type == EventType.ExecuteCommand)
                {
                    LogEntries.wrapped.StacktraceListView_CopyAll();
                }
                e.Use();
            }
        }
예제 #23
0
        private void OnGUI()
        {
            Event current = Event.current;

            ConsoleWindow.LoadIcons();
            if (!this.m_HasUpdatedGuiStyles)
            {
                this.m_LineHeight   = Mathf.RoundToInt(ConsoleWindow.Constants.ErrorStyle.lineHeight);
                this.m_BorderHeight = ConsoleWindow.Constants.ErrorStyle.border.top + ConsoleWindow.Constants.ErrorStyle.border.bottom;
                this.UpdateListView();
            }
            GUILayout.BeginHorizontal(ConsoleWindow.Constants.Toolbar, new GUILayoutOption[0]);
            if (GUILayout.Button(ConsoleWindow.Constants.ClearLabel, ConsoleWindow.Constants.MiniButton, new GUILayoutOption[0]))
            {
                LogEntries.Clear();
                GUIUtility.keyboardControl = 0;
            }
            int count = LogEntries.GetCount();

            if (this.m_ListView.totalRows != count && this.m_ListView.totalRows > 0)
            {
                if (this.m_ListView.scrollPos.y >= (float)(this.m_ListView.rowHeight * this.m_ListView.totalRows - this.ms_LVHeight))
                {
                    this.m_ListView.scrollPos.y = (float)(count * this.RowHeight - this.ms_LVHeight);
                }
            }
            EditorGUILayout.Space();
            bool flag = ConsoleWindow.HasFlag(ConsoleWindow.ConsoleFlags.Collapse);

            ConsoleWindow.SetFlag(ConsoleWindow.ConsoleFlags.Collapse, GUILayout.Toggle(flag, ConsoleWindow.Constants.CollapseLabel, ConsoleWindow.Constants.MiniButtonLeft, new GUILayoutOption[0]));
            bool flag2 = flag != ConsoleWindow.HasFlag(ConsoleWindow.ConsoleFlags.Collapse);

            if (flag2)
            {
                this.m_ListView.row         = -1;
                this.m_ListView.scrollPos.y = (float)(LogEntries.GetCount() * this.RowHeight);
            }
            ConsoleWindow.SetFlag(ConsoleWindow.ConsoleFlags.ClearOnPlay, GUILayout.Toggle(ConsoleWindow.HasFlag(ConsoleWindow.ConsoleFlags.ClearOnPlay), ConsoleWindow.Constants.ClearOnPlayLabel, ConsoleWindow.Constants.MiniButtonMiddle, new GUILayoutOption[0]));
            ConsoleWindow.SetFlag(ConsoleWindow.ConsoleFlags.ErrorPause, GUILayout.Toggle(ConsoleWindow.HasFlag(ConsoleWindow.ConsoleFlags.ErrorPause), ConsoleWindow.Constants.ErrorPauseLabel, ConsoleWindow.Constants.MiniButtonRight, new GUILayoutOption[0]));
            this.m_AttachProfilerUI.OnGUILayout(this);
            EditorGUILayout.Space();
            if (this.m_DevBuild)
            {
                GUILayout.FlexibleSpace();
                ConsoleWindow.SetFlag(ConsoleWindow.ConsoleFlags.StopForAssert, GUILayout.Toggle(ConsoleWindow.HasFlag(ConsoleWindow.ConsoleFlags.StopForAssert), ConsoleWindow.Constants.StopForAssertLabel, ConsoleWindow.Constants.MiniButtonLeft, new GUILayoutOption[0]));
                ConsoleWindow.SetFlag(ConsoleWindow.ConsoleFlags.StopForError, GUILayout.Toggle(ConsoleWindow.HasFlag(ConsoleWindow.ConsoleFlags.StopForError), ConsoleWindow.Constants.StopForErrorLabel, ConsoleWindow.Constants.MiniButtonRight, new GUILayoutOption[0]));
            }
            GUILayout.FlexibleSpace();
            int num  = 0;
            int num2 = 0;
            int num3 = 0;

            LogEntries.GetCountsByType(ref num, ref num2, ref num3);
            EditorGUI.BeginChangeCheck();
            bool val  = GUILayout.Toggle(ConsoleWindow.HasFlag(ConsoleWindow.ConsoleFlags.LogLevelLog), new GUIContent((num3 > 999) ? "999+" : num3.ToString(), (num3 <= 0) ? ConsoleWindow.iconInfoMono : ConsoleWindow.iconInfoSmall), ConsoleWindow.Constants.MiniButtonRight, new GUILayoutOption[0]);
            bool val2 = GUILayout.Toggle(ConsoleWindow.HasFlag(ConsoleWindow.ConsoleFlags.LogLevelWarning), new GUIContent((num2 > 999) ? "999+" : num2.ToString(), (num2 <= 0) ? ConsoleWindow.iconWarnMono : ConsoleWindow.iconWarnSmall), ConsoleWindow.Constants.MiniButtonMiddle, new GUILayoutOption[0]);
            bool val3 = GUILayout.Toggle(ConsoleWindow.HasFlag(ConsoleWindow.ConsoleFlags.LogLevelError), new GUIContent((num > 999) ? "999+" : num.ToString(), (num <= 0) ? ConsoleWindow.iconErrorMono : ConsoleWindow.iconErrorSmall), ConsoleWindow.Constants.MiniButtonLeft, new GUILayoutOption[0]);

            if (EditorGUI.EndChangeCheck())
            {
                this.SetActiveEntry(null);
            }
            ConsoleWindow.SetFlag(ConsoleWindow.ConsoleFlags.LogLevelLog, val);
            ConsoleWindow.SetFlag(ConsoleWindow.ConsoleFlags.LogLevelWarning, val2);
            ConsoleWindow.SetFlag(ConsoleWindow.ConsoleFlags.LogLevelError, val3);
            GUILayout.EndHorizontal();
            this.m_ListView.totalRows = LogEntries.StartGettingEntries();
            SplitterGUILayout.BeginVerticalSplit(this.spl, new GUILayoutOption[0]);
            int rowHeight = this.RowHeight;

            EditorGUIUtility.SetIconSize(new Vector2((float)rowHeight, (float)rowHeight));
            GUIContent gUIContent = new GUIContent();
            int        controlID  = GUIUtility.GetControlID(FocusType.Native);

            try
            {
                bool        flag3      = false;
                bool        flag4      = ConsoleWindow.HasFlag(ConsoleWindow.ConsoleFlags.Collapse);
                IEnumerator enumerator = ListViewGUI.ListView(this.m_ListView, ConsoleWindow.Constants.Box, new GUILayoutOption[0]).GetEnumerator();
                try
                {
                    while (enumerator.MoveNext())
                    {
                        ListViewElement listViewElement = (ListViewElement)enumerator.Current;
                        if (current.type == EventType.MouseDown && current.button == 0 && listViewElement.position.Contains(current.mousePosition))
                        {
                            if (current.clickCount == 2)
                            {
                                LogEntries.RowGotDoubleClicked(this.m_ListView.row);
                            }
                            flag3 = true;
                        }
                        if (current.type == EventType.Repaint)
                        {
                            int    mode = 0;
                            string text = null;
                            LogEntries.GetLinesAndModeFromEntryInternal(listViewElement.row, ConsoleWindow.Constants.LogStyleLineCount, ref mode, ref text);
                            GUIStyle gUIStyle = (listViewElement.row % 2 != 0) ? ConsoleWindow.Constants.EvenBackground : ConsoleWindow.Constants.OddBackground;
                            gUIStyle.Draw(listViewElement.position, false, false, this.m_ListView.row == listViewElement.row, false);
                            GUIStyle styleForErrorMode = ConsoleWindow.GetStyleForErrorMode(mode, true, ConsoleWindow.Constants.LogStyleLineCount == 1);
                            styleForErrorMode.Draw(listViewElement.position, false, false, this.m_ListView.row == listViewElement.row, false);
                            gUIContent.text = text;
                            GUIStyle styleForErrorMode2 = ConsoleWindow.GetStyleForErrorMode(mode, false, ConsoleWindow.Constants.LogStyleLineCount == 1);
                            styleForErrorMode2.Draw(listViewElement.position, gUIContent, controlID, this.m_ListView.row == listViewElement.row);
                            if (flag4)
                            {
                                Rect position = listViewElement.position;
                                gUIContent.text = LogEntries.GetEntryCount(listViewElement.row).ToString(CultureInfo.InvariantCulture);
                                Vector2 vector = ConsoleWindow.Constants.CountBadge.CalcSize(gUIContent);
                                position.xMin  = position.xMax - vector.x;
                                position.yMin += (position.yMax - position.yMin - vector.y) * 0.5f;
                                position.x    -= 5f;
                                GUI.Label(position, gUIContent, ConsoleWindow.Constants.CountBadge);
                            }
                        }
                    }
                }
                finally
                {
                    IDisposable disposable;
                    if ((disposable = (enumerator as IDisposable)) != null)
                    {
                        disposable.Dispose();
                    }
                }
                if (flag3)
                {
                    if (this.m_ListView.scrollPos.y >= (float)(this.m_ListView.rowHeight * this.m_ListView.totalRows - this.ms_LVHeight))
                    {
                        this.m_ListView.scrollPos.y = (float)(this.m_ListView.rowHeight * this.m_ListView.totalRows - this.ms_LVHeight - 1);
                    }
                }
                if (this.m_ListView.totalRows == 0 || this.m_ListView.row >= this.m_ListView.totalRows || this.m_ListView.row < 0)
                {
                    if (this.m_ActiveText.Length != 0)
                    {
                        this.SetActiveEntry(null);
                    }
                }
                else
                {
                    LogEntry logEntry = new LogEntry();
                    LogEntries.GetEntryInternal(this.m_ListView.row, logEntry);
                    this.SetActiveEntry(logEntry);
                    LogEntries.GetEntryInternal(this.m_ListView.row, logEntry);
                    if (this.m_ListView.selectionChanged || !this.m_ActiveText.Equals(logEntry.condition))
                    {
                        this.SetActiveEntry(logEntry);
                    }
                }
                if (GUIUtility.keyboardControl == this.m_ListView.ID && current.type == EventType.KeyDown && current.keyCode == KeyCode.Return && this.m_ListView.row != 0)
                {
                    LogEntries.RowGotDoubleClicked(this.m_ListView.row);
                    Event.current.Use();
                }
                if (current.type != EventType.Layout && ListViewGUI.ilvState.rectHeight != 1)
                {
                    this.ms_LVHeight = ListViewGUI.ilvState.rectHeight;
                }
            }
            finally
            {
                LogEntries.EndGettingEntries();
                EditorGUIUtility.SetIconSize(Vector2.zero);
            }
            this.m_TextScroll = GUILayout.BeginScrollView(this.m_TextScroll, ConsoleWindow.Constants.Box);
            float minHeight = ConsoleWindow.Constants.MessageStyle.CalcHeight(GUIContent.Temp(this.m_ActiveText), base.position.width);

            EditorGUILayout.SelectableLabel(this.m_ActiveText, ConsoleWindow.Constants.MessageStyle, new GUILayoutOption[]
            {
                GUILayout.ExpandWidth(true),
                GUILayout.ExpandHeight(true),
                GUILayout.MinHeight(minHeight)
            });
            GUILayout.EndScrollView();
            SplitterGUILayout.EndVerticalSplit();
            if ((current.type == EventType.ValidateCommand || current.type == EventType.ExecuteCommand) && current.commandName == "Copy" && this.m_ActiveText != string.Empty)
            {
                if (current.type == EventType.ExecuteCommand)
                {
                    EditorGUIUtility.systemCopyBuffer = this.m_ActiveText;
                }
                current.Use();
            }
        }
예제 #24
0
        public void OnGUI()
        {
            var modifiers = Event.current.modifiers & ~(EventModifiers.FunctionKey | EventModifiers.CapsLock | EventModifiers.Numeric);

            var isOSX = Application.platform == RuntimePlatform.OSXEditor;

            if (isOSX)
            {
                if ((modifiers & EventModifiers.Alt) == 0)
                {
                    EditorApplication.delayCall -= CloseAndSwitch;
                    EditorApplication.delayCall += CloseAndSwitch;
                    return;
                }
            }
            else
            {
                if ((modifiers & EventModifiers.Control) == 0)
                {
                    EditorApplication.delayCall -= CloseAndSwitch;
                    EditorApplication.delayCall += CloseAndSwitch;
                    return;
                }
            }

            if (itemStyle == null)
            {
                itemStyle = new GUIStyle("PR Label");
                itemStyle.padding.left  = 2;
                itemStyle.padding.right = 4;
                itemStyle.border        = new RectOffset();
                itemStyle.margin        = new RectOffset();
                itemStyle.fixedWidth    = 0;
                // itemStyle.stretchWidth = false;
                // itemStyle.fixedHeight = itemHeight;

                captionStyle                  = new GUIStyle(EditorStyles.largeLabel);
                captionStyle.fontStyle        = FontStyle.Bold;
                captionStyle.fontSize         = 18;
                captionStyle.padding          = new RectOffset(6, 10, 10, 10);
                captionStyle.normal.textColor = EditorGUIUtility.isProSkin ?
                                                new Color(0.7f, 0.7f, 0.7f, 1f) : new Color(0.4f, 0.4f, 0.4f, 1f);
            }

            if (items == null)
            {
                EditorApplication.delayCall += Close;
                return;
            }

            if (Event.current.type == EventType.KeyDown)
            {
                var newSelected = selected;
                var isTabKey    = Event.current.keyCode == KeyCode.Tab;
                if (Event.current.keyCode == KeyCode.DownArrow || isTabKey && !Event.current.shift)
                {
                    if (++newSelected == items.Length)
                    {
                        newSelected = 0;
                    }
                }
                else if (Event.current.keyCode == KeyCode.UpArrow || isTabKey && Event.current.shift)
                {
                    if (--newSelected < 0)
                    {
                        newSelected = items.Length - 1;
                    }
                }
                else if (items.Length > 10 &&
                         (Event.current.keyCode == KeyCode.RightArrow || Event.current.keyCode == KeyCode.LeftArrow))
                {
                    newSelected += Event.current.keyCode == KeyCode.RightArrow ? 10 : -10;
                    if (newSelected < 0)
                    {
                        newSelected += ((items.Length + 9) / 10) * 10;
                    }
                    if (newSelected >= items.Length)
                    {
                        if (newSelected / 10 == items.Length / 10)
                        {
                            newSelected = items.Length - 1;
                        }
                        else
                        {
                            newSelected = newSelected % 10;
                        }
                    }
                }
                if (newSelected != selected)
                {
                    selected = newSelected;
                    Repaint();
                    Event.current.Use();
                }
            }
            else if (Event.current.type == EventType.Layout)
            {
                EditorGUIUtility.SetIconSize(new Vector2(16f, 16f));

                if (itemsWidth == 0f)
                {
                    EditorGUIUtility.SetIconSize(new Vector2(32f, 32f));
                    for (int i = 0; i < items.Length; ++i)
                    {
                        var size = itemStyle.CalcSize(items[i]);
                        itemsWidth   = Mathf.Max(itemsWidth, size.x);
                        size         = captionStyle.CalcSize(items[i]);
                        captionWidth = Mathf.Max(captionWidth, size.x);
                    }
                    captionHeight = 54f;

                    var width  = Mathf.Max(captionWidth, 8f + itemsWidth * ((items.Length + 9) / 10));
                    var height = 4f + itemHeight * (Mathf.Min(items.Length, 10)) + captionHeight;
                    SetSize(width, height);
                    Repaint();
                }

                EditorGUIUtility.SetIconSize(Vector2.zero);
            }

            EditorGUIUtility.SetIconSize(new Vector2(32f, 32f));
            if (captionStyle != null)
            {
                GUI.Label(new Rect(0f, 0f, captionWidth, captionHeight), items[selected], captionStyle);
            }

            if (Event.current.type == EventType.Repaint)
            {
                EditorGUIUtility.SetIconSize(new Vector2(16f, 16f));
                for (int i = 0; i < items.Length; ++i)
                {
                    var pos = new Rect(4f + itemsWidth * (i / 10), captionHeight + itemHeight * (i % 10), itemsWidth, itemHeight);
                    itemStyle.Draw(pos, items[i], false, false, i == selected, true);
                }
            }

            EditorGUIUtility.SetIconSize(Vector2.zero);
        }
        public override void OnPreviewGUI(Rect r, GUIStyle background)
        {
            if (Event.current.type == EventType.Repaint)
            {
                background.Draw(r, false, false, false, false);
            }

            // show texture
            Texture t = target as Texture;

            if (t == null) // texture might be gone by now, in case this code is used for floating texture preview
            {
                return;
            }

            // Render target must be created before we can display it (case 491797)
            RenderTexture rt = t as RenderTexture;

            if (rt != null)
            {
                if (!SystemInfo.IsFormatSupported(rt.graphicsFormat, FormatUsage.Render))
                {
                    return; // can't do this RT format
                }
                rt.Create();
            }

            if (IsCubemap())
            {
                m_CubemapPreview.OnPreviewGUI(t, r, background);
                return;
            }

            // target can report zero sizes in some cases just after a parameter change;
            // guard against that.
            int texWidth  = Mathf.Max(t.width, 1);
            int texHeight = Mathf.Max(t.height, 1);

            float mipLevel   = GetMipLevelForRendering();
            float zoomLevel  = Mathf.Min(Mathf.Min(r.width / texWidth, r.height / texHeight), 1);
            Rect  wantedRect = new Rect(r.x, r.y, texWidth * zoomLevel, texHeight * zoomLevel);

            PreviewGUI.BeginScrollView(r, m_Pos, wantedRect, "PreHorizontalScrollbar", "PreHorizontalScrollbarThumb");
            FilterMode oldFilter = t.filterMode;

            TextureUtil.SetFilterModeNoDirty(t, FilterMode.Point);
            Texture2D      t2d            = t as Texture2D;
            ColorWriteMask colorWriteMask = ColorWriteMask.All;

            switch (m_PreviewMode)
            {
            case PreviewMode.R:
                colorWriteMask = ColorWriteMask.Red | ColorWriteMask.Alpha;
                break;

            case PreviewMode.G:
                colorWriteMask = ColorWriteMask.Green | ColorWriteMask.Alpha;
                break;

            case PreviewMode.B:
                colorWriteMask = ColorWriteMask.Blue | ColorWriteMask.Alpha;
                break;
            }

            if (m_PreviewMode == PreviewMode.A)
            {
                EditorGUI.DrawTextureAlpha(wantedRect, t, ScaleMode.StretchToFill, 0, mipLevel);
            }
            else
            {
                if (t2d != null && t2d.alphaIsTransparency)
                {
                    EditorGUI.DrawTextureTransparent(wantedRect, t, ScaleMode.StretchToFill, 0, mipLevel, colorWriteMask);
                }
                else
                {
                    EditorGUI.DrawPreviewTexture(wantedRect, t, null, ScaleMode.StretchToFill, 0, mipLevel, colorWriteMask);
                }
            }

            // TODO: Less hacky way to prevent sprite rects to not appear in smaller previews like icons.
            if ((wantedRect.width > 32 && wantedRect.height > 32) && Event.current.type == EventType.Repaint)
            {
                string           path            = AssetDatabase.GetAssetPath(t);
                TextureImporter  textureImporter = AssetImporter.GetAtPath(path) as TextureImporter;
                SpriteMetaData[] spritesheet     = textureImporter != null ? textureImporter.spritesheet : null;

                if (spritesheet != null && textureImporter.spriteImportMode == SpriteImportMode.Multiple)
                {
                    Rect screenRect = new Rect();
                    Rect sourceRect = new Rect();
                    GUI.CalculateScaledTextureRects(wantedRect, ScaleMode.StretchToFill, (float)t.width / (float)t.height, ref screenRect, ref sourceRect);

                    int origWidth  = t.width;
                    int origHeight = t.height;
                    textureImporter.GetWidthAndHeight(ref origWidth, ref origHeight);
                    float definitionScale = (float)t.width / (float)origWidth;

                    HandleUtility.ApplyWireMaterial();
                    GL.PushMatrix();
                    GL.MultMatrix(Handles.matrix);
                    GL.Begin(GL.LINES);
                    GL.Color(new Color(1f, 1f, 1f, 0.5f));
                    foreach (SpriteMetaData sprite in spritesheet)
                    {
                        Rect spriteRect       = sprite.rect;
                        Rect spriteScreenRect = new Rect();
                        spriteScreenRect.xMin = screenRect.xMin + screenRect.width * (spriteRect.xMin / t.width * definitionScale);
                        spriteScreenRect.xMax = screenRect.xMin + screenRect.width * (spriteRect.xMax / t.width * definitionScale);
                        spriteScreenRect.yMin = screenRect.yMin + screenRect.height * (1f - spriteRect.yMin / t.height * definitionScale);
                        spriteScreenRect.yMax = screenRect.yMin + screenRect.height * (1f - spriteRect.yMax / t.height * definitionScale);
                        DrawRect(spriteScreenRect);
                    }
                    GL.End();
                    GL.PopMatrix();
                }
            }

            TextureUtil.SetFilterModeNoDirty(t, oldFilter);

            m_Pos = PreviewGUI.EndScrollView();
            if (mipLevel != 0)
            {
                EditorGUI.DropShadowLabel(new Rect(r.x, r.y, r.width, 20), "Mip " + mipLevel);
            }
        }
예제 #26
0
        internal static string DoTextField(RecycledTextEditor editor, int id, Rect position, string text, GUIStyle style, string allowedletters, out bool changed, bool reset, bool multiline, bool passwordField)
        {
            Event  current = Event.current;
            string result  = text;

            if (text == null)
            {
                text = string.Empty;
            }
            if (showMixedValue)
            {
                text = string.Empty;
            }
            if (HasKeyboardFocus(id) && Event.current.type != EventType.Layout)
            {
                if (editor.IsEditingControl(id))
                {
                    editor.position        = position;
                    editor.style           = style;
                    editor.controlID       = id;
                    editor.multiline       = multiline;
                    editor.isPasswordField = passwordField;
                    editor.DetectFocusChange();
                }
                else if (editingTextField)
                {
                    editor.BeginEditing(id, text, position, style, multiline, passwordField);
                    if (GUI.skin.settings.cursorColor.a > 0f)
                    {
                        editor.SelectAll();
                    }
                }
            }
            if (editor.controlID == id && GUIUtility.keyboardControl != id)
            {
                editor.controlID = 0;
            }
            bool      flag           = false;
            string    text2          = editor.text;
            EventType typeForControl = current.GetTypeForControl(id);

            switch (typeForControl)
            {
            case EventType.MouseDown:
                if (position.Contains(current.mousePosition) && current.button == 0)
                {
                    if (editor.IsEditingControl(id))
                    {
                        if (Event.current.clickCount == 2 && GUI.skin.settings.doubleClickSelectsWord)
                        {
                            editor.MoveCursorToPosition(Event.current.mousePosition);
                            editor.SelectCurrentWord();
                            editor.MouseDragSelectsWholeWords(true);
                            editor.DblClickSnap(TextEditor.DblClickSnapping.WORDS);
                            s_DragToPosition = false;
                        }
                        else if (Event.current.clickCount == 3 && GUI.skin.settings.tripleClickSelectsLine)
                        {
                            editor.MoveCursorToPosition(Event.current.mousePosition);
                            editor.SelectCurrentParagraph();
                            editor.MouseDragSelectsWholeWords(true);
                            editor.DblClickSnap(TextEditor.DblClickSnapping.PARAGRAPHS);
                            s_DragToPosition = false;
                        }
                        else
                        {
                            editor.MoveCursorToPosition(Event.current.mousePosition);
                            s_SelectAllOnMouseUp = false;
                        }
                    }
                    else
                    {
                        GUIUtility.keyboardControl = id;
                        editor.BeginEditing(id, text, position, style, multiline, passwordField);
                        editor.MoveCursorToPosition(Event.current.mousePosition);
                        if (GUI.skin.settings.cursorColor.a > 0f)
                        {
                            s_SelectAllOnMouseUp = true;
                        }
                    }
                    GUIUtility.hotControl = id;
                    current.Use();
                }
                break;

            case EventType.MouseUp:
                if (GUIUtility.hotControl == id)
                {
                    if (s_Dragged && s_DragToPosition)
                    {
                        editor.MoveSelectionToAltCursor();
                        flag = true;
                    }
                    else if (s_PostPoneMove)
                    {
                        editor.MoveCursorToPosition(Event.current.mousePosition);
                    }
                    else if (s_SelectAllOnMouseUp)
                    {
                        if (GUI.skin.settings.cursorColor.a > 0f)
                        {
                            editor.SelectAll();
                        }
                        s_SelectAllOnMouseUp = false;
                    }
                    editor.MouseDragSelectsWholeWords(false);
                    s_DragToPosition = true;
                    s_Dragged        = false;
                    s_PostPoneMove   = false;
                    if (current.button == 0)
                    {
                        GUIUtility.hotControl = 0;
                        current.Use();
                    }
                }
                break;

            case EventType.MouseMove:
            case EventType.KeyUp:
            case EventType.ScrollWheel:
                switch (typeForControl)
                {
                case EventType.ValidateCommand:
                    if (GUIUtility.keyboardControl == id)
                    {
                        string commandName = current.commandName;
                        switch (commandName)
                        {
                        case "Cut":
                        case "Copy":
                            if (editor.hasSelection)
                            {
                                current.Use();
                            }
                            break;

                        case "Paste":
                            if (editor.CanPaste())
                            {
                                current.Use();
                            }
                            break;

                        case "SelectAll":
                            current.Use();
                            break;

                        case "UndoRedoPerformed":
                            editor.text = text;
                            current.Use();
                            break;

                        case "Delete":
                            current.Use();
                            break;
                        }
                    }
                    break;

                case EventType.ExecuteCommand:
                    if (GUIUtility.keyboardControl == id)
                    {
                        string commandName = current.commandName;
                        switch (commandName)
                        {
                        case "OnLostFocus":
                            if (activeEditor != null)
                            {
                                activeEditor.EndEditing();
                            }
                            current.Use();
                            break;

                        case "Cut":
                            editor.BeginEditing(id, text, position, style, multiline, passwordField);
                            editor.Cut();
                            flag = true;
                            break;

                        case "Copy":
                            editor.Copy();
                            current.Use();
                            break;

                        case "Paste":
                            editor.BeginEditing(id, text, position, style, multiline, passwordField);
                            editor.Paste();
                            flag = true;
                            break;

                        case "SelectAll":
                            editor.SelectAll();
                            current.Use();
                            break;

                        case "Delete":
                            editor.BeginEditing(id, text, position, style, multiline, passwordField);
                            if (Application.platform == RuntimePlatform.OSXPlayer || Application.platform == RuntimePlatform.OSXEditor || (Application.platform == RuntimePlatform.WebGLPlayer && SystemInfo.operatingSystem.StartsWith("Mac")))
                            {
                                editor.Delete();
                            }
                            else
                            {
                                editor.Cut();
                            }
                            flag = true;
                            current.Use();
                            break;
                        }
                    }
                    break;

                case EventType.DragExited:
                    break;

                case EventType.ContextClick:
                    if (position.Contains(current.mousePosition))
                    {
                        if (!editor.IsEditingControl(id))
                        {
                            GUIUtility.keyboardControl = id;
                            editor.BeginEditing(id, text, position, style, multiline, passwordField);
                            editor.MoveCursorToPosition(Event.current.mousePosition);
                        }
                        //ShowTextEditorPopupMenu();
                        Event.current.Use();
                    }
                    break;

                default:
                    break;
                }
                break;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == id)
                {
                    if (!current.shift && editor.hasSelection && s_DragToPosition)
                    {
                        editor.MoveAltCursorToPosition(Event.current.mousePosition);
                    }
                    else
                    {
                        if (current.shift)
                        {
                            editor.MoveCursorToPosition(Event.current.mousePosition);
                        }
                        else
                        {
                            editor.SelectToPosition(Event.current.mousePosition);
                        }
                        s_DragToPosition     = false;
                        s_SelectAllOnMouseUp = !editor.hasSelection;
                    }
                    s_Dragged = true;
                    current.Use();
                }
                break;

            case EventType.KeyDown:
                if (GUIUtility.keyboardControl == id)
                {
                    char character = current.character;
                    if (editor.IsEditingControl(id) && editor.HandleKeyEvent(current))
                    {
                        current.Use();
                        flag = true;
                    }
                    else if (current.keyCode == KeyCode.Escape)
                    {
                        if (editor.IsEditingControl(id))
                        {
                            /*if (style == EditorStyles.toolbarSearchField || style == EditorStyles.searchField)
                             * {
                             *      EditorGUI.s_OriginalText = string.Empty;
                             * }*/
                            editor.text = s_OriginalText;
                            editor.EndEditing();
                            flag = true;
                        }
                    }
                    else if (character == '\n' || character == '\u0003')
                    {
                        if (!editor.IsEditingControl(id))
                        {
                            editor.BeginEditing(id, text, position, style, multiline, passwordField);
                            editor.SelectAll();
                        }
                        else
                        {
                            if (multiline && !current.alt && !current.shift && !current.control)
                            {
                                editor.Insert(character);
                                flag = true;
                                break;
                            }
                            editor.EndEditing();
                        }
                        current.Use();
                    }
                    else if (character == '\t' || current.keyCode == KeyCode.Tab)
                    {
                        if (multiline && editor.IsEditingControl(id))
                        {
                            bool flag2 = allowedletters == null || allowedletters.IndexOf(character) != -1;
                            bool flag3 = !current.alt && !current.shift && !current.control && character == '\t';
                            if (flag3 && flag2)
                            {
                                editor.Insert(character);
                                flag = true;
                            }
                        }
                    }
                    else if (character != '\u0019' && character != '\u001b')
                    {
                        if (editor.IsEditingControl(id))
                        {
                            bool flag4 = (allowedletters == null || allowedletters.IndexOf(character) != -1) && character != '\0';
                            if (flag4)
                            {
                                editor.Insert(character);
                                flag = true;
                            }
                            else
                            {
                                if (Input.compositionString != string.Empty)
                                {
                                    editor.ReplaceSelection(string.Empty);
                                    flag = true;
                                }
                                current.Use();
                            }
                        }
                    }
                }
                break;

            case EventType.Repaint:
            {
                string text3;
                if (editor.IsEditingControl(id))
                {
                    text3 = ((!passwordField) ? editor.text : string.Empty.PadRight(editor.text.Length, '*'));
                }
                else if (showMixedValue)
                {
                    text3 = s_MixedValueContent.text;
                }
                else
                {
                    text3 = ((!passwordField) ? text : string.Empty.PadRight(text.Length, '*'));
                }
                if (!string.IsNullOrEmpty(s_UnitString) && !passwordField)
                {
                    text3 = text3 + " " + s_UnitString;
                }
                if (GUIUtility.hotControl == 0)
                {
                    //EditorGUIUtility.AddCursorRect(position, MouseCursor.Text);
                }
                if (!editor.IsEditingControl(id))
                {
                    BeginHandleMixedValueContentColor();
                    style.Draw(position, RuntimeEditorGUIUtility.TempContent(text3), id, false);
                    EndHandleMixedValueContentColor();
                }
                else
                {
                    editor.DrawCursor(text3);
                }
                break;
            }
            }
            if (GUIUtility.keyboardControl == id)
            {
                //GUIUtility.textFieldInput = true;
            }
            editor.UpdateScrollOffsetIfNeeded(current);
            changed = false;
            if (flag)
            {
                changed = (text2 != editor.text);
                current.Use();
            }
            if (changed)
            {
                GUI.changed = true;
                return(editor.text);
            }
            RecycledTextEditor.s_AllowContextCutOrPaste = true;
            return(result);
        }
예제 #27
0
        internal void OnGUI()
        {
            Event e = Event.current;

            LoadIcons();

            if (!m_HasUpdatedGuiStyles)
            {
                m_LineHeight   = Mathf.RoundToInt(Constants.ErrorStyle.lineHeight);
                m_BorderHeight = Constants.ErrorStyle.border.top + Constants.ErrorStyle.border.bottom;
                UpdateListView();
            }

            GUILayout.BeginHorizontal(Constants.Toolbar);

            // Clear button and clearing options
            bool clearClicked = false;

            if (EditorGUILayout.DropDownToggle(ref clearClicked, Constants.Clear, EditorStyles.toolbarDropDownToggle))
            {
                var clearOnPlay  = HasFlag(ConsoleFlags.ClearOnPlay);
                var clearOnBuild = HasFlag(ConsoleFlags.ClearOnBuild);

                GenericMenu menu = new GenericMenu();
                menu.AddItem(Constants.ClearOnPlay, clearOnPlay, () => { SetFlag(ConsoleFlags.ClearOnPlay, !clearOnPlay); });
                menu.AddItem(Constants.ClearOnBuild, clearOnBuild, () => { SetFlag(ConsoleFlags.ClearOnBuild, !clearOnBuild); });
                var rect = GUILayoutUtility.GetLastRect();
                rect.y += EditorGUIUtility.singleLineHeight;
                menu.DropDown(rect);
            }
            if (clearClicked)
            {
                LogEntries.Clear();
                GUIUtility.keyboardControl = 0;
            }

            int currCount = LogEntries.GetCount();

            if (m_ListView.totalRows != currCount && m_ListView.totalRows > 0)
            {
                // scroll bar was at the bottom?
                if (m_ListView.scrollPos.y >= m_ListView.rowHeight * m_ListView.totalRows - ms_LVHeight)
                {
                    m_ListView.scrollPos.y = currCount * RowHeight - ms_LVHeight;
                }
            }

            bool wasCollapsed = HasFlag(ConsoleFlags.Collapse);

            SetFlag(ConsoleFlags.Collapse, GUILayout.Toggle(wasCollapsed, Constants.Collapse, Constants.MiniButton));

            bool collapsedChanged = (wasCollapsed != HasFlag(ConsoleFlags.Collapse));

            if (collapsedChanged)
            {
                // unselect if collapsed flag changed
                m_ListView.row = -1;

                // scroll to bottom
                m_ListView.scrollPos.y = LogEntries.GetCount() * RowHeight;
            }

            if (HasSpaceForExtraButtons())
            {
                SetFlag(ConsoleFlags.ErrorPause, GUILayout.Toggle(HasFlag(ConsoleFlags.ErrorPause), Constants.ErrorPause, Constants.MiniButton));
                PlayerConnectionGUILayout.ConnectionTargetSelectionDropdown(m_ConsoleAttachToPlayerState, EditorStyles.toolbarDropDown);
            }

            GUILayout.FlexibleSpace();

            // Search bar
            if (HasSpaceForExtraButtons())
            {
                SearchField(e);
            }

            // Flags
            int errorCount = 0, warningCount = 0, logCount = 0;

            LogEntries.GetCountsByType(ref errorCount, ref warningCount, ref logCount);
            EditorGUI.BeginChangeCheck();
            bool setLogFlag     = GUILayout.Toggle(HasFlag(ConsoleFlags.LogLevelLog), new GUIContent((logCount <= 999 ? logCount.ToString() : "999+"), logCount > 0 ? iconInfoSmall : iconInfoMono), Constants.MiniButton);
            bool setWarningFlag = GUILayout.Toggle(HasFlag(ConsoleFlags.LogLevelWarning), new GUIContent((warningCount <= 999 ? warningCount.ToString() : "999+"), warningCount > 0 ? iconWarnSmall : iconWarnMono), Constants.MiniButton);
            bool setErrorFlag   = GUILayout.Toggle(HasFlag(ConsoleFlags.LogLevelError), new GUIContent((errorCount <= 999 ? errorCount.ToString() : "999+"), errorCount > 0 ? iconErrorSmall : iconErrorMono), Constants.MiniButtonRight);

            // Active entry index may no longer be valid
            if (EditorGUI.EndChangeCheck())
            {
                SetActiveEntry(null);
            }

            SetFlag(ConsoleFlags.LogLevelLog, setLogFlag);
            SetFlag(ConsoleFlags.LogLevelWarning, setWarningFlag);
            SetFlag(ConsoleFlags.LogLevelError, setErrorFlag);

            GUILayout.EndHorizontal();

            // Console entries
            SplitterGUILayout.BeginVerticalSplit(spl);

            GUIContent tempContent      = new GUIContent();
            int        id               = GUIUtility.GetControlID(0);
            int        rowDoubleClicked = -1;

            /////@TODO: Make Frame selected work with ListViewState
            using (new GettingLogEntriesScope(m_ListView))
            {
                int  selectedRow      = -1;
                bool openSelectedItem = false;
                bool collapsed        = HasFlag(ConsoleFlags.Collapse);
                foreach (ListViewElement el in ListViewGUI.ListView(m_ListView, ListViewOptions.wantsRowMultiSelection, Constants.Box))
                {
                    if (e.type == EventType.MouseDown && e.button == 0 && el.position.Contains(e.mousePosition))
                    {
                        selectedRow = m_ListView.row;
                        if (e.clickCount == 2)
                        {
                            openSelectedItem = true;
                        }
                    }
                    else if (e.type == EventType.Repaint)
                    {
                        int    mode = 0;
                        string text = null;
                        LogEntries.GetLinesAndModeFromEntryInternal(el.row, Constants.LogStyleLineCount, ref mode, ref text);
                        bool entryIsSelected = m_ListView.selectedItems != null && el.row < m_ListView.selectedItems.Length && m_ListView.selectedItems[el.row];

                        // offset value in x for icon and text
                        var offset = Constants.LogStyleLineCount == 1 ? 4 : 8;

                        // Draw the background
                        GUIStyle s = el.row % 2 == 0 ? Constants.OddBackground : Constants.EvenBackground;
                        s.Draw(el.position, false, false, entryIsSelected, false);

                        // Draw the icon
                        GUIStyle iconStyle = GetStyleForErrorMode(mode, true, Constants.LogStyleLineCount == 1);
                        Rect     iconRect  = el.position;
                        iconRect.x += offset;
                        iconRect.y += 2;

                        iconStyle.Draw(iconRect, false, false, entryIsSelected, false);

                        // Draw the text
                        tempContent.text = text;
                        GUIStyle errorModeStyle =
                            GetStyleForErrorMode(mode, false, Constants.LogStyleLineCount == 1);
                        var textRect = el.position;
                        textRect.x += offset;

                        if (string.IsNullOrEmpty(m_SearchText))
                        {
                            errorModeStyle.Draw(textRect, tempContent, id, m_ListView.row == el.row);
                        }
                        else
                        {
                            //the whole text contains the searchtext, we have to know where it is
                            int startIndex = text.IndexOf(m_SearchText, StringComparison.OrdinalIgnoreCase);
                            if (startIndex == -1) // the searchtext is not in the visible text, we don't show the selection
                            {
                                errorModeStyle.Draw(textRect, tempContent, id, m_ListView.row == el.row);
                            }
                            else // the searchtext is visible, we show the selection
                            {
                                int endIndex = startIndex + m_SearchText.Length;

                                const bool isActive          = false;
                                const bool hasKeyboardFocus  = true; // This ensure we draw the selection text over the label.
                                const bool drawAsComposition = false;
                                Color      selectionColor    = GUI.skin.settings.selectionColor;

                                errorModeStyle.DrawWithTextSelection(textRect, tempContent, isActive, hasKeyboardFocus, startIndex, endIndex, drawAsComposition, selectionColor);
                            }
                        }

                        if (collapsed)
                        {
                            Rect badgeRect = el.position;
                            tempContent.text = LogEntries.GetEntryCount(el.row)
                                               .ToString(CultureInfo.InvariantCulture);
                            Vector2 badgeSize = Constants.CountBadge.CalcSize(tempContent);

                            if (Constants.CountBadge.fixedHeight > 0)
                            {
                                badgeSize.y = Constants.CountBadge.fixedHeight;
                            }
                            badgeRect.xMin  = badgeRect.xMax - badgeSize.x;
                            badgeRect.yMin += ((badgeRect.yMax - badgeRect.yMin) - badgeSize.y) * 0.5f;
                            badgeRect.x    -= 5f;
                            GUI.Label(badgeRect, tempContent, Constants.CountBadge);
                        }
                    }
                }

                if (selectedRow != -1)
                {
                    if (m_ListView.scrollPos.y >= m_ListView.rowHeight * m_ListView.totalRows - ms_LVHeight)
                    {
                        m_ListView.scrollPos.y = m_ListView.rowHeight * m_ListView.totalRows - ms_LVHeight - 1;
                    }
                }

                // Make sure the selected entry is up to date
                if (m_ListView.totalRows == 0 || m_ListView.row >= m_ListView.totalRows || m_ListView.row < 0)
                {
                    if (m_ActiveText.Length != 0)
                    {
                        SetActiveEntry(null);
                    }
                }
                else
                {
                    LogEntry entry = new LogEntry();
                    LogEntries.GetEntryInternal(m_ListView.row, entry);
                    SetActiveEntry(entry);

                    // see if selected entry changed. if so - clear additional info
                    LogEntries.GetEntryInternal(m_ListView.row, entry);
                    if (m_ListView.selectionChanged || !m_ActiveText.Equals(entry.message))
                    {
                        SetActiveEntry(entry);
                    }

                    // If copy, get the messages from selected rows
                    if (e.type == EventType.ExecuteCommand && e.commandName == EventCommandNames.Copy && m_ListView.selectedItems != null)
                    {
                        m_CopyString.Clear();
                        for (int rowIndex = 0; rowIndex < m_ListView.selectedItems.Length; rowIndex++)
                        {
                            if (m_ListView.selectedItems[rowIndex])
                            {
                                LogEntries.GetEntryInternal(rowIndex, entry);
                                m_CopyString.AppendLine(entry.message);
                            }
                        }
                    }
                }
                // Open entry using return key
                if ((GUIUtility.keyboardControl == m_ListView.ID) && (e.type == EventType.KeyDown) &&
                    (e.keyCode == KeyCode.Return) && (m_ListView.row != 0))
                {
                    selectedRow      = m_ListView.row;
                    openSelectedItem = true;
                }

                if (e.type != EventType.Layout && ListViewGUI.ilvState.rectHeight != 1)
                {
                    ms_LVHeight = ListViewGUI.ilvState.rectHeight;
                }

                if (openSelectedItem)
                {
                    rowDoubleClicked = selectedRow;
                    e.Use();
                }
            }

            // Prevent dead locking in EditorMonoConsole by delaying callbacks (which can log to the console) until after LogEntries.EndGettingEntries() has been
            // called (this releases the mutex in EditorMonoConsole so logging again is allowed). Fix for case 1081060.
            if (rowDoubleClicked != -1)
            {
                LogEntries.RowGotDoubleClicked(rowDoubleClicked);
            }


            // Display active text (We want word wrapped text with a vertical scrollbar)
            m_TextScroll = GUILayout.BeginScrollView(m_TextScroll, Constants.Box);

            string stackWithHyperlinks = StacktraceWithHyperlinks(m_ActiveText);
            float  height = Constants.MessageStyle.CalcHeight(GUIContent.Temp(stackWithHyperlinks), position.width);

            EditorGUILayout.SelectableLabel(stackWithHyperlinks, Constants.MessageStyle, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true), GUILayout.MinHeight(height + 10));

            GUILayout.EndScrollView();

            SplitterGUILayout.EndVerticalSplit();

            // Copy & Paste selected item
            if ((e.type == EventType.ValidateCommand || e.type == EventType.ExecuteCommand) && e.commandName == EventCommandNames.Copy && m_CopyString != null)
            {
                if (e.type == EventType.ExecuteCommand)
                {
                    EditorGUIUtility.systemCopyBuffer = m_CopyString.ToString();
                }
                e.Use();
            }
        }
예제 #28
0
            // draw the default footer
            public void DrawFooter(Rect rect, ReorderableList list)
            {
                float rightEdge = rect.xMax;
                float leftEdge  = rightEdge - 8f;

                if (list.displayAdd)
                {
                    leftEdge -= 25;
                }
                if (list.displayRemove)
                {
                    leftEdge -= 25;
                }
                rect = new Rect(leftEdge, rect.y, rightEdge - leftEdge, rect.height);
                Rect addRect    = new Rect(leftEdge + 4, rect.y - 3, 25, 13);
                Rect removeRect = new Rect(rightEdge - 29, rect.y - 3, 25, 13);

                if (Event.current.type == EventType.Repaint)
                {
                    footerBackground.Draw(rect, false, false, false, false);
                }
                if (list.displayAdd)
                {
                    using (new EditorGUI.DisabledScope(
                               list.onCanAddCallback != null && !list.onCanAddCallback(list)))
                    {
                        if (GUI.Button(addRect, list.onAddDropdownCallback != null ? iconToolbarPlusMore : iconToolbarPlus, preButton))
                        {
                            if (list.onAddDropdownCallback != null)
                            {
                                list.onAddDropdownCallback(addRect, list);
                            }
                            else if (list.onAddCallback != null)
                            {
                                list.onAddCallback(list);
                            }
                            else
                            {
                                DoAddButton(list);
                            }

                            if (list.onChangedCallback != null)
                            {
                                list.onChangedCallback(list);
                            }
                        }
                    }
                }
                if (list.displayRemove)
                {
                    using (new EditorGUI.DisabledScope(
                               list.index < 0 || list.index >= list.count ||
                               (list.onCanRemoveCallback != null && !list.onCanRemoveCallback(list))))
                    {
                        if (GUI.Button(removeRect, iconToolbarMinus, preButton))
                        {
                            if (list.onRemoveCallback == null)
                            {
                                DoRemoveButton(list);
                            }
                            else
                            {
                                list.onRemoveCallback(list);
                            }

                            if (list.onChangedCallback != null)
                            {
                                list.onChangedCallback(list);
                            }
                        }
                    }
                }
            }
예제 #29
0
        protected override void OldOnGUI()
        {
            ConsoleWindow.LoadIcons();
            if (background == null)
            {
                background = "AppToolbar";
            }

            if (EditorApplication.isPlayingOrWillChangePlaymode)
            {
                GUI.color = HostView.kPlayModeDarken;
            }

            if (Event.current.type == EventType.Repaint)
            {
                background.Draw(new Rect(0, 0, position.width, position.height), false, false, false, false);
            }

            var compiling        = EditorApplication.isCompiling;
            var assembliesLocked = !EditorApplication.CanReloadAssemblies();

            GUILayout.Space(2);
            GUILayout.BeginHorizontal();
            GUILayout.Space(2);

            string statusText = LogEntries.GetStatusText();

            if (statusText != null)
            {
                // Render
                int      mask       = LogEntries.GetStatusMask();
                GUIStyle errorStyle = ConsoleWindow.GetStatusStyleForErrorMode(mask);

                GUILayout.Label(ConsoleWindow.GetIconForErrorMode(mask, false), errorStyle);

                GUILayout.Space(2);
                GUILayout.BeginVertical();
                GUILayout.Space(2);

                if (compiling) //leave space for indicator
                {
                    GUILayout.Label(statusText, errorStyle, GUILayout.MaxWidth(GUIView.current.position.width - 52));
                }
                else
                {
                    GUILayout.Label(statusText, errorStyle);
                }
                GUILayout.FlexibleSpace();

                GUILayout.EndVertical();

                // Handle status bar click
                if (Event.current.type == EventType.MouseDown)
                {
                    Event.current.Use();
                    LogEntries.ClickStatusBar(Event.current.clickCount);
                    GUIUtility.ExitGUI();
                }
            }

            GUILayout.EndHorizontal();

            if (Event.current.type == EventType.Repaint)
            {
                const float statusWheelWidth = 24;
                const float progressBarStatusWheelSpacing = 3;

                float progressBarHorizontalPosition = position.width - statusWheelWidth;
                if (AsyncProgressBar.isShowing)
                {
                    const int progressBarWidth = 185;
                    progressBarHorizontalPosition -= progressBarWidth + progressBarStatusWheelSpacing;
                    EditorGUI.ProgressBar(new Rect(progressBarHorizontalPosition, 0, progressBarWidth, 19), AsyncProgressBar.progress, AsyncProgressBar.progressInfo);
                }

                if (compiling)
                {
                    if (assembliesLocked)
                    {
                        GUI.Label(new Rect(position.width - statusWheelWidth, 0, s_AssemblyLock.image.width, s_AssemblyLock.image.height), s_AssemblyLock, GUIStyle.none);
                    }
                    else
                    {
                        int frame = (int)Mathf.Repeat(Time.realtimeSinceStartup * 10, 11.99f);
                        GUI.Label(new Rect(position.width - statusWheelWidth, 0, s_StatusWheel[frame].image.width, s_StatusWheel[frame].image.height), s_StatusWheel[frame], GUIStyle.none);
                    }
                }

                if (Unsupported.IsBleedingEdgeBuild())
                {
                    var backup = GUI.color;
                    GUI.color = Color.yellow;
                    GUI.Label(new Rect(progressBarHorizontalPosition - 310, 0, 310, 19), "THIS IS AN UNTESTED BLEEDINGEDGE UNITY BUILD");
                    GUI.color = backup;
                }
                else if (Unsupported.IsDeveloperMode())
                {
                    GUI.Label(new Rect(progressBarHorizontalPosition - 200, 0, 200, 19), m_LastMiniMemoryOverview, EditorStyles.progressBarText);
                    EditorGUIUtility.CleanCache(m_LastMiniMemoryOverview);
                }
            }

            DoWindowDecorationEnd();

            EditorGUI.ShowRepaints();
        }
예제 #30
0
        /**
         *  Static function to handle the GUI and User input related to the cascade slider.
         *
         *  @param  normalizedCascadePartition      The array of partition sizes in the range 0.0f - 1.0f; expects ONE entry if cascades = 2, and THREE if cascades=4
         *                                          The last entry will be automatically determined by summing up the array, and doing 1.0f - sum
         */
        static void HandleCascadeSliderGUI(ref float[] normalizedCascadePartitions, ref float[] endPartitionBordersPercent, bool[] enabledCascadePartitionHandles, bool[] enabledEndPartitionBorderHandles, bool drawEndPartitionHandles, bool useMetric, float baseMetric)
        {
            EditorGUILayout.BeginVertical();
            GUILayout.Space(10);
            EditorGUILayout.BeginHorizontal();

            // get the inspector width since we need it while drawing the partition rects.
            // Only way currently is to reserve the block in the layout using GetRect(), and then immediately drawing the empty box
            // to match the call to GetRect.
            // From this point on, we move to non-layout based code.
            var sliderRect = GUILayoutUtility.GetRect(GUIContent.none
                                                      , s_CascadeSliderBG
                                                      , GUILayout.Height(kSliderbarTopMargin + kSliderbarHeight + kSliderbarBottomMargin)
                                                      , GUILayout.ExpandWidth(true));

            GUI.Box(sliderRect, GUIContent.none);

            float currentX            = sliderRect.x + 3;
            float cascadeBoxStartY    = sliderRect.y + kSliderbarTopMargin;
            int   borderAdjustment    = (3 - normalizedCascadePartitions.Length) * 2;
            float cascadeSliderWidth  = sliderRect.width - (normalizedCascadePartitions.Length * kPartitionHandleWidth) - borderAdjustment;
            Color origTextColor       = GUI.color;
            Color origBackgroundColor = GUI.backgroundColor;
            int   colorIndex          = -1;

            // setup the array locally with the last partition
            float[] adjustedCascadePartitions = new float[normalizedCascadePartitions.Length + 1];
            Array.Copy(normalizedCascadePartitions, adjustedCascadePartitions, normalizedCascadePartitions.Length);
            adjustedCascadePartitions[adjustedCascadePartitions.Length - 1] = 1.0f - normalizedCascadePartitions.Sum();


            // check for user input on any of the partition handles
            // this mechanism gets the current event in the queue... make sure that the mouse is over our control before consuming the event
            int   sliderControlId         = GUIUtility.GetControlID(s_CascadeSliderId, FocusType.Passive);
            Event currentEvent            = Event.current;
            int   hotPartitionHandleIndex = -1; // the index of any partition handle that we are hovering over or dragging

            EventType eventType = currentEvent.GetTypeForControl(sliderControlId);

            // draw each cascade partition
            for (int i = 0; i < adjustedCascadePartitions.Length; ++i)
            {
                float currentPartition = adjustedCascadePartitions[i];

                colorIndex          = (colorIndex + 1) % kCascadeColors.Length;
                GUI.backgroundColor = kCascadeColors[colorIndex];
                float boxLength = Mathf.RoundToInt(cascadeSliderWidth * currentPartition);

                // main cascade box
                Rect partitionRect = new Rect(currentX, cascadeBoxStartY, boxLength, kSliderbarHeight);
                GUI.Box(partitionRect, GUIContent.none, s_CascadeSliderBG);
                currentX += boxLength;

                // cascade box texts preparation
                Rect fullCascadeText  = partitionRect;
                Rect blendCascadeText = partitionRect;
                blendCascadeText.x    += partitionRect.width;
                blendCascadeText.width = 0f;
                float fullCascadeValue  = currentPartition * 100.0f;
                float blendCascadeValue = 0f;

                Rect separationRect = partitionRect;
                if (i < endPartitionBordersPercent.Length)
                {
                    // partition blend background and separators
                    GUI.backgroundColor  = Color.black;
                    separationRect.width = Mathf.Max(kPartitionHandleWidth, Mathf.CeilToInt(endPartitionBordersPercent[i] * partitionRect.width));
                    separationRect.x     = Mathf.CeilToInt(partitionRect.x + partitionRect.width - separationRect.width);
                    GUI.Box(separationRect, GUIContent.none, s_CascadeSliderBG);

                    //update cascade box texts update
                    blendCascadeValue       = endPartitionBordersPercent[i] * currentPartition * 100f;
                    fullCascadeValue       -= blendCascadeValue;
                    blendCascadeText.x     -= separationRect.width - 1; //remove left border
                    blendCascadeText.width  = endPartitionBordersPercent[i] * boxLength;
                    fullCascadeText.width  -= separationRect.width;
                    blendCascadeText.width -= 3; //remove right border
                }

                // full cascade box text
                GUI.color = Color.white;
                float textValue = fullCascadeValue;
                if (useMetric)
                {
                    textValue *= baseMetric / 100;
                }
                var cascadeText = String.Format(System.Globalization.CultureInfo.InvariantCulture.NumberFormat, "{0}\n{1:F1}{2}", i, textValue, useMetric ? 'm' : '%');
                GUI.Label(fullCascadeText, TempGUIContent(cascadeText, cascadeText), s_TextCenteredStyle);

                if (i >= endPartitionBordersPercent.Length)
                {
                    break;
                }

                // partition blend gradient
                Rect gradientRect = separationRect;
                gradientRect.x     += 1;
                gradientRect.width -= 3;
                if (gradientRect.width > 0)
                {
                    kBorderBlends.Value[i].Resize((int)gradientRect.width, 1);
                    FillWithGradient(kBorderBlends.Value[i], kCascadeColors[i], i < adjustedCascadePartitions.Length - 1 ? kCascadeColors[i + 1] : Color.black);
                    GUI.DrawTexture(gradientRect, kBorderBlends.Value[i]);
                }

                // blend cascade box text
                textValue = blendCascadeValue;
                if (useMetric)
                {
                    textValue *= baseMetric / 100;
                }
                if (i == normalizedCascadePartitions.Length)
                {
                    cascadeText = String.Format(System.Globalization.CultureInfo.InvariantCulture.NumberFormat, "{0}\u2192{1}\n{2:F1}{3}", i, blendCascadeText.width < 57 ? "F." : "Fallback", textValue, useMetric ? 'm' : '%');
                    string cascadeToolTip = String.Format(System.Globalization.CultureInfo.InvariantCulture.NumberFormat, "{0}\u2192{1}\n{2:F1}{3}", i, "Fallback", textValue, useMetric ? 'm' : '%');
                    GUI.Label(blendCascadeText, TempGUIContent(cascadeText, cascadeToolTip), s_TextCenteredStyle);
                }
                else
                {
                    cascadeText = String.Format(System.Globalization.CultureInfo.InvariantCulture.NumberFormat, "{0}\u2192{1}\n{2:F1}{3}", i, i + 1, textValue, useMetric ? 'm' : '%');
                    GUI.Label(blendCascadeText, TempGUIContent(cascadeText, cascadeText), s_TextCenteredStyle);
                }

                // init rect for Swatches
                Rect cascadeHandleRect = default;
                if (i < normalizedCascadePartitions.Length)
                {
                    cascadeHandleRect        = separationRect;
                    cascadeHandleRect.x     += separationRect.width - 6f;
                    cascadeHandleRect.width  = enabledCascadePartitionHandles[i] ? 10 : 0;
                    cascadeHandleRect.y     -= 14;
                    cascadeHandleRect.height = 15;
                }
                Rect blendHandleRect = default;
                if (drawEndPartitionHandles)
                {
                    blendHandleRect        = separationRect;
                    blendHandleRect.x     -= 5f;
                    blendHandleRect.width  = enabledEndPartitionBorderHandles[i] ? 10 : 0;
                    blendHandleRect.y     += 22;
                    blendHandleRect.height = 15;
                }

                if (eventType == EventType.Repaint) //Can only draw the snatch in repaint event
                {
                    // Add handle to change end of cascade
                    if (i < normalizedCascadePartitions.Length)
                    {
                        GUI.backgroundColor = enabledCascadePartitionHandles[i] ? kCascadeColors[colorIndex + 1] : kDisabledColor;
                        s_DownSwatch.Draw(cascadeHandleRect, false, false, s_BlendHandleSelected == i, false);
                    }

                    if (drawEndPartitionHandles)
                    {
                        GUI.backgroundColor = enabledEndPartitionBorderHandles[i] ? kCascadeColors[colorIndex] : kDisabledColor;
                        s_UpSwatch.Draw(blendHandleRect, false, false, s_BlendHandleSelected == i + 100, false);
                    }
                }

                if (cascadeHandleRect.Contains(currentEvent.mousePosition))
                {
                    hotPartitionHandleIndex = i;
                }

                if (blendHandleRect.Contains(currentEvent.mousePosition))
                {
                    hotPartitionHandleIndex = i + 100;
                }

                // add regions to slider where the cursor changes to Resize-Horizontal
                EditorGUIUtility.AddCursorRect(cascadeHandleRect, MouseCursor.ResizeHorizontal, sliderControlId);
                EditorGUIUtility.AddCursorRect(blendHandleRect, MouseCursor.ResizeHorizontal, sliderControlId);
            }

            GUI.color           = origTextColor;
            GUI.backgroundColor = origBackgroundColor;

            switch (eventType)
            {
            case EventType.MouseDown:
                if (hotPartitionHandleIndex >= 0)
                {
                    if (hotPartitionHandleIndex < 100)
                    {
                        s_DragCache = new DragCache(hotPartitionHandleIndex, normalizedCascadePartitions[hotPartitionHandleIndex], hotPartitionHandleIndex >= endPartitionBordersPercent.Length  ? 0f : endPartitionBordersPercent[hotPartitionHandleIndex], currentEvent.mousePosition, isEndBlendArea: false);
                    }
                    else
                    {
                        int endIndex = hotPartitionHandleIndex - 100;
                        s_DragCache = new DragCache(endIndex, adjustedCascadePartitions[endIndex], endPartitionBordersPercent[endIndex], currentEvent.mousePosition, isEndBlendArea: true);
                    }
                    if (GUIUtility.hotControl == 0)
                    {
                        GUIUtility.hotControl = sliderControlId;
                    }
                    currentEvent.Use();
                }
                break;

            case EventType.MouseUp:
                // mouseUp event anywhere should release the hotcontrol (if it belongs to us), drags (if any)
                if (GUIUtility.hotControl == sliderControlId)
                {
                    GUIUtility.hotControl = 0;
                    currentEvent.Use();
                }
                s_DragCache = null;
                break;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl != sliderControlId)
                {
                    break;
                }

                // convert the mouse movement to normalized cascade width. Make sure that we are safe to apply the delta before using it.
                if (s_DragCache.isEndBlendArea)
                {
                    float delta = (currentEvent.mousePosition - s_DragCache.lastCachedMousePosition).x / (cascadeSliderWidth * adjustedCascadePartitions[s_DragCache.activePartition]);
                    s_DragCache.endBlendAreaPercent = Mathf.Clamp01(s_DragCache.endBlendAreaPercent - delta);
                    endPartitionBordersPercent[s_DragCache.activePartition] = s_DragCache.endBlendAreaPercent;
                    GUI.changed = true;
                }
                else
                {
                    float delta = (currentEvent.mousePosition - s_DragCache.lastCachedMousePosition).x / cascadeSliderWidth;
                    bool  isLeftPartitionPositive  = ((adjustedCascadePartitions[s_DragCache.activePartition] + delta) > 0.0f);
                    bool  isRightPartitionPositive = ((adjustedCascadePartitions[s_DragCache.activePartition + 1] - delta) > 0.0f);
                    if (isLeftPartitionPositive && isRightPartitionPositive)
                    {
                        s_DragCache.normalizedPartitionSize += delta;
                        normalizedCascadePartitions[s_DragCache.activePartition] = s_DragCache.normalizedPartitionSize;
                        if (s_DragCache.activePartition < normalizedCascadePartitions.Length - 1)
                        {
                            normalizedCascadePartitions[s_DragCache.activePartition + 1] -= delta;
                        }
                        GUI.changed = true;
                    }
                }
                s_DragCache.lastCachedMousePosition = currentEvent.mousePosition;
                currentEvent.Use();
                break;
            }

            EditorGUILayout.EndHorizontal();
            GUILayout.Space(6);
            EditorGUILayout.EndVertical();
        }