コード例 #1
0
        // Public API to serialize GUIStyle and GUISkin
        public static void AddStyle(StyleSheetBuilderHelper helper, string name, GUIStyle style, GUIStyle defaultStyle = null, string extendName = null)
        {
            defaultStyle = defaultStyle ?? GUIStyle.none;
            // All common Style property
            helper.BeginRule();

            using (helper.builder.BeginComplexSelector(0))
            {
                // Construct rule according to the GUIStyle -> is it custom? is it bound on a type?
                helper.builder.AddSimpleSelector(new[] { StyleSelectorPart.CreateType(name) }, StyleSelectorRelationship.None);
            }

            if (!string.IsNullOrEmpty(extendName))
            {
                helper.AddPropertyString(ConverterUtils.k_Extend, extendName);
            }

            // Loop for each GUIStyle property
            if (helper.options.exportDefaultValues || style.alignment != defaultStyle.alignment)
            {
                helper.AddProperty(ConverterUtils.k_TextAlignment, ConverterUtils.ToUssString(style.alignment), "GUIStyle.alignment");
            }

            if (helper.options.exportDefaultValues || !GUISkinCompare.CompareTo(style.border, defaultStyle.border))
            {
                AddProperty(helper, ConverterUtils.k_Border, "", style.border, defaultStyle.border, "GUIStyle.border");
            }

            if (helper.options.exportDefaultValues || style.clipping != defaultStyle.clipping)
            {
                helper.AddProperty(ConverterUtils.k_Clipping, ConverterUtils.ToUssString(style.clipping), "GUIStyle.clipping");
            }

            if (helper.options.exportDefaultValues || style.contentOffset != defaultStyle.contentOffset)
            {
                helper.AddProperty(ConverterUtils.k_ContentOffset, style.contentOffset, "GUIStyle.contentOffset");
            }

            if (helper.options.exportDefaultValues || !GUISkinCompare.CompareTo(style.fixedHeight, defaultStyle.fixedHeight))
            {
                helper.AddProperty(ConverterUtils.k_Height, style.fixedHeight, "GUIStyle.fixedHeight");
            }

            if (helper.options.exportDefaultValues || !GUISkinCompare.CompareTo(style.fixedWidth, defaultStyle.fixedWidth))
            {
                helper.AddProperty(ConverterUtils.k_Width, style.fixedWidth, "GUIStyle.fixedWidth");
            }

            if (helper.options.exportDefaultValues || style.font != defaultStyle.font)
            {
                AddPropertyResource(helper, ConverterUtils.k_Font, style.font, "GUIStyle.font");
            }

            if (helper.options.exportDefaultValues || style.fontSize != defaultStyle.fontSize)
            {
                helper.AddProperty(ConverterUtils.k_FontSize, style.fontSize, "GUIStyle.fontSize");
            }

            if (helper.options.exportDefaultValues || style.fontStyle != defaultStyle.fontStyle)
            {
                AddProperty(helper, style.fontStyle, "GUIStyle.fontSize");
            }

            if (helper.options.exportDefaultValues || style.imagePosition != defaultStyle.imagePosition)
            {
                helper.AddProperty(ConverterUtils.k_ImagePosition, ConverterUtils.ToUssString(style.imagePosition), "GUIStyle.imagePosition");
            }

            if (helper.options.exportDefaultValues || !GUISkinCompare.CompareTo(style.margin, defaultStyle.margin))
            {
                AddProperty(helper, ConverterUtils.k_Margin, null, style.margin, defaultStyle.margin, "GUIStyle.margin");
            }

            // Always export name:
            helper.AddPropertyString(ConverterUtils.k_Name, style.name, "GUIStyle.name");

            if (helper.options.exportDefaultValues || !GUISkinCompare.CompareTo(style.overflow, defaultStyle.overflow))
            {
                AddProperty(helper, ConverterUtils.k_Overflow, null, style.overflow, defaultStyle.overflow, "GUIStyle.overflow");
            }

            if (helper.options.exportDefaultValues || !GUISkinCompare.CompareTo(style.padding, defaultStyle.padding))
            {
                AddProperty(helper, ConverterUtils.k_Padding, null, style.padding, defaultStyle.padding, "GUIStyle.padding");
            }

            if (helper.options.exportDefaultValues || style.richText != defaultStyle.richText)
            {
                helper.AddProperty(ConverterUtils.k_RichText, style.richText, "GUIStyle.richText");
            }

            if (helper.options.exportDefaultValues || style.stretchHeight != defaultStyle.stretchHeight)
            {
                helper.AddProperty(ConverterUtils.k_StretchHeight, style.stretchHeight, "GUIStyle.stretchHeight");
            }

            if (helper.options.exportDefaultValues || style.stretchWidth != defaultStyle.stretchWidth)
            {
                helper.AddProperty(ConverterUtils.k_StretchWidth, style.stretchWidth, "GUIStyle.stretchWidth");
            }

            if (helper.options.exportDefaultValues || style.wordWrap != defaultStyle.wordWrap)
            {
                helper.AddProperty(ConverterUtils.k_WordWrap, style.wordWrap, "GUIStyle.wordWrap");
            }

            // Add Normal state properties
            if (helper.options.exportDefaultValues || !GUISkinCompare.CompareTo(style.normal, defaultStyle.normal))
            {
                AddState(helper, style.normal, defaultStyle.normal);
            }

            helper.EndRule();

            // Add one rule for each GUIStyleState (other than normal)
            if (helper.options.exportDefaultValues || !GUISkinCompare.CompareTo(style.active, defaultStyle.active))
            {
                AddState(helper, name, style.active, "active", defaultStyle.active);
            }

            if (helper.options.exportDefaultValues || !GUISkinCompare.CompareTo(style.focused, defaultStyle.focused))
            {
                AddState(helper, name, style.focused, "focused", defaultStyle.focused);
            }

            if (helper.options.exportDefaultValues || !GUISkinCompare.CompareTo(style.hover, defaultStyle.hover))
            {
                AddState(helper, name, style.hover, "hover", defaultStyle.hover);
            }

            if (helper.options.exportDefaultValues || !GUISkinCompare.CompareTo(style.onActive, defaultStyle.onActive))
            {
                AddState(helper, name, style.onActive, "onActive", defaultStyle.onActive);
            }

            if (helper.options.exportDefaultValues || !GUISkinCompare.CompareTo(style.onFocused, defaultStyle.onFocused))
            {
                AddState(helper, name, style.onFocused, "onFocused", defaultStyle.onFocused);
            }

            if (helper.options.exportDefaultValues || !GUISkinCompare.CompareTo(style.onHover, defaultStyle.onHover))
            {
                AddState(helper, name, style.onHover, "onHover", defaultStyle.onHover);
            }

            if (helper.options.exportDefaultValues || !GUISkinCompare.CompareTo(style.onNormal, defaultStyle.onNormal))
            {
                AddState(helper, name, style.onNormal, "onNormal", defaultStyle.onNormal);
            }
        }
