Example #1
0
        private static bool DisplaySwitch(DiagnosticSwitch diagnosticSwitch)
        {
            GUIContent label = new GUIContent(diagnosticSwitch.name, diagnosticSwitch.name + "\n\n" + diagnosticSwitch.description);
            bool       flag  = !object.Equals(diagnosticSwitch.value, diagnosticSwitch.persistentValue);

            EditorGUI.BeginChangeCheck();
            using (new EditorGUILayout.HorizontalScope(new GUILayoutOption[0]))
            {
                GUILayoutOption[] options = new GUILayoutOption[] { GUILayout.ExpandWidth(true) };
                Rect position             = GUILayoutUtility.GetRect(GUIContent.none, EditorStyles.label, options);
                Rect rect2 = new Rect(position.x, position.y, position.height, position.height);
                position.xMin += rect2.width + 3f;
                if (flag && (Event.current.type == EventType.Repaint))
                {
                    GUI.DrawTexture(rect2, s_Resources.smallWarningIcon);
                }
                if (diagnosticSwitch.value is bool)
                {
                    diagnosticSwitch.persistentValue = EditorGUI.Toggle(position, label, (bool)diagnosticSwitch.persistentValue);
                }
                else if (diagnosticSwitch.enumInfo != null)
                {
                    if (diagnosticSwitch.enumInfo.isFlags)
                    {
                        int num = 0;
                        foreach (int num2 in diagnosticSwitch.enumInfo.values)
                        {
                            num |= num2;
                        }
                        string[] names  = diagnosticSwitch.enumInfo.names;
                        int[]    values = diagnosticSwitch.enumInfo.values;
                        if (diagnosticSwitch.enumInfo.values[0] == 0)
                        {
                            names  = new string[names.Length - 1];
                            values = new int[values.Length - 1];
                            Array.Copy(diagnosticSwitch.enumInfo.names, 1, names, 0, names.Length);
                            Array.Copy(diagnosticSwitch.enumInfo.values, 1, values, 0, values.Length);
                        }
                        diagnosticSwitch.persistentValue = EditorGUI.MaskFieldInternal(position, label, (int)diagnosticSwitch.persistentValue, names, values, EditorStyles.popup) & num;
                    }
                    else
                    {
                        diagnosticSwitch.persistentValue = EditorGUI.IntPopup(position, label, (int)diagnosticSwitch.persistentValue, diagnosticSwitch.enumInfo.guiNames, diagnosticSwitch.enumInfo.values);
                    }
                }
                else if (diagnosticSwitch.value is uint)
                {
                    uint minValue = (uint)diagnosticSwitch.minValue;
                    uint maxValue = (uint)diagnosticSwitch.maxValue;
                    if ((((maxValue - minValue) <= 10) && ((maxValue - minValue) > 0)) && ((minValue < 0x7fffffff) && (maxValue < 0x7fffffff)))
                    {
                        diagnosticSwitch.persistentValue = (uint)EditorGUI.IntSlider(position, label, (int)((uint)diagnosticSwitch.persistentValue), (int)minValue, (int)maxValue);
                    }
                    else
                    {
                        diagnosticSwitch.persistentValue = (uint)EditorGUI.IntField(position, label, (int)((uint)diagnosticSwitch.persistentValue));
                    }
                }
                else if (diagnosticSwitch.value is string)
                {
                    diagnosticSwitch.persistentValue = EditorGUI.TextField(position, label, (string)diagnosticSwitch.persistentValue);
                }
            }
            if (EditorGUI.EndChangeCheck())
            {
                Debug.SetDiagnosticSwitch(diagnosticSwitch.name, diagnosticSwitch.persistentValue, true);
            }
            return(flag);
        }
 private static bool PassesFilter(DiagnosticSwitch diagnosticSwitch, string filterString)
 {
     return(string.IsNullOrEmpty(DiagnosticSwitchPreferences.s_FilterString) || diagnosticSwitch.name.ToLowerInvariant().Contains(filterString) || diagnosticSwitch.description.ToLowerInvariant().Contains(filterString));
 }
        private static bool DisplaySwitch(DiagnosticSwitch diagnosticSwitch)
        {
            GUIContent label = new GUIContent(diagnosticSwitch.name, diagnosticSwitch.name + "\n\n" + diagnosticSwitch.description);
            bool       flag  = !object.Equals(diagnosticSwitch.value, diagnosticSwitch.persistentValue);

            EditorGUI.BeginChangeCheck();
            using (new EditorGUILayout.HorizontalScope(new GUILayoutOption[0]))
            {
                Rect rect = GUILayoutUtility.GetRect(GUIContent.none, EditorStyles.label, new GUILayoutOption[]
                {
                    GUILayout.ExpandWidth(true)
                });
                Rect position = new Rect(rect.x, rect.y, rect.height, rect.height);
                rect.xMin += position.width + 3f;
                if (flag && Event.current.type == EventType.Repaint)
                {
                    GUI.DrawTexture(position, DiagnosticSwitchPreferences.s_Resources.smallWarningIcon);
                }
                if (diagnosticSwitch.value is bool)
                {
                    diagnosticSwitch.persistentValue = EditorGUI.Toggle(rect, label, (bool)diagnosticSwitch.persistentValue);
                }
                else if (diagnosticSwitch.enumInfo != null)
                {
                    if (diagnosticSwitch.enumInfo.isFlags)
                    {
                        int   num    = 0;
                        int[] values = diagnosticSwitch.enumInfo.values;
                        for (int i = 0; i < values.Length; i++)
                        {
                            int num2 = values[i];
                            num |= num2;
                        }
                        string[] array  = diagnosticSwitch.enumInfo.names;
                        int[]    array2 = diagnosticSwitch.enumInfo.values;
                        if (diagnosticSwitch.enumInfo.values[0] == 0)
                        {
                            array  = new string[array.Length - 1];
                            array2 = new int[array2.Length - 1];
                            Array.Copy(diagnosticSwitch.enumInfo.names, 1, array, 0, array.Length);
                            Array.Copy(diagnosticSwitch.enumInfo.values, 1, array2, 0, array2.Length);
                        }
                        diagnosticSwitch.persistentValue = (EditorGUI.MaskFieldInternal(rect, label, (int)diagnosticSwitch.persistentValue, array, array2, EditorStyles.popup) & num);
                    }
                    else
                    {
                        GUIContent[] array3 = new GUIContent[diagnosticSwitch.enumInfo.names.Length];
                        for (int j = 0; j < diagnosticSwitch.enumInfo.names.Length; j++)
                        {
                            array3[j] = new GUIContent(diagnosticSwitch.enumInfo.names[j], diagnosticSwitch.enumInfo.annotations[j]);
                        }
                        diagnosticSwitch.persistentValue = EditorGUI.IntPopup(rect, label, (int)diagnosticSwitch.persistentValue, array3, diagnosticSwitch.enumInfo.values);
                    }
                }
                else if (diagnosticSwitch.value is uint)
                {
                    uint num3 = (uint)diagnosticSwitch.minValue;
                    uint num4 = (uint)diagnosticSwitch.maxValue;
                    if (num4 - num3 <= 10u && num4 - num3 > 0u && num3 < 2147483647u && num4 < 2147483647u)
                    {
                        diagnosticSwitch.persistentValue = (uint)EditorGUI.IntSlider(rect, label, (int)((uint)diagnosticSwitch.persistentValue), (int)num3, (int)num4);
                    }
                    else
                    {
                        diagnosticSwitch.persistentValue = (uint)EditorGUI.IntField(rect, label, (int)((uint)diagnosticSwitch.persistentValue));
                    }
                }
                else if (diagnosticSwitch.value is int)
                {
                    int num5 = (int)diagnosticSwitch.minValue;
                    int num6 = (int)diagnosticSwitch.maxValue;
                    if ((long)(num6 - num5) <= 10L && num6 - num5 > 0 && num5 < 2147483647 && num6 < 2147483647)
                    {
                        diagnosticSwitch.persistentValue = EditorGUI.IntSlider(rect, label, (int)diagnosticSwitch.persistentValue, num5, num6);
                    }
                    else
                    {
                        diagnosticSwitch.persistentValue = EditorGUI.IntField(rect, label, (int)diagnosticSwitch.persistentValue);
                    }
                }
                else if (diagnosticSwitch.value is string)
                {
                    diagnosticSwitch.persistentValue = EditorGUI.TextField(rect, label, (string)diagnosticSwitch.persistentValue);
                }
                else
                {
                    GUIStyle gUIStyle = new GUIStyle();
                    gUIStyle.normal.textColor = Color.red;
                    EditorGUI.LabelField(rect, label, EditorGUIUtility.TrTextContent("Unsupported type: " + diagnosticSwitch.value.GetType().Name, null, null), gUIStyle);
                }
            }
            if (EditorGUI.EndChangeCheck())
            {
                Debug.SetDiagnosticSwitch(diagnosticSwitch.name, diagnosticSwitch.persistentValue, true);
            }
            return(flag);
        }
