public static void Draw(this GUIStyle current, string key, bool compact = false, bool grouped = false, bool headers = false)
        {
            EditorGUILayout.BeginVertical();
            var styleKey     = key + "." + current.name;
            var styleFoldout = current.name.ToLabel().DrawFoldout(styleKey);

            if (styleFoldout)
            {
                var labelWidth = compact ? 140 : 0;
                EditorGUI.indentLevel += 1;
                EditorUI.SetFieldSize(-1, labelWidth, false);
                current.name = current.name.Draw("Name".ToLabel());
                Utility.SetPref <bool>(key + "." + current.name, true);
                if (compact && headers)
                {
                    EditorGUILayout.BeginHorizontal();
                    GUILayout.Space(140);
                    EditorUI.SetLayout(120);
                    "Text".ToLabel().DrawLabel(EditorStyles.boldLabel, false);
                    "Background".ToLabel().DrawLabel(EditorStyles.boldLabel, false);
                    EditorGUILayout.EndHorizontal();
                }
                foreach (var state in current.GetNamedStates())
                {
                    state.Value.Draw(state.Key, compact, styleKey + "." + state.Key);
                }
                current.border.Draw("Border", compact, key + ".Border");
                current.margin.Draw("Margin", compact, key + ".Margin");
                current.padding.Draw("Padding", compact, key + ".Padding");
                current.overflow.Draw("Overflow", compact, key + ".Overflow");
                if (!grouped || "Text".ToTitleCase().ToLabel().DrawFoldout(key + "Text"))
                {
                    current.DrawTextSettings(compact);
                }
                if (!grouped || "Position & Size".ToTitleCase().ToLabel().DrawFoldout(key + "Area"))
                {
                    current.imagePosition = current.imagePosition.Draw("Image Position").As <ImagePosition>();
                    current.contentOffset = current.contentOffset.DrawVector2("Content Offset");
                    current.fixedWidth    = current.fixedWidth.Draw("Fixed Width");
                    current.fixedHeight   = current.fixedHeight.Draw("Fixed Height");
                    current.stretchWidth  = current.stretchWidth.Draw("Stretch Width");
                    current.stretchHeight = current.stretchHeight.Draw("Stretch Height");
                }
                EditorUI.ResetFieldSize();
                EditorGUI.indentLevel -= 1;
            }
            EditorGUILayout.EndVertical();
        }
Пример #2
0
 public static GUIStyleState[] GetStates(this GUIStyle current, bool offStates = true, bool onStates = true)
 {
     return(current.GetNamedStates(offStates, onStates).Values.ToArray());
 }
 public bool ContainsAttributes(GUIStyle style)
 {
     foreach (var input in this.searchAttributes)
     {
         var name       = input.name;
         var rawValue   = input.value;
         var value      = rawValue.Remove("*", "#");
         var state      = input.state;
         var CheckMatch = input.method;
         if (value.IsEmpty())
         {
             continue;
         }
         if (name.ContainsAny("textColor", "background"))
         {
             var found  = false;
             var states = style.GetNamedStates();
             if (!state.IsEmpty() && states.ContainsKey(state))
             {
                 states = states[state].AsArray().ToDictionary(x => state, x => x);
             }
             foreach (var item in states)
             {
                 var styleState = item.Value;
                 if (name.Matches("textColor", true))
                 {
                     bool hasAlpha     = !rawValue.Contains(" ") ? value.Length > 6 : value.Split(" ").Length == 4;
                     bool hexMatch     = !rawValue.Contains(" ") && CheckMatch(styleState.textColor.ToHex(hasAlpha));
                     bool decimalMatch = rawValue.Contains(" ") && CheckMatch(styleState.textColor.ToDecimal(hasAlpha));
                     if (hexMatch || decimalMatch)
                     {
                         found = true;
                     }
                 }
                 if (name.Matches("background", true) && !styleState.background.IsNull() && CheckMatch(styleState.background.name))
                 {
                     found = true;
                 }
             }
             if (found)
             {
                 continue;
             }
             return(false);
         }
         name = name.Replace("textClipping", "clipping").Replace("color", "textColor");
         if (name.IsEnum <GUIStyleField>())
         {
             var current = style.GetVariable(name);
             var type    = style.GetVariableType(name);
             if (current.IsNull())
             {
                 return(false);
             }
             if (type.Is <RectOffset>())
             {
                 if (!CheckMatch(current.As <RectOffset>().Serialize()))
                 {
                     return(false);
                 }
             }
             else if (type.Is <Vector2>())
             {
                 if (!CheckMatch(current.As <Vector2>().ToString().Remove(".0", ",", "(", ")")))
                 {
                     return(false);
                 }
             }
             else if (type.Is <bool>())
             {
                 if (value.ToBool() != current.As <bool>())
                 {
                     return(false);
                 }
             }
             else if (type.IsAny <float, int>())
             {
                 if (current.ToString() != value)
                 {
                     return(false);
                 }
             }
             else if (type.Is <Font>())
             {
                 if (!CheckMatch(current.As <Font>().name))
                 {
                     return(false);
                 }
             }
             else if (!CheckMatch(current.ToString()) && !CheckMatch(current.ToString().ToTitleCase()))
             {
                 return(false);
             }
         }
         else
         {
             return(false);
         }
     }
     return(true);
 }