コード例 #2
0
        private void DrawMatchingRules()
        {
            if (s_MatchedRulesExtractor.selectedElementStylesheets != null && s_MatchedRulesExtractor.selectedElementStylesheets.Count > 0)
            {
                EditorGUILayout.LabelField(Styles.stylesheetsContent, Styles.KInspectorTitle);
                foreach (string sheet in s_MatchedRulesExtractor.selectedElementStylesheets)
                {
                    if (GUILayout.Button(sheet))
                    {
                        InternalEditorUtility.OpenFileAtLineExternal(sheet, 0);
                    }
                }
            }

            if (s_MatchedRulesExtractor.selectedElementRules != null && s_MatchedRulesExtractor.selectedElementRules.Count > 0)
            {
                EditorGUILayout.LabelField(Styles.selectorsContent, Styles.KInspectorTitle);
                int i = 0;
                foreach (MatchedRulesExtractor.MatchedRule rule in s_MatchedRulesExtractor.selectedElementRules)
                {
                    StringBuilder builder = new StringBuilder();
                    for (int j = 0; j < rule.ruleMatcher.complexSelector.selectors.Length; j++)
                    {
                        StyleSelector sel = rule.ruleMatcher.complexSelector.selectors[j];
                        switch (sel.previousRelationship)
                        {
                        case StyleSelectorRelationship.Child:
                            builder.Append(" > ");
                            break;

                        case StyleSelectorRelationship.Descendent:
                            builder.Append(" ");
                            break;
                        }
                        for (int k = 0; k < sel.parts.Length; k++)
                        {
                            StyleSelectorPart part = sel.parts[k];
                            switch (part.type)
                            {
                            case StyleSelectorType.Class:
                                builder.Append(".");
                                break;

                            case StyleSelectorType.ID:
                                builder.Append("#");
                                break;

                            case StyleSelectorType.PseudoClass:
                            case StyleSelectorType.RecursivePseudoClass:
                                builder.Append(":");
                                break;

                            case StyleSelectorType.Wildcard: break;
                            }
                            builder.Append(part.value);
                        }
                    }

                    StyleProperty[] props    = rule.ruleMatcher.complexSelector.rule.properties;
                    bool            expanded = m_CurFoldout.Contains(i);
                    EditorGUILayout.BeginHorizontal();
                    bool foldout = EditorGUILayout.Foldout(m_CurFoldout.Contains(i), new GUIContent(builder.ToString()), true);
                    if (rule.displayPath != null && GUILayout.Button(rule.displayPath, EditorStyles.miniButton, GUILayout.MaxWidth(150)))
                    {
                        InternalEditorUtility.OpenFileAtLineExternal(rule.fullPath, rule.lineNumber);
                    }
                    EditorGUILayout.EndHorizontal();

                    if (expanded && !foldout)
                    {
                        m_CurFoldout.Remove(i);
                    }
                    else if (!expanded && foldout)
                    {
                        m_CurFoldout.Add(i);
                    }

                    if (foldout)
                    {
                        EditorGUI.indentLevel++;
                        for (int j = 0; j < props.Length; j++)
                        {
                            string s = rule.ruleMatcher.sheet.ReadAsString(props[j].values[0]);
                            EditorGUILayout.LabelField(new GUIContent(props[j].name), new GUIContent(s));
                        }

                        EditorGUI.indentLevel--;
                    }
                    i++;
                }
            }
        }
