public BuilderInspectorInheritedStyles(BuilderInspector inspector, BuilderInspectorMatchingSelectors matchingSelectors)
        {
            m_Inspector         = inspector;
            m_Selection         = inspector.selection;
            m_PaneWindow        = inspector.paneWindow;
            m_MatchingSelectors = matchingSelectors;

            m_InheritedStylesSection   = m_Inspector.Q <PersistedFoldout>("inspector-inherited-styles-foldout");
            m_ClassListContainer       = m_Inspector.Q("class-list-container");
            m_MatchingSelectorsFoldout = m_Inspector.Q <PersistedFoldout>("matching-selectors-container");

            m_AddClassField           = m_Inspector.Q <TextField>("add-class-field");
            m_AddClassField.isDelayed = true;
            m_AddClassField.RegisterCallback <KeyUpEvent>(OnAddClassFieldChange);

            m_AddClassButton    = m_Inspector.Q <Button>("add-class-button");
            m_CreateClassButton = m_Inspector.Q <Button>("create-class-button");

            m_ClassPillTemplate = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>(
                BuilderConstants.UIBuilderPackagePath + "/BuilderClassPill.uxml");

            m_AddClassButton.clickable.clicked    += AddStyleClass;
            m_CreateClassButton.clickable.clicked += ExtractLocalStylesToNewClass;
        }
예제 #2
0
        VisualElement GeneratedMatchingSelectors()
        {
            m_MatchingSelectors.GetElementMatchers();
            if (m_MatchingSelectors.matchedRulesExtractor.selectedElementRules == null ||
                m_MatchingSelectors.matchedRulesExtractor.selectedElementRules.Count <= 0)
            {
                return(null);
            }

            var container = new VisualElement();

            int ruleIndex = 0;

            foreach (var rule in m_MatchingSelectors.matchedRulesExtractor.selectedElementRules)
            {
                var selectorStr = StyleSheetToUss.ToUssSelector(rule.matchRecord.complexSelector);

                StyleProperty[] props       = rule.matchRecord.complexSelector.rule.properties;
                var             ruleFoldout = new PersistedFoldout()
                {
                    value       = false,
                    text        = selectorStr,
                    viewDataKey = "builder-inspector-rule-foldout__" + ruleIndex
                };
                ruleIndex++;
                container.Add(ruleFoldout);

                if (props.Length == 0)
                {
                    var label = new Label("None");
                    label.AddToClassList(BuilderConstants.InspectorEmptyFoldoutLabelClassName);
                    ruleFoldout.Add(label);
                    continue;
                }

                for (int j = 0; j < props.Length; j++)
                {
                    string s = "";
                    for (int k = 0; k < props[j].values.Length; k++)
                    {
                        if (k > 0)
                        {
                            s += " ";
                        }

                        var str = rule.matchRecord.sheet.ReadAsString(props[j].values[k]);
                        s += str;
                    }

                    s = s.ToLower();
                    var textField = new TextField(props[j].name)
                    {
                        value = s
                    };
                    textField.isReadOnly = true;
                    ruleFoldout.Add(textField);
                }
            }

            return(container);
        }
