public BuilderInspectorStyleSheet(BuilderInspector inspector)
        {
            m_Inspector = inspector;
            m_Selection = inspector.selection;

            m_StyleSheetSection        = m_Inspector.Q("shared-styles-controls");
            m_NewSelectorNameNameField = m_Inspector.Q <TextField>("add-new-selector-field");
            m_AddNewSelectorButton     = m_Inspector.Q <Button>("add-new-selector-button");

            m_AddNewSelectorButton.clickable.clicked += CreateNewSelector;
            m_NewSelectorNameNameField.RegisterValueChangedCallback(OnCreateNewSelector);
            m_NewSelectorNameNameField.isDelayed = true;
        }
Exemplo n.º 2
0
        public BuilderInspectorAttributes(BuilderInspector inspector)
        {
            m_Inspector = inspector;
            m_Selection = inspector.selection;

            m_AttributesSection = m_Inspector.Q <PersistedFoldout>("inspector-attributes-foldout");
        }
Exemplo n.º 3
0
        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_AddClassValidationMessageContainer = m_Inspector.Q("add-class-validation-message-container");
            m_AddClassValidationMessageContainer.Add(new IMGUIContainer(DrawAddClassValidationMessage));
            m_AddClassValidationMessageContainer.style.display = DisplayStyle.None;

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

            m_AddClassButton.clickable.clicked    += AddStyleClass;
            m_CreateClassButton.clickable.clicked += ExtractLocalStylesToNewClass;

            m_AddClassValidationRegex = new Regex(@"^[a-zA-Z0-9\-_]+$");
        }
        public BuilderInspectorSelector(BuilderInspector inspector)
        {
            m_Inspector = inspector;
            m_Selection = inspector.selection;

            m_StyleSelectorSection             = m_Inspector.Q <PersistedFoldout>("shared-style-selector-controls");
            m_StyleSelectorNameField           = m_StyleSelectorSection.Q <TextField>("rename-selector-field");
            m_StyleSelectorNameField.isDelayed = true;
            m_StyleSelectorNameField.RegisterValueChangedCallback(OnStyleSelectorNameChange);
        }
        public BuilderInspectorHeader(BuilderInspector inspector)
        {
            m_Inspector       = inspector;
            m_Selection       = inspector.selection;
            m_Header          = m_Inspector.Q <VisualElement>("header-container");
            m_StatusIndicator = m_Header.Q <FieldStatusIndicator>("header-field-status-indicator");
            m_StatusIndicator.populateMenuItems = (menu) =>
            {
                BuildNameFieldContextualMenu(menu, m_TextField);
            };

            m_InnerHeader = m_Inspector.Q <VisualElement>("header-container-minor");
            m_Icon        = m_Inspector.Q <VisualElement>("header-icon");

            m_Pill = m_Inspector.Q <Label>("header-selected-pill");
            m_Pill.AddToClassList("unity-builder-tag-pill");

            m_TextField             = m_Inspector.Q <TextField>("header-selected-text-field");
            m_TextField.isDelayed   = true;
            m_TextField.tooltip     = "name";
            m_TextField.bindingPath = "name";

            m_EditorWarningHelpBox      = m_Inspector.Q <UnityEngine.UIElements.HelpBox>("header-editor-warning-help-box");
            m_EditorWarningHelpBox.text = BuilderConstants.HeaderSectionHelpBoxMessage;
            m_ErrorIcon = m_Inspector.Q <VisualElement>("header-error-icon");

            // Warning must be hidden at first
            m_ErrorIcon.style.backgroundImage = EditorGUIUtility.LoadIcon("console.erroricon");
            AdjustBottomPadding(false);

            // Store callbacks to reduce delegate allocations
            m_ElementNameChangeCallback    = new EventCallback <ChangeEvent <string> >(OnNameAttributeChange);
            m_SelectorNameChangeCallback   = new EventCallback <ChangeEvent <string> >(OnStyleSelectorNameChange);
            m_SelectorEnterKeyDownCallback = new EventCallback <KeyDownEvent>(OnEnterStyleSelectorNameChange);

            m_TextField.RegisterValueChangedCallback(m_ElementNameChangeCallback);
            m_RightClickManipulator = new ContextualMenuManipulator(BuildNameFieldContextualMenu);
        }