コード例 #3
0
        private void DrawMatchingRules()
        {
            if (UIElementsDebugger.s_MatchedRulesExtractor.selectedElementStylesheets != null && UIElementsDebugger.s_MatchedRulesExtractor.selectedElementStylesheets.Count > 0)
            {
                EditorGUILayout.LabelField(UIElementsDebugger.Styles.stylesheetsContent, UIElementsDebugger.Styles.KInspectorTitle, new GUILayoutOption[0]);
                foreach (string current in UIElementsDebugger.s_MatchedRulesExtractor.selectedElementStylesheets)
                {
                    if (GUILayout.Button(current, new GUILayoutOption[0]))
                    {
                        InternalEditorUtility.OpenFileAtLineExternal(current, 0);
                    }
                }
            }
            if (UIElementsDebugger.s_MatchedRulesExtractor.selectedElementRules != null && UIElementsDebugger.s_MatchedRulesExtractor.selectedElementRules.Count > 0)
            {
                EditorGUILayout.LabelField(UIElementsDebugger.Styles.selectorsContent, UIElementsDebugger.Styles.KInspectorTitle, new GUILayoutOption[0]);
                int num = 0;
                foreach (MatchedRulesExtractor.MatchedRule current2 in UIElementsDebugger.s_MatchedRulesExtractor.selectedElementRules)
                {
                    StringBuilder stringBuilder = new StringBuilder();
                    for (int i = 0; i < current2.ruleMatcher.complexSelector.selectors.Length; i++)
                    {
                        StyleSelector             styleSelector        = current2.ruleMatcher.complexSelector.selectors[i];
                        StyleSelectorRelationship previousRelationship = styleSelector.previousRelationship;
                        if (previousRelationship != StyleSelectorRelationship.Child)
                        {
                            if (previousRelationship == StyleSelectorRelationship.Descendent)
                            {
                                stringBuilder.Append(" ");
                            }
                        }
                        else
                        {
                            stringBuilder.Append(" > ");
                        }
                        for (int j = 0; j < styleSelector.parts.Length; j++)
                        {
                            StyleSelectorPart styleSelectorPart = styleSelector.parts[j];
                            switch (styleSelectorPart.type)
                            {
                            case StyleSelectorType.Class:
                                stringBuilder.Append(".");
                                break;

                            case StyleSelectorType.PseudoClass:
                            case StyleSelectorType.RecursivePseudoClass:
                                stringBuilder.Append(":");
                                break;

                            case StyleSelectorType.ID:
                                stringBuilder.Append("#");
                                break;
                            }
                            stringBuilder.Append(styleSelectorPart.value);
                        }
                    }
                    StyleProperty[] properties = current2.ruleMatcher.complexSelector.rule.properties;
                    bool            flag       = this.m_CurFoldout.Contains(num);
                    EditorGUILayout.BeginHorizontal(new GUILayoutOption[0]);
                    bool flag2 = EditorGUILayout.Foldout(this.m_CurFoldout.Contains(num), new GUIContent(stringBuilder.ToString()), true);
                    if (current2.displayPath != null && GUILayout.Button(current2.displayPath, EditorStyles.miniButton, new GUILayoutOption[]
                    {
                        GUILayout.MaxWidth(150f)
                    }))
                    {
                        InternalEditorUtility.OpenFileAtLineExternal(current2.fullPath, current2.lineNumber);
                    }
                    EditorGUILayout.EndHorizontal();
                    if (flag && !flag2)
                    {
                        this.m_CurFoldout.Remove(num);
                    }
                    else if (!flag && flag2)
                    {
                        this.m_CurFoldout.Add(num);
                    }
                    if (flag2)
                    {
                        EditorGUI.indentLevel++;
                        for (int k = 0; k < properties.Length; k++)
                        {
                            string text = current2.ruleMatcher.sheet.ReadAsString(properties[k].values[0]);
                            EditorGUILayout.LabelField(new GUIContent(properties[k].name), new GUIContent(text), new GUILayoutOption[0]);
                        }
                        EditorGUI.indentLevel--;
                    }
                    num++;
                }
            }
        }