예제 #3
0
        public BuilderInspectorLocalStyles(BuilderInspector inspector, BuilderInspectorStyleFields styleFields)
        {
            m_Inspector   = inspector;
            m_StyleFields = styleFields;

            m_StyleFields.updateFlexColumnGlobalState         = UpdateFlexColumnGlobalState;
            m_StyleFields.updateStyleCategoryFoldoutOverrides = UpdateStyleCategoryFoldoutOverrides;

            m_LocalStylesSection = m_Inspector.Q <PersistedFoldout>("inspector-local-styles-foldout");

            var styleCategories = m_LocalStylesSection.Query <PersistedFoldout>(
                className: "unity-builder-inspector__style-category-foldout").ToList();

            foreach (var styleCategory in styleCategories)
            {
                styleCategory.Q <VisualElement>(null, PersistedFoldout.headerUssClassName)
                .AddManipulator(new ContextualMenuManipulator(StyleCategoryContextualMenu));

                var categoryStyleFields = new List <BindableElement>();
                var styleRows           = styleCategory.Query <BuilderStyleRow>().ToList();
                foreach (var styleRow in styleRows)
                {
                    var bindingPath        = styleRow.bindingPath;
                    var currentStyleFields = styleRow.Query <BindableElement>().ToList();

#if UNITY_2019_2
                    if (styleRow.ClassListContains(BuilderConstants.Version_2019_3_OrNewer))
                    {
                        styleRow.AddToClassList(BuilderConstants.HiddenStyleClassName);
                        continue;
                    }
#else
                    if (styleRow.ClassListContains(BuilderConstants.Version_2019_2))
                    {
                        styleRow.AddToClassList(BuilderConstants.HiddenStyleClassName);
                        continue;
                    }
#endif

                    if (styleRow.ClassListContains("unity-builder-double-field-row"))
                    {
                        m_StyleFields.BindDoubleFieldRow(styleRow);
                    }

                    foreach (var styleField in currentStyleFields)
                    {
                        // Avoid fields within fields.
                        if (styleField.parent != styleRow)
                        {
                            continue;
                        }

                        if (styleField is FoldoutNumberField)
                        {
                            m_StyleFields.BindStyleField(styleRow, styleField as FoldoutNumberField);
                        }
                        else if (styleField is FoldoutColorField)
                        {
                            m_StyleFields.BindStyleField(styleRow, styleField as FoldoutColorField);
                        }
                        else if (!string.IsNullOrEmpty(styleField.bindingPath))
                        {
                            m_StyleFields.BindStyleField(styleRow, styleField.bindingPath, styleField);
                        }
                        else
                        {
                            BuilderStyleRow.ReAssignTooltipToChild(styleField);
                            m_StyleFields.BindStyleField(styleRow, bindingPath, styleField);
                        }

                        categoryStyleFields.Add(styleField);
                    }
                }
                m_StyleCategories.Add(styleCategory, categoryStyleFields);
            }
        }
        public BuilderInspectorLocalStyles(BuilderInspector inspector, BuilderInspectorStyleFields styleFields)
        {
            m_Inspector   = inspector;
            m_StyleFields = styleFields;

            m_StyleFields.updateFlexColumnGlobalState         = UpdateFlexColumnGlobalState;
            m_StyleFields.updateStyleCategoryFoldoutOverrides = UpdateStyleCategoryFoldoutOverrides;

            m_LocalStylesSection = m_Inspector.Q <PersistedFoldout>("inspector-local-styles-foldout");

            // We need to hide new Text Asset style property fields in any Unity version older than 2021.1.
#if !PACKAGE_TEXT_CORE || UNITY_2019_4 || UNITY_2020_1 || UNITY_2020_2 || UNITY_2020_3
            m_LocalStylesSection.Query(className: "unity-builder-font-asset-property-container").ForEach(e => e.style.display = DisplayStyle.None);
#else
            m_LocalStylesSection.Query(className: "unity-builder-no-font-asset-property-container").ForEach(e => e.style.display = DisplayStyle.None);
#endif

            var styleCategories = m_LocalStylesSection.Query <PersistedFoldout>(
                className: "unity-builder-inspector__style-category-foldout").ToList();

            foreach (var styleCategory in styleCategories)
            {
                styleCategory.Q <VisualElement>(null, PersistedFoldout.headerUssClassName)
                .AddManipulator(new ContextualMenuManipulator(StyleCategoryContextualMenu));

                var categoryStyleFields = new List <VisualElement>();
                var styleRows           = styleCategory.Query <BuilderStyleRow>().ToList();
                foreach (var styleRow in styleRows)
                {
                    var bindingPath        = styleRow.bindingPath;
                    var currentStyleFields = styleRow.Query <BindableElement>().ToList();

                    if (styleRow.ClassListContains("unity-builder-double-field-row"))
                    {
                        m_StyleFields.BindDoubleFieldRow(styleRow);
                    }

                    foreach (var styleField in currentStyleFields)
                    {
                        // Avoid fields within fields.
                        if (styleField.parent != styleRow)
                        {
                            continue;
                        }

                        if (styleField is FoldoutNumberField)
                        {
                            m_StyleFields.BindStyleField(styleRow, styleField as FoldoutNumberField);
                        }
                        else if (styleField is FoldoutColorField)
                        {
                            m_StyleFields.BindStyleField(styleRow, styleField as FoldoutColorField);
                        }
                        else if (!string.IsNullOrEmpty(styleField.bindingPath))
                        {
                            m_StyleFields.BindStyleField(styleRow, styleField.bindingPath, styleField);
                        }
                        else
                        {
                            BuilderStyleRow.ReAssignTooltipToChild(styleField);
                            m_StyleFields.BindStyleField(styleRow, bindingPath, styleField);
                        }

                        categoryStyleFields.Add(styleField);
                    }
                }
                m_StyleCategories.Add(styleCategory, categoryStyleFields);
            }
        }