Exemplo n.º 6
0
        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 = BuilderPackageUtilities.LoadAssetAtPath <VisualTreeAsset>(
                BuilderConstants.UIBuilderPackagePath + "/BuilderClassPill.uxml");

            m_AddClassButton.clickable.clicked    += AddStyleClass;
            m_CreateClassButton.clickable.clicked += ExtractLocalStylesToNewClass;
        }
        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 BuilderInspectorCanvas(BuilderInspector inspector)
        {
            m_Inspector       = inspector;
            m_Document        = inspector.document;
            m_CanvasInspector = m_Inspector.Q(ContainerName);

            var builderWindow = inspector.paneWindow as Builder;

            if (builderWindow == null)
            {
                return;
            }

            m_Canvas = builderWindow.canvas;

            m_CameraModeEnabled = false;

            // Size Fields
            m_CanvasWidth = root.Q <IntegerField>("canvas-width");
            m_CanvasWidth.RegisterValueChangedCallback(OnWidthChange);
            m_CanvasHeight = root.Q <IntegerField>("canvas-height");
            m_CanvasHeight.RegisterValueChangedCallback(OnHeightChange);
            m_Canvas.RegisterCallback <GeometryChangedEvent>(OnCanvasSizeChange);

            // This allows user to temporarily type values below the minimum canvas size
            SetDelayOnSizeFieldsEnabled(true);

            // To update the canvas size as user mouse drags the width or height labels
            DisableDelayOnActiveLabelMouseDraggers();

            m_MatchGameViewToggle = root.Q <Toggle>("match-game-view");
            m_MatchGameViewToggle.RegisterValueChangedCallback(OnMatchGameViewModeChanged);
            m_MatchGameViewHelpBox = root.Q <HelpBox>("match-game-view-hint");

            // Background Opacity
            m_ColorOpacityField = root.Q <PercentSlider>("background-color-opacity-field");
            m_ColorOpacityField.RegisterValueChangedCallback(e =>
            {
                settings.ColorModeBackgroundOpacity = e.newValue;
                OnBackgroundOpacityChange(e.newValue);
            });

            m_ImageOpacityField = root.Q <PercentSlider>("background-image-opacity-field");
            m_ImageOpacityField.RegisterValueChangedCallback(e =>
            {
                settings.ImageModeCanvasBackgroundOpacity = e.newValue;
                OnBackgroundOpacityChange(e.newValue);
            });

            m_CameraOpacityField = root.Q <PercentSlider>("background-camera-opacity-field");
            m_CameraOpacityField.RegisterValueChangedCallback(e =>
            {
                settings.CameraModeCanvasBackgroundOpacity = e.newValue;
                OnBackgroundOpacityChange(e.newValue);
            });

            // Setup Background State
            m_BackgroundOptionsFoldout = root.Q <FoldoutWithCheckbox>("canvas-background-foldout");
            m_BackgroundOptionsFoldout.RegisterCheckboxValueChangedCallback(e =>
            {
                settings.EnableCanvasBackground = e.newValue;
                PostSettingsChange();
                ApplyBackgroundOptions();
            });

            // Setup Background Mode
            var backgroundModeType   = typeof(BuilderCanvasBackgroundMode);
            var backgroundModeValues = Enum.GetValues(backgroundModeType)
                                       .OfType <BuilderCanvasBackgroundMode>().Select((v) => v.ToString()).ToList();

            m_BackgroundMode          = root.Q <ToggleButtonStrip>("background-mode-field");
            m_BackgroundMode.enumType = backgroundModeType;
            m_BackgroundMode.choices  = backgroundModeValues;
            m_BackgroundMode.RegisterValueChangedCallback(OnBackgroundModeChange);

            // Color field.
            m_ColorField = root.Q <ColorField>("background-color-field");
            m_ColorField.RegisterValueChangedCallback(OnBackgroundColorChange);

            // Set Image field.
            m_ImageField            = root.Q <ObjectField>("background-image-field");
            m_ImageField.objectType = typeof(Texture2D);
            m_ImageField.RegisterValueChangedCallback(OnBackgroundImageChange);
            m_ImageScaleModeField          = root.Q <ToggleButtonStrip>("background-image-scale-mode-field");
            m_ImageScaleModeField.enumType = typeof(ScaleMode);
            var backgroundScaleModeValues = Enum.GetValues(typeof(ScaleMode))
                                            .OfType <ScaleMode>().Select((v) => BuilderNameUtilities.ConvertCamelToDash(v.ToString())).ToList();

            m_ImageScaleModeField.choices = backgroundScaleModeValues;
            m_ImageScaleModeField.RegisterValueChangedCallback(OnBackgroundImageScaleModeChange);
            m_FitCanvasToImageButton = root.Q <Button>("background-image-fit-canvas-button");
            m_FitCanvasToImageButton.clickable.clicked += FitCanvasToImage;

            // Set Camera field.
            m_CameraField            = root.Q <ObjectField>("background-camera-field");
            m_CameraField.objectType = typeof(Camera);
            m_CameraField.RegisterValueChangedCallback(OnBackgroundCameraChange);

#if !UNITY_2019_4
            SetupEditorExtensionsModeToggle();
#else
            RemoveDocumentSettings();
#endif

            // Control Containers
            m_BackgroundColorModeControls  = root.Q("canvas-background-color-mode-controls");
            m_BackgroundImageModeControls  = root.Q("canvas-background-image-mode-controls");
            m_BackgroundCameraModeControls = root.Q("canvas-background-camera-mode-controls");

            EditorApplication.playModeStateChanged += PlayModeStateChange;
        }
