public static void showBar(IPool pool)
        {
            var   r  = EditorGUILayout.GetControlRect(false, GUILayout.Height(20));
            float hi = Mathf.Max(pool.Count, pool.Settings.Threshold);
            Color c  = Color.green;

            if (pool.Count < pool.Settings.MinItems)
            {
                c = Color.yellow;
            }
            else if (pool.Count > pool.Settings.Threshold)
            {
                c = Color.red;
            }
            DTGUI.PushContentColor(c);
            var s = pool.Identifier;

            if (!string.IsNullOrEmpty(s))
            {
                var i = s.IndexOf(",");
                if (i > 0)
                {
                    s = pool.Identifier.Substring(0, i);
                }
            }
            EditorGUI.ProgressBar(r, pool.Count / hi, s + ":" + pool.Count.ToString());
            DTGUI.PopContentColor();
        }
示例#2
0
 protected void PopCustomColors()
 {
     if (!string.IsNullOrEmpty(Attribute.Color))
     {
         DTGUI.PopColor();
     }
 }
示例#3
0
 protected void PushCustomColors()
 {
     if (!string.IsNullOrEmpty(Attribute.Color))
     {
         DTGUI.PushColor(Attribute.Color.ColorFromHtml());
     }
 }
示例#4
0
        void doCompact(Rect r, SerializedProperty property, GUIContent label, GUIContent labelTo, bool showOptional, bool fullLine = false)
        {
            float lw               = EditorGUIUtility.labelWidth;
            float fw               = EditorGUIUtility.fieldWidth;
            var   r2               = new Rect(r);
            bool  showTo           = !showOptional || !ppSimpleValue.boolValue;
            float showToLabelWidth = DTGUI.LabelWidth(labelTo);

            float chkWidth = showOptional ? 16 : 0;

            if (fullLine)
            {
                EditorGUIUtility.labelWidth = DTGUI.LabelWidth(label);
                lw = EditorGUIUtility.labelWidth;
            }

            r2.width = (r.width - lw - chkWidth - showToLabelWidth) / 2;

            // From
            r.width = lw + r2.width;
            EditorGUI.BeginChangeCheck();
            EditorGUI.PropertyField(r, ppFrom, label);
            if (EditorGUI.EndChangeCheck())
            {
                validateFrom();
            }

            r.x += r.width;

            // "To" may be optional
            if (showOptional)
            {
                ppSimpleValue.boolValue = !EditorGUI.Toggle(new Rect(r.x, r.y, 16, r.height), new GUIContent("", mOptions.OptionalTooltip), !ppSimpleValue.boolValue);
                r.x += 16;
            }
            // Show "To"?

            if (showTo)
            {
                EditorGUI.BeginChangeCheck();
                EditorGUIUtility.labelWidth = showToLabelWidth;
                r.width         = r2.width + showToLabelWidth;
                ppTo.floatValue = EditorGUI.FloatField(r, labelTo, ppTo.floatValue);
                if (EditorGUI.EndChangeCheck())
                {
                    validateTo();
                }
            }

            EditorGUIUtility.labelWidth = lw;
            EditorGUIUtility.fieldWidth = fw;
        }
        public virtual void RenderSectionHeader(DTGroupNode node)
        {
            GUILayout.Space(10);
            var r   = EditorGUILayout.GetControlRect(false, 16);
            int lvl = EditorGUI.indentLevel;

            EditorGUI.indentLevel = Mathf.Max(0, lvl - 1);
            r = EditorGUI.IndentedRect(r);
            float off = (DTInspectorNode.IsInsideInspector) ? 12 : 0;

            r.x -= off;
            bool hasHelp = !string.IsNullOrEmpty(node.HelpURL);

            DTGUI.PushColor(new Color(0.8f, 0.8f, 0.8f));
            var r2 = new Rect(r.x - 1, r.y - 2, r.width + off + 4, r.height + 5);

            DTHandles.DrawOutline(r2, Color.black);
            GUI.Box(r2, "", GUI.skin.box);

            DTGUI.PopColor();
            var r3 = new Rect(r);

            if (hasHelp)
            {
                r3.width -= 20;
            }

            node.Expanded = GUI.Toggle(r3, node.Expanded, node.GUIContent, BoldFoldout);;
            if (hasHelp)
            {
                if (GUI.Button(new Rect(r2.xMax - 20, r2.y + 3, 16, 16), new GUIContent(HelpIcon), new GUIStyle()))
                {
                    Application.OpenURL(node.HelpURL);
                }
            }
            if (node.Expanded)
            {
                GUILayout.Space(3);
            }
            EditorGUILayout.BeginFadeGroup(node.ExpandedFaded);
            EditorGUI.indentLevel = (node.Level <= 1) ? lvl : lvl + 1;
        }