Example #4
0
        private static bool DisplaySwitch(DiagnosticSwitch diagnosticSwitch)
        {
            var  labelText         = new GUIContent(diagnosticSwitch.name, diagnosticSwitch.name + "\n\n" + diagnosticSwitch.description);
            bool hasUnappliedValue = !System.Object.Equals(diagnosticSwitch.value, diagnosticSwitch.persistentValue);

            EditorGUI.BeginChangeCheck();
            using (new EditorGUILayout.HorizontalScope())
            {
                var rowRect = GUILayoutUtility.GetRect(GUIContent.none, EditorStyles.label, GUILayout.ExpandWidth(true));

                var warningRect = new Rect(rowRect.x, rowRect.y, rowRect.height, rowRect.height);
                rowRect.xMin += warningRect.width + 3;

                if (hasUnappliedValue && Event.current.type == EventType.Repaint)
                {
                    GUI.DrawTexture(warningRect, s_Resources.smallWarningIcon);
                }

                if (diagnosticSwitch.value is bool)
                {
                    diagnosticSwitch.persistentValue = EditorGUI.Toggle(rowRect, labelText, (bool)diagnosticSwitch.persistentValue);
                }
                else if (diagnosticSwitch.enumInfo != null)
                {
                    if (diagnosticSwitch.enumInfo.isFlags)
                    {
                        // MaskField's "Everything" entry will set the value to 0xffffffff, but that might mean that it has set bits that
                        // are not actually valid in the enum. Correct for it by masking the value against the bit patterns that are actually valid.
                        int validMask = 0;
                        foreach (int value in diagnosticSwitch.enumInfo.values)
                        {
                            validMask |= value;
                        }

                        // Also, many enums will provide a 'Nothing' entry at the bottom. If so we need to chop it off, because MaskField can't cope with there being two 'Nothing' entries.
                        string[] names  = diagnosticSwitch.enumInfo.names;
                        int[]    values = diagnosticSwitch.enumInfo.values;
                        if (diagnosticSwitch.enumInfo.values[0] == 0)
                        {
                            names  = new string[names.Length - 1];
                            values = new int[values.Length - 1];
                            Array.Copy(diagnosticSwitch.enumInfo.names, 1, names, 0, names.Length);
                            Array.Copy(diagnosticSwitch.enumInfo.values, 1, values, 0, values.Length);
                        }

                        diagnosticSwitch.persistentValue = EditorGUI.MaskFieldInternal(rowRect, labelText, (int)diagnosticSwitch.persistentValue, names, values, EditorStyles.popup) & validMask;
                    }
                    else
                    {
                        var guiNames = new GUIContent[diagnosticSwitch.enumInfo.names.Length];
                        for (int i = 0; i < diagnosticSwitch.enumInfo.names.Length; ++i)
                        {
                            guiNames[i] = new GUIContent(diagnosticSwitch.enumInfo.names[i], diagnosticSwitch.enumInfo.annotations[i]);
                        }
                        diagnosticSwitch.persistentValue = EditorGUI.IntPopup(rowRect, labelText, (int)diagnosticSwitch.persistentValue, guiNames, diagnosticSwitch.enumInfo.values);
                    }
                }
                else if (diagnosticSwitch.value is UInt32)
                {
                    UInt32 minValue = (UInt32)diagnosticSwitch.minValue;
                    UInt32 maxValue = (UInt32)diagnosticSwitch.maxValue;
                    if ((maxValue - minValue <= kMaxRangeForSlider) &&
                        (maxValue - minValue > 0) &&
                        (minValue < int.MaxValue && maxValue < int.MaxValue))
                    {
                        diagnosticSwitch.persistentValue = (UInt32)EditorGUI.IntSlider(rowRect, labelText, (int)(UInt32)diagnosticSwitch.persistentValue, (int)minValue, (int)maxValue);
                    }
                    else
                    {
                        diagnosticSwitch.persistentValue = (UInt32)EditorGUI.IntField(rowRect, labelText, (int)(UInt32)diagnosticSwitch.persistentValue);
                    }
                }
                else if (diagnosticSwitch.value is int)
                {
                    int minValue = (int)diagnosticSwitch.minValue;
                    int maxValue = (int)diagnosticSwitch.maxValue;
                    if ((maxValue - minValue <= kMaxRangeForSlider) &&
                        (maxValue - minValue > 0) &&
                        (minValue < int.MaxValue && maxValue < int.MaxValue))
                    {
                        diagnosticSwitch.persistentValue = EditorGUI.IntSlider(rowRect, labelText, (int)diagnosticSwitch.persistentValue, minValue, maxValue);
                    }
                    else
                    {
                        diagnosticSwitch.persistentValue = EditorGUI.IntField(rowRect, labelText, (int)diagnosticSwitch.persistentValue);
                    }
                }
                else if (diagnosticSwitch.value is string)
                {
                    diagnosticSwitch.persistentValue = EditorGUI.TextField(rowRect, labelText, (string)diagnosticSwitch.persistentValue);
                }
                else
                {
                    var redStyle = new GUIStyle();
                    redStyle.normal.textColor = Color.red;
                    EditorGUI.LabelField(rowRect, labelText, EditorGUIUtility.TrTextContent("Unsupported type: " + diagnosticSwitch.value.GetType().Name), redStyle);
                }
            }

            if (EditorGUI.EndChangeCheck())
            {
                Debug.SetDiagnosticSwitch(diagnosticSwitch.name, diagnosticSwitch.persistentValue, true);
            }

            return(hasUnappliedValue);
        }
 private static bool HasUnappliedValues(DiagnosticSwitch diagnosticSwitch)
 {
     return(!Equals(diagnosticSwitch.value, diagnosticSwitch.persistentValue));
 }
 private static bool PassesFilter(DiagnosticSwitch diagnosticSwitch, string filterString)
 {
     return(string.IsNullOrEmpty(filterString) ||
            SearchUtils.MatchSearchGroups(filterString, diagnosticSwitch.name));
 }
        private void DisplaySwitch(DiagnosticSwitch diagnosticSwitch)
        {
            var labelText = new GUIContent(diagnosticSwitch.name, diagnosticSwitch.description);

            var rowRect = GUILayoutUtility.GetRect(0, EditorGUI.kSingleLineHeight, GUILayout.ExpandWidth(true));

            rowRect.xMax -= GUISkin.current.verticalScrollbar.fixedWidth + 5;
            var iconScaleFactor = EditorGUI.kSingleLineHeight / Styles.smallWarningIcon.height;
            var warningRect     = new Rect(rowRect.x, rowRect.y, Styles.smallWarningIcon.width * iconScaleFactor, Styles.smallWarningIcon.height * iconScaleFactor);

            rowRect.x += warningRect.width + 2;
            if (diagnosticSwitch.needsRestart && Event.current.type == EventType.Repaint)
            {
                GUI.DrawTexture(warningRect, Styles.smallWarningIcon);
            }

            var resetButtonSize = EditorStyles.miniButton.CalcSize(GUIContent.Temp("Reset"));
            var resetButtonRect = new Rect(rowRect.xMax - resetButtonSize.x, rowRect.y, resetButtonSize.x,
                                           resetButtonSize.y);

            rowRect.xMax -= resetButtonSize.x + 2;
            if (!diagnosticSwitch.isSetToDefault)
            {
                if (GUI.Button(resetButtonRect, "Reset", EditorStyles.miniButton))
                {
                    diagnosticSwitch.persistentValue = diagnosticSwitch.defaultValue;
                    DiagnosticSwitchesConsoleMessage.Instance.Update();
                }
            }
            else
            {
                // Reserve an ID for the 'reset' button so that if the user begins typing in a text-valued switch, the
                // button showing up doesn't cause the focus to change
                GUIUtility.GetControlID("Button".GetHashCode(), FocusType.Passive, resetButtonRect);
            }

            EditorGUIUtility.SetBoldDefaultFont(!diagnosticSwitch.persistentValue.Equals(diagnosticSwitch.defaultValue));

            EditorGUI.BeginChangeCheck();

            if (diagnosticSwitch.value is bool)
            {
                diagnosticSwitch.persistentValue = EditorGUI.Toggle(rowRect, labelText, (bool)diagnosticSwitch.persistentValue);
            }
            else if (diagnosticSwitch.enumInfo != null)
            {
                if (diagnosticSwitch.enumInfo.isFlags)
                {
                    // MaskField's "Everything" entry will set the value to 0xffffffff, but that might mean that it has set bits that
                    // are not actually valid in the enum. Correct for it by masking the value against the bit patterns that are actually valid.
                    int validMask = 0;
                    foreach (int value in diagnosticSwitch.enumInfo.values)
                    {
                        validMask |= value;
                    }

                    // Also, many enums will provide a 'Nothing' entry at the bottom. If so we need to chop it off, because MaskField can't cope with there being two 'Nothing' entries.
                    string[] names  = diagnosticSwitch.enumInfo.names;
                    int[]    values = diagnosticSwitch.enumInfo.values;
                    if (diagnosticSwitch.enumInfo.values[0] == 0)
                    {
                        names  = new string[names.Length - 1];
                        values = new int[values.Length - 1];
                        Array.Copy(diagnosticSwitch.enumInfo.names, 1, names, 0, names.Length);
                        Array.Copy(diagnosticSwitch.enumInfo.values, 1, values, 0, values.Length);
                    }

                    diagnosticSwitch.persistentValue = EditorGUI.MaskFieldInternal(rowRect, labelText, (int)diagnosticSwitch.persistentValue, names, values, EditorStyles.popup) & validMask;
                }
                else
                {
                    var guiNames = new GUIContent[diagnosticSwitch.enumInfo.names.Length];
                    for (int i = 0; i < diagnosticSwitch.enumInfo.names.Length; ++i)
                    {
                        guiNames[i] = new GUIContent(diagnosticSwitch.enumInfo.names[i], diagnosticSwitch.enumInfo.annotations[i]);
                    }
                    diagnosticSwitch.persistentValue = EditorGUI.IntPopup(rowRect, labelText, (int)diagnosticSwitch.persistentValue, guiNames, diagnosticSwitch.enumInfo.values);
                }
            }
            else if (diagnosticSwitch.value is UInt32)
            {
                UInt32 minValue = (UInt32)diagnosticSwitch.minValue;
                UInt32 maxValue = (UInt32)diagnosticSwitch.maxValue;
                if ((maxValue - minValue <= kMaxRangeForSlider) &&
                    (maxValue - minValue > 0) &&
                    (minValue < int.MaxValue && maxValue < int.MaxValue))
                {
                    diagnosticSwitch.persistentValue = (UInt32)EditorGUI.IntSlider(rowRect, labelText, (int)(UInt32)diagnosticSwitch.persistentValue, (int)minValue, (int)maxValue);
                }
                else
                {
                    diagnosticSwitch.persistentValue = (UInt32)EditorGUI.IntField(rowRect, labelText, (int)(UInt32)diagnosticSwitch.persistentValue);
                }
            }
            else if (diagnosticSwitch.value is int)
            {
                int minValue = (int)diagnosticSwitch.minValue;
                int maxValue = (int)diagnosticSwitch.maxValue;
                if ((maxValue - minValue <= kMaxRangeForSlider) &&
                    (maxValue - minValue > 0) &&
                    (minValue < int.MaxValue && maxValue < int.MaxValue))
                {
                    diagnosticSwitch.persistentValue = EditorGUI.IntSlider(rowRect, labelText, (int)diagnosticSwitch.persistentValue, minValue, maxValue);
                }
                else
                {
                    diagnosticSwitch.persistentValue = EditorGUI.IntField(rowRect, labelText, (int)diagnosticSwitch.persistentValue);
                }
            }
            else if (diagnosticSwitch.value is string)
            {
                diagnosticSwitch.persistentValue = EditorGUI.TextField(rowRect, labelText, (string)diagnosticSwitch.persistentValue);
            }
            else if (diagnosticSwitch.value is float)
            {
                diagnosticSwitch.persistentValue = EditorGUI.FloatField(rowRect, labelText, (float)diagnosticSwitch.persistentValue);
            }
            else
            {
                var redStyle = new GUIStyle();
                redStyle.normal.textColor = Color.red;
                EditorGUI.LabelField(rowRect, labelText, EditorGUIUtility.TrTextContent("Unsupported type: " + diagnosticSwitch.value.GetType().Name), redStyle);
            }

            if (EditorGUI.EndChangeCheck())
            {
                DiagnosticSwitchesConsoleMessage.Instance.Update();
            }
        }
 private static bool DisplaySwitch(DiagnosticSwitch diagnosticSwitch)
 {
     GUIContent label = new GUIContent(diagnosticSwitch.name, diagnosticSwitch.name + "\n\n" + diagnosticSwitch.description);
     bool flag = !object.Equals(diagnosticSwitch.value, diagnosticSwitch.persistentValue);
     EditorGUI.BeginChangeCheck();
     using (new EditorGUILayout.HorizontalScope(new GUILayoutOption[0]))
     {
         GUILayoutOption[] options = new GUILayoutOption[] { GUILayout.ExpandWidth(true) };
         Rect position = GUILayoutUtility.GetRect(GUIContent.none, EditorStyles.label, options);
         Rect rect2 = new Rect(position.x, position.y, position.height, position.height);
         position.xMin += rect2.width + 3f;
         if (flag && (Event.current.type == EventType.Repaint))
         {
             GUI.DrawTexture(rect2, s_Resources.smallWarningIcon);
         }
         if (diagnosticSwitch.value is bool)
         {
             diagnosticSwitch.persistentValue = EditorGUI.Toggle(position, label, (bool) diagnosticSwitch.persistentValue);
         }
         else if (diagnosticSwitch.enumInfo != null)
         {
             if (diagnosticSwitch.enumInfo.isFlags)
             {
                 int num = 0;
                 foreach (int num2 in diagnosticSwitch.enumInfo.values)
                 {
                     num |= num2;
                 }
                 string[] names = diagnosticSwitch.enumInfo.names;
                 int[] values = diagnosticSwitch.enumInfo.values;
                 if (diagnosticSwitch.enumInfo.values[0] == 0)
                 {
                     names = new string[names.Length - 1];
                     values = new int[values.Length - 1];
                     Array.Copy(diagnosticSwitch.enumInfo.names, 1, names, 0, names.Length);
                     Array.Copy(diagnosticSwitch.enumInfo.values, 1, values, 0, values.Length);
                 }
                 diagnosticSwitch.persistentValue = EditorGUI.MaskFieldInternal(position, label, (int) diagnosticSwitch.persistentValue, names, values, EditorStyles.popup) & num;
             }
             else
             {
                 diagnosticSwitch.persistentValue = EditorGUI.IntPopup(position, label, (int) diagnosticSwitch.persistentValue, diagnosticSwitch.enumInfo.guiNames, diagnosticSwitch.enumInfo.values);
             }
         }
         else if (diagnosticSwitch.value is uint)
         {
             uint minValue = (uint) diagnosticSwitch.minValue;
             uint maxValue = (uint) diagnosticSwitch.maxValue;
             if ((((maxValue - minValue) <= 10) && ((maxValue - minValue) > 0)) && ((minValue < 0x7fffffff) && (maxValue < 0x7fffffff)))
             {
                 diagnosticSwitch.persistentValue = (uint) EditorGUI.IntSlider(position, label, (int) ((uint) diagnosticSwitch.persistentValue), (int) minValue, (int) maxValue);
             }
             else
             {
                 diagnosticSwitch.persistentValue = (uint) EditorGUI.IntField(position, label, (int) ((uint) diagnosticSwitch.persistentValue));
             }
         }
         else if (diagnosticSwitch.value is string)
         {
             diagnosticSwitch.persistentValue = EditorGUI.TextField(position, label, (string) diagnosticSwitch.persistentValue);
         }
     }
     if (EditorGUI.EndChangeCheck())
     {
         Debug.SetDiagnosticSwitch(diagnosticSwitch.name, diagnosticSwitch.persistentValue, true);
     }
     return flag;
 }