Exemplo n.º 9
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 BuilderInspectorCanvas(BuilderInspector inspector)
        {
            m_Inspector       = inspector;
            m_Document        = inspector.document;
            m_CanvasInspector = m_Inspector.Q("canvas-inspector");

            var builderWindow = inspector.paneWindow as Builder;

            if (builderWindow == null)
            {
                return;
            }

            m_Canvas = builderWindow.canvas;

            m_CameraModeEnabled = false;

            // Size Fields
            m_CanvasWidth           = root.Q <IntegerField>("canvas-width");
            m_CanvasWidth.isDelayed = true;
            m_CanvasWidth.RegisterValueChangedCallback(OnWidthChange);
            m_CanvasHeight           = root.Q <IntegerField>("canvas-height");
            m_CanvasHeight.isDelayed = true;
            m_CanvasHeight.RegisterValueChangedCallback(OnHeightChange);
            m_Canvas.RegisterCallback <GeometryChangedEvent>(OnCanvasSizeChange);

            // Background Opacity
            m_OpacityField = root.Q <PercentSlider>("background-opacity-field");
            m_OpacityField.RegisterValueChangedCallback(OnBackgroundOpacityChange);

            // Setup Background Mode
            var backgroundModeType   = typeof(BuilderCanvasBackgroundMode);
            var backgroundModeValues = Enum.GetValues(backgroundModeType)
                                       .OfType <BuilderCanvasBackgroundMode>().Select((v) => v.ToString()).ToList();
            var backgroundModeNames = Enum.GetNames(backgroundModeType);

            m_BackgroundMode          = root.Q <ToggleButtonStrip>("background-mode-field");
            m_BackgroundMode.enumType = backgroundModeType;
            m_BackgroundMode.labels   = backgroundModeNames;
            m_BackgroundMode.choices  = backgroundModeValues;
            m_BackgroundMode.RegisterValueChangedCallback(OnBackgroundModeChange);

            // Color field.
            m_ColorField = root.Q <ColorField>("background-color-field");
            m_ColorField.RegisterValueChangedCallback(OnBackgroundColorChange);

            // Set Image field.
            m_ImageField            = root.Q <ObjectField>("background-image-field");
            m_ImageField.objectType = typeof(Texture2D);
            m_ImageField.RegisterValueChangedCallback(OnBackgroundImageChange);
            m_ImageScaleModeField          = root.Q <ToggleButtonStrip>("background-image-scale-mode-field");
            m_ImageScaleModeField.enumType = typeof(ScaleMode);
            var backgroundScaleModeValues = Enum.GetValues(typeof(ScaleMode))
                                            .OfType <ScaleMode>().Select((v) => BuilderNameUtilities.ConvertCamelToDash(v.ToString())).ToList();

            m_ImageScaleModeField.choices = backgroundScaleModeValues;
            m_ImageScaleModeField.RegisterValueChangedCallback(OnBackgroundImageScaleModeChange);
            m_FitCanvasToImageButton = root.Q <Button>("background-image-fit-canvas-button");
            m_FitCanvasToImageButton.clickable.clicked += FitCanvasToImage;

            // Set Camera field.
            m_CameraField            = root.Q <ObjectField>("background-camera-field");
            m_CameraField.objectType = typeof(Camera);
            m_CameraField.RegisterValueChangedCallback(OnBackgroundCameraChange);

            // Control Containers
            m_BackgroundColorModeControls  = root.Q("canvas-background-color-mode-controls");
            m_BackgroundImageModeControls  = root.Q("canvas-background-image-mode-controls");
            m_BackgroundCameraModeControls = root.Q("canvas-background-camera-mode-controls");

            EditorApplication.playModeStateChanged += PlayModeStateChange;
        }
Exemplo n.º 11
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);
            }
        }