示例#6
0
        static void Render(SceneView view)
        {
            Event ev = Event.current;

            MouseOverToolbarElement = false;
            // Only let certain hotkeys pass
            if (!EditorGUIUtility.editingTextField)
            {
                GUIUtility.keyboardControl = GUIUtility.GetControlID(FocusType.Passive);
            }

            List <DTProject> projects = DT.Projects;

            projects.Sort();

            Handles.BeginGUI();
            GUI.skin = null; // to ensure light-skin is used if set in preferences (or not Pro)
            // Get largest item for each side
            if (RecalcItemSize)
            {
                calcMaxItemDimension();
            }

            // Get starting position for each side
            _InitialRects = getInitialItemRect();
            _ItemRect     = new Rect[4];
            _InitialRects.CopyTo(_ItemRect, 0);

            DTToolbarItem lastItem = null;

            DTSelection.MuteEvents = true;

            DTToolbarItem hovering = null;

            foreach (DTProject project in projects)
            {
#if UNITY_5_0
                if (true)
#else
                if (project.ShowToolbarInAllSceneViews || view.titleContent.text == "Scene")
#endif
                {
                    int side = (int)project.ToolbarOrientation;
                    if (lastItem && lastItem.Project.ToolbarOrientation != project.ToolbarOrientation)
                    {
                        lastItem = null;
                    }
                    List <DTToolbarItem> items = project.ToolbarItems;

                    // Render items
                    for (int i = 0; i < items.Count; i++)
                    {
                        if (items[i].Visible)
                        {
                            Vector2 itemSize = items[i].GetItemSize();                       // size of current item
                            _ItemRect[side] = advanceItemRect(lastItem, items[i], itemSize); // advance by using the last itemRect and the new(current) size

                            items[i].mItemRect = _ItemRect[side];                            // Store current item rect


                            if (items[i].Enabled)
                            {
                                Handles.EndGUI();
                                EditorKeyBinding.BindingsEnabled = false;
                                if (items[i].mItemRect.Contains(DTGUI.MousePosition))
                                {
                                    hovering = items[i];
                                    MouseOverToolbarElement = true;
                                }
                                items[i].OnSceneGUI();

                                EditorKeyBinding.BindingsEnabled = true;
                                Handles.BeginGUI();
                            }
                            GUI.enabled = items[i].Enabled;
                            items[i].Render(_ItemRect[side]);

                            GUI.enabled = true;
                            if (ev != null && items[i].Enabled && (DTToolbarItem.FocusedItem == null || DTToolbarItem.FocusedItem == items[i]))
                            {
                                items[i].HandleEvents(ev);
                            }

                            lastItem = items[i];
                        }
                    }
                }
            }
            DTSelection.MuteEvents = false;
            detailOpen             = false;
            // Render items client area (Note: itemRect contains the last rendered item, a.k.a. a way to get the number of rows/cols needed
            foreach (DTProject project in projects)
            {
#if UNITY_5_0
                if (true)
#else
                if (project.ShowToolbarInAllSceneViews || view.titleContent.text == "Scene")
#endif
                {
                    List <DTToolbarItem> items = project.ToolbarItems;
                    for (int i = 0; i < items.Count; i++)
                    {
                        if (items[i].Visible && items[i].ShowClientArea)
                        {
                            detailOpen = true;
                            Rect clientRect = items[i].mItemRect;
                            int  side       = (int)project.ToolbarOrientation;
                            switch (project.ToolbarOrientation)
                            {
                            case DTToolbarOrientation.Left:
                                clientRect.x = _ItemRect[side].x + _MaxItemDimension[side].x + 5;
                                break;

                            case DTToolbarOrientation.Right:
                                clientRect.x = _ItemRect[side].x - 5;
                                break;

                            case DTToolbarOrientation.Top:
                                clientRect.y = _ItemRect[side].y + _MaxItemDimension[side].y + 5;
                                break;

                            case DTToolbarOrientation.Bottom:
                                clientRect.y = _ItemRect[side].y - 5;
                                break;
                            }
                            if (clientRect.width > 0 && clientRect.height > 0)
                            {
                                items[i].mBackgroundRects.Clear();
                                MouseOverToolbarElement          = MouseOverToolbarElement || clientRect.Contains(DTGUI.MousePosition);
                                EditorKeyBinding.BindingsEnabled = false;
                                items[i].RenderClientArea(clientRect);
                                EditorKeyBinding.BindingsEnabled = true;
                                if (DTGUI.IsClick)
                                {
                                    foreach (Rect r in items[i].mBackgroundRects)
                                    {
                                        if (r.Contains(ev.mousePosition))
                                        {
                                            DTGUI.UseEvent(items[i].GetHashCode(), ev);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }



            // Handle statusbar info when hovering over an item
            if (hovering != null)
            {
                DTToolbarItem._StatusBar.Set(hovering.StatusBarInfo, "Info");
            }
            else
            {
                DTToolbarItem._StatusBar.Clear("Info");
            }

            // Render Statusbar
            DTToolbarItem._StatusBar.Render(getStatusBarRect(), null, true);

            Handles.EndGUI();
        }
示例#7
0
        public static void DoGUI(Rect position, SerializedProperty property, DTPropertyAttribute attribute, GUIContent label, AttributeOptionsFlags flags, VectorExPropertyDrawer drawer = null)
        {
            if (property.propertyType != SerializedPropertyType.Vector2 && property.propertyType != SerializedPropertyType.Vector3 && property.propertyType != SerializedPropertyType.Quaternion)
            {
                Debug.LogError("DevTools: [VectorEx] only valid for Vector and Quaternion fields!");
            }
            else
            {
                Rect posb = position.WithoutLabel();
                posb.height = EditorGUIUtility.singleLineHeight;

                int buttons = 0;
                if (flags.HasFlag(AttributeOptionsFlags.Clipboard))
                {
                    buttons += 2;
                }
                if (flags.HasFlag(AttributeOptionsFlags.One))
                {
                    buttons++;
                }
                if (flags.HasFlag(AttributeOptionsFlags.Zero))
                {
                    buttons++;
                }
                if (flags.HasFlag(AttributeOptionsFlags.Negate))
                {
                    buttons++;
                }

                Rect r = position.WithoutLabel();
                r.width -= buttons * 20;

                if (flags.HasFlag(AttributeOptionsFlags.Compact) || EditorGUIUtility.wideMode)
                {
                    if (drawer != null)
                    {
                        drawer.PushCustomColors();
                    }
                    EditorGUI.PrefixLabel(position, label);

                    if (property.propertyType == SerializedPropertyType.Vector2)
                    {
                        EditorGUI.BeginChangeCheck();
                        Vector2 v = DTGUI.CompactVector2Field(r, property.vector2Value);
                        if (EditorGUI.EndChangeCheck())
                        {
                            property.vector2Value = DT._UseSnapValuePrecision ? DTMath.SnapPrecision(v, attribute.Precision) : v;
                        }
                    }
                    else if (property.propertyType == SerializedPropertyType.Vector3)
                    {
                        EditorGUI.BeginChangeCheck();
                        Vector3 v = DTGUI.CompactVector3Field(r, property.vector3Value);
                        if (EditorGUI.EndChangeCheck())
                        {
                            property.vector3Value = DT._UseSnapValuePrecision ? DTMath.SnapPrecision(v, attribute.Precision) : v;
                        }
                    }
                    else if (property.propertyType == SerializedPropertyType.Quaternion)
                    {
                        EditorGUI.BeginChangeCheck();
                        Vector3 v = DTGUI.CompactVector3Field(r, DT._UseSnapValuePrecision ? DTMath.SnapPrecision(property.quaternionValue.eulerAngles, attribute.Precision) : property.quaternionValue.eulerAngles);
                        if (EditorGUI.EndChangeCheck())
                        {
                            property.quaternionValue = Quaternion.Euler(v);
                        }
                    }
                    if (drawer != null)
                    {
                        drawer.PopCustomColors();
                    }
                }
                else
                {
                    EditorGUI.BeginChangeCheck();
                    if (drawer != null)
                    {
                        drawer.PushCustomColors();
                    }
                    EditorGUI.PropertyField(position, property, label);
                    if (drawer != null)
                    {
                        drawer.PopCustomColors();
                    }
                    if (EditorGUI.EndChangeCheck() && DT._UseSnapValuePrecision)
                    {
                        if (property.propertyType == SerializedPropertyType.Vector2)
                        {
                            property.vector2Value = DTMath.SnapPrecision(property.vector2Value, attribute.Precision);
                        }
                        else if (property.propertyType == SerializedPropertyType.Vector3)
                        {
                            property.vector3Value = DTMath.SnapPrecision(property.vector3Value, attribute.Precision);
                        }
                    }
                }

                // Buttons
                posb       = posb.ShiftXBy(r.width);
                posb.width = 19;
                if (flags.HasFlag(AttributeOptionsFlags.Clipboard))
                {
                    if (GUI.Button(posb, new GUIContent("C", "Copy"), EditorStyles.miniButton))
                    {
                        if (property.propertyType == SerializedPropertyType.Vector2)
                        {
                            DT.ClipboardCopy(property.vector2Value);
                        }
                        else if (property.propertyType == SerializedPropertyType.Vector3)
                        {
                            DT.ClipboardCopy(property.vector3Value);
                        }
                    }
                    posb.x += 20;
                    // Can Paste?
                    if (property.propertyType == SerializedPropertyType.Vector2)
                    {
                        GUI.enabled = DT.ClipboardCanPasteTo <Vector2>();
                    }
                    else if (property.propertyType == SerializedPropertyType.Vector3)
                    {
                        GUI.enabled = DT.ClipboardCanPasteTo <Vector3>();
                    }

                    if (GUI.Button(posb, new GUIContent("P", "Pastge"), EditorStyles.miniButton))
                    {
                        if (property.propertyType == SerializedPropertyType.Vector2)
                        {
                            property.vector2Value = DT.ClipboardPaste <Vector2>();
                        }
                        else if (property.propertyType == SerializedPropertyType.Vector3)
                        {
                            property.vector3Value = DT.ClipboardPaste <Vector3>();
                        }
                    }
                    GUI.enabled = true;
                    posb.x     += 20;
                }
                if (flags.HasFlag(AttributeOptionsFlags.Zero))
                {
                    if (GUI.Button(posb, new GUIContent("0", "Set to zero"), EditorStyles.miniButton))
                    {
                        if (property.propertyType == SerializedPropertyType.Vector2)
                        {
                            property.vector2Value = Vector2.zero;
                        }
                        else if (property.propertyType == SerializedPropertyType.Vector3)
                        {
                            property.vector3Value = Vector3.zero;
                        }
                    }
                    posb.x += 20;
                }
                if (flags.HasFlag(AttributeOptionsFlags.One))
                {
                    if (GUI.Button(posb, new GUIContent("1", "Set to one"), EditorStyles.miniButton))
                    {
                        if (property.propertyType == SerializedPropertyType.Vector2)
                        {
                            property.vector2Value = Vector2.one;
                        }
                        else if (property.propertyType == SerializedPropertyType.Vector3)
                        {
                            property.vector3Value = Vector3.one;
                        }
                    }
                    posb.x += 20;
                }
                if (flags.HasFlag(AttributeOptionsFlags.Negate))
                {
                    if (GUI.Button(posb, new GUIContent("~", "Negate"), EditorStyles.miniButton))
                    {
                        if (property.propertyType == SerializedPropertyType.Vector2)
                        {
                            property.vector2Value *= -1;
                        }
                        else if (property.propertyType == SerializedPropertyType.Vector3)
                        {
                            property.vector3Value *= -1;
                        }
                    }
                    posb.x += 20;
                }
            }
        }