public void BindStyleField(BuilderStyleRow styleRow, FoldoutColorField foldoutElement) { var colorFields = foldoutElement.Query <ColorField>().ToList(); foreach (var field in colorFields) { field.SetProperty(BuilderConstants.FoldoutFieldPropertyName, foldoutElement); field.RegisterValueChangedCallback((evt) => { var row = field.GetProperty(BuilderConstants.InspectorLinkedStyleRowVEPropertyName) as BuilderStyleRow; if (row != null && !string.IsNullOrEmpty(row.bindingPath)) { foldoutElement.UpdateFromChildField(row.bindingPath, field.value); } foldoutElement.header.AddToClassList(BuilderConstants.InspectorLocalStyleOverrideClassName); }); BuilderStyleRow.ReAssignTooltipToChild(field); } foldoutElement.header.SetProperty(BuilderConstants.FoldoutFieldPropertyName, foldoutElement); foldoutElement.headerInputField.RegisterValueChangedCallback(FoldoutColorFieldOnValueChange); foldoutElement.headerInputField.AddManipulator( new ContextualMenuManipulator((e) => { e.target = foldoutElement.header; BuildStyleFieldContextualMenu(e); })); foldoutElement.header.AddManipulator( new ContextualMenuManipulator(BuildStyleFieldContextualMenu)); }
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); } }
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); } }