コード例 #4
0
        public static StyleSelectorPart[] GetStateRuleSelectorParts(string baseSelectorStr, string id)
        {
            var baseSelector = baseSelectorStr[0] == '.' ? StyleSelectorPart.CreateClass(baseSelectorStr.Substring(1)) : StyleSelectorPart.CreateType(baseSelectorStr);

            switch (id)
            {
            case "active":
                return(new[]
                {
                    baseSelector,
                    StyleSelectorPart.CreatePseudoClass("hover"),
                    StyleSelectorPart.CreatePseudoClass("active")
                });

            case "focused":
                return(new[]
                {
                    baseSelector,
                    StyleSelectorPart.CreatePseudoClass("focus")
                });

            case "hover":
                return(new[]
                {
                    baseSelector,
                    StyleSelectorPart.CreatePseudoClass("hover")
                });

            case "onActive":
                return(new[]
                {
                    baseSelector,
                    StyleSelectorPart.CreatePseudoClass("hover"),
                    StyleSelectorPart.CreatePseudoClass("active"),
                    StyleSelectorPart.CreatePseudoClass("checked")
                });

            case "onFocused":
                return(new[]
                {
                    baseSelector,
                    StyleSelectorPart.CreatePseudoClass("hover"),
                    StyleSelectorPart.CreatePseudoClass("focus"),
                    StyleSelectorPart.CreatePseudoClass("checked")
                });

            case "onHover":
                return(new[]
                {
                    baseSelector,
                    StyleSelectorPart.CreatePseudoClass("hover"),
                    StyleSelectorPart.CreatePseudoClass("checked")
                });

            case "onNormal":
                return(new[]
                {
                    baseSelector,
                    StyleSelectorPart.CreatePseudoClass("checked")
                });

            default:
                throw new Exception("Unsupported GUIStyleStateId: " + id);
            }
        }
コード例 #5
0
 public static StyleSelectorPart CreateSelectorPart(string selectorStr)
 {
     return(selectorStr[0] == '.' ? StyleSelectorPart.CreateClass(selectorStr.Substring(1)) : StyleSelectorPart.CreateType(selectorStr));
 }