예제 #5
0
        public BuilderInspectorLocalStyles(BuilderInspector inspector, BuilderInspectorStyleFields styleFields)
        {
            m_Inspector   = inspector;
            m_StyleFields = styleFields;

            m_StyleFields.updateFlexColumnGlobalState         = UpdateFlexColumnGlobalState;
            m_StyleFields.updateStyleCategoryFoldoutOverrides = UpdateStyleCategoryFoldoutOverrides;

            m_LocalStylesSection = m_Inspector.Q <PersistedFoldout>("inspector-local-styles-foldout");

            var styleCategories = m_LocalStylesSection.Query <PersistedFoldout>(
                className: "unity-builder-inspector__style-category-foldout").ToList();

            foreach (var styleCategory in styleCategories)
            {
                styleCategory.Q <VisualElement>(null, PersistedFoldout.headerUssClassName)
                .AddManipulator(new ContextualMenuManipulator(StyleCategoryContextualMenu));

                var categoryStyleFields = new List <VisualElement>();
                var styleRows           = styleCategory.Query <BuilderStyleRow>().ToList();
                foreach (var styleRow in styleRows)
                {
                    var bindingPath        = styleRow.bindingPath;
                    var currentStyleFields = styleRow.Query <BindableElement>().ToList();

                    if (styleRow.ClassListContains("unity-builder-double-field-row"))
                    {
                        m_StyleFields.BindDoubleFieldRow(styleRow);
                    }

                    foreach (var styleField in currentStyleFields)
                    {
                        // Avoid fields within fields.
                        if (styleField.parent != styleRow)
                        {
                            continue;
                        }

                        if (styleField is FoldoutNumberField)
                        {
                            m_StyleFields.BindStyleField(styleRow, styleField as FoldoutNumberField);
                        }
                        else if (styleField is FoldoutColorField)
                        {
                            m_StyleFields.BindStyleField(styleRow, styleField as FoldoutColorField);
                        }
                        else if (styleField is TransitionsListView transitionsListView)
                        {
                            GenerateTransitionPropertiesContent();
                            m_StyleFields.BindStyleField(styleRow, transitionsListView);
                        }
                        else if (!string.IsNullOrEmpty(styleField.bindingPath))
                        {
                            m_StyleFields.BindStyleField(styleRow, styleField.bindingPath, styleField);
                        }
                        else
                        {
                            m_StyleFields.BindStyleField(styleRow, bindingPath, styleField);
                        }

                        categoryStyleFields.Add(styleField);
                    }
                }
                m_StyleCategories.Add(styleCategory, categoryStyleFields);
            }
        }