public void Initialize(BaseGraphView graphView, Group block)
        {
            group = block;
            owner = graphView;

            title = block.title;
            SetPosition(block.position);

            this.AddManipulator(new ContextualMenuManipulator(BuildContextualMenu));

            headerContainer.Q <TextField>().RegisterCallback <ChangeEvent <string> >(TitleChangedCallback);
            titleLabel = headerContainer.Q <Label>();

            colorField = new ColorField {
                value = group.color, name = "headerColorPicker"
            };
            colorField.RegisterValueChangedCallback(e =>
            {
                UpdateGroupColor(e.newValue);
            });
            UpdateGroupColor(group.color);

            headerContainer.Add(colorField);

            InitializeInnerNodes();
        }
Esempio n. 2
0
        void OnEnable()
        {
            rootVisualElement.StyleBorderWidth(1);
            Color c = new Color32(58, 121, 187, 255);

            rootVisualElement.StyleBorderColor(c);

            // EditorHelpBox helpBox = new EditorHelpBox("This feature currently in preview state", MessageType.Info);
            // rootVisualElement.Add(helpBox);

            hierarchyLocalData         = HierarchyEditor.Instance.GetHierarchyLocalData(Selection.activeGameObject.scene);
            gameObject                 = Selection.activeGameObject;
            Selection.activeGameObject = null;

            CustomRowItem customRowItem = null;

            if (hierarchyLocalData.TryGetCustomRowData(gameObject, out customRowItem) == false)
            {
                customRowItem = hierarchyLocalData.CreateCustomRowItemFor(gameObject);
            }
            DlfU.UIElements.Toggle useBackground = new DlfU.UIElements.Toggle("Use Background",
                                                                              customRowItem.useBackground,
                                                                              Justify.FlexStart,
                                                                              (evt) =>
            {
                customRowItem.useBackground = evt.newValue;
                EditorApplication.RepaintHierarchyWindow();
            });
            rootVisualElement.Add(useBackground);

            EnumField backgroundStyle = new EnumField(customRowItem.backgroundStyle);

            backgroundStyle.label = "Background Style";
            backgroundStyle.RegisterValueChangedCallback((evt) =>
            {
                customRowItem.backgroundStyle = (CustomRowItem.BackgroundStyle)evt.newValue;
                EditorApplication.RepaintHierarchyWindow();
            });
            rootVisualElement.Add(backgroundStyle);

            EnumField backgroundMode = new EnumField(customRowItem.backgroundMode);

            backgroundMode.label = "Background Mode";
            backgroundMode.RegisterValueChangedCallback((evt) =>
            {
                customRowItem.backgroundMode = (CustomRowItem.BackgroundMode)evt.newValue;
                EditorApplication.RepaintHierarchyWindow();
            });
            rootVisualElement.Add(backgroundMode);

            ColorField backgroundColor = new ColorField("Background Color");

            backgroundColor.value = customRowItem.backgroundColor;
            backgroundColor.RegisterValueChangedCallback((evt) =>
            {
                customRowItem.backgroundColor = evt.newValue;
                EditorApplication.RepaintHierarchyWindow();
            });
            rootVisualElement.Add(backgroundColor);
        }
        void BuildColorPropertyField(ColorShaderProperty property)
        {
            var colorField = new ColorField {
                value = property.value, showEyeDropper = false, hdr = property.colorMode == ColorMode.HDR
            };

            colorField.RegisterValueChangedCallback(evt =>
            {
                graph.owner.RegisterCompleteObjectUndo("Change property value");
                property.value = evt.newValue;
                DirtyNodes();
            });
            AddRow("Default", colorField);

            if (!graph.isSubGraph)
            {
                var colorModeField = new EnumField((Enum)property.colorMode);
                colorModeField.RegisterValueChangedCallback(evt =>
                {
                    graph.owner.RegisterCompleteObjectUndo("Change Color Mode");
                    if (property.colorMode == (ColorMode)evt.newValue)
                    {
                        return;
                    }
                    property.colorMode = (ColorMode)evt.newValue;
                    colorField.hdr     = property.colorMode == ColorMode.HDR;
                    colorField.MarkDirtyRepaint();
                    DirtyNodes();
                });
                AddRow("Mode", colorModeField);
            }
        }
Esempio n. 4
0
        void OnEnable()
        {
            var refColorField = new ColorField("Reference");

            refColorField.RegisterValueChangedCallback((evt =>
            {
                m_RefColor = evt.newValue;
                UpdateDistancesDisplay();
            }));
            refColorField.value = m_RefColor;
            rootVisualElement.Add(refColorField);

            var testColorField = new ColorField("Test");

            testColorField.RegisterValueChangedCallback(evt =>
            {
                m_TestColor = evt.newValue;
                UpdateDistancesDisplay();
            });
            testColorField.value = m_TestColor;
            rootVisualElement.Add(testColorField);

            AddDistanceFloatField("rgb", "RGB Distance", rootVisualElement);
            AddDistanceFloatField("cie", "CIE Distance", rootVisualElement);
            AddDistanceFloatField("yuv", "YUV Distance", rootVisualElement);
            AddDistanceFloatField("similarity", "Weighted Similarity", rootVisualElement);

            UpdateDistancesDisplay();
        }
Esempio n. 5
0
        // -----------------------------------------------------------------------------------------

        public void Generate_BlackBoard_Error_Color_Field()
        {
            var color = new ColorProperty();

            color.PropertyName  = _TranzmitGraphView.ErrorColor.PropertyName;
            color.PropertyValue = _TranzmitGraphView.ErrorColor.PropertyValue;

            var visualElement   = new VisualElement();
            var blackboardField = new BlackboardField {
                text = color.PropertyName, typeText = ""
            };

            visualElement.Add(blackboardField);

            var field = new ColorField("Value:");

            field.value = color.PropertyValue;

            field.RegisterValueChangedCallback(ChangeEvent =>
            {
                _TranzmitGraphView.ErrorColor.PropertyValue = field.value;
                _TranzmitGraphView.UpdateErrorColorsOnGraphElements();
            });

            var blackBoardValueRow = new BlackboardRow(blackboardField, field);

            visualElement.Add(blackBoardValueRow);

            _TranzmitGraphView.Blackboard.Add(visualElement);
        }
Esempio n. 6
0
        public ColorControlView(string label, ColorMode colorMode, AbstractMaterialNode node, PropertyInfo propertyInfo)
        {
            m_Node         = node;
            m_PropertyInfo = propertyInfo;
            styleSheets.Add(Resources.Load <StyleSheet>("Styles/Controls/ColorControlView"));
            if (propertyInfo.PropertyType != typeof(Color))
            {
                throw new ArgumentException("Property must be of type Color.", "propertyInfo");
            }
            label = label ?? ObjectNames.NicifyVariableName(propertyInfo.Name);

            m_Color = (Color)m_PropertyInfo.GetValue(m_Node, null);

            if (!string.IsNullOrEmpty(label))
            {
                Add(new Label(label));
            }

            m_ColorField = new ColorField {
                value = m_Color.color, hdr = m_Color.mode == ColorMode.HDR, showEyeDropper = false
            };
            m_ColorField.RegisterValueChangedCallback(OnChange);
            Add(m_ColorField);

            VisualElement enumPanel = new VisualElement {
                name = "enumPanel"
            };

            enumPanel.Add(new Label("Mode"));
            var enumField = new EnumField(m_Color.mode);

            enumField.RegisterValueChangedCallback(OnModeChanged);
            enumPanel.Add(enumField);
            Add(enumPanel);
        }
Esempio n. 7
0
        public static VisualElement GetElementOfColorField(Color startValue, string fieldName, Action <object> setValue, Action <object> getValue)
        {
            ColorField field = new ColorField(fieldName);

            field.SetValueWithoutNotify(startValue);
            field.RegisterValueChangedCallback(s => setValue.Invoke(s.newValue));
            getValue += o => field.SetValueWithoutNotify((Color)o);
            return(field);
        }
Esempio n. 8
0
        public VisualElement Build(InspectorDataProxy <Color> proxy)
        {
            var c = proxy.Data;

            m_Field = new ColorField(proxy.Name);
            m_Field.AddToClassList(proxy.Name);
            m_Field.RegisterValueChangedCallback(evt => ColorChanged(proxy, evt));
            return(m_Field);
        }
        public static void RenderColorProperty(VisualElement container, string name, object value,
                                               Action <object> setter)
        {
            var field = new ColorField(name);

            field.SetValueWithoutNotify((Color)value);
            field.MarkDirtyRepaint();
            field.RegisterValueChangedCallback(evt => setter(evt.newValue));
            container.Add(field);
        }
Esempio n. 10
0
    private void DrawPalette()
    {
        var palette = m_Root.Q <VisualElement>(name: "palette");

        palette.Clear();
        var paletteSO = new SerializedObject(pixelAsset.Palette);
        var picker    = new ObjectField();

        picker.objectType = typeof(Palette);
        picker.BindProperty(paletteSO);
        // palette.Add(new IMGUIContainer(PaletteDrawOnGUI));
        palette.style.backgroundColor = Color.black;
        var colorsProp = paletteSO.FindProperty("Colors");

        for (int i = 0; i < colorsProp.arraySize; i++)
        {
            if (i == paletteIndex)
            {
                var entry = new ColorField();
                entry.pickingMode = PickingMode.Position;
                entry.BindProperty(colorsProp.GetArrayElementAtIndex(i));
                entry.showEyeDropper               = false;
                entry.showAlpha                    = false;
                entry.style.width                  = entry.style.height = 18;
                entry.style.marginLeft             = entry.style.marginRight = 0;
                entry.style.marginTop              = entry.style.marginBottom = 0;
                entry.style.borderColor            = Color.white;
                entry.style.borderLeftWidth        = entry.style.borderRightWidth = 1;
                entry.style.borderTopWidth         = entry.style.borderBottomWidth = 1;
                entry.style.borderBottomLeftRadius = entry.style.borderBottomRightRadius = 2;
                entry.style.borderTopLeftRadius    = entry.style.borderTopRightRadius = 2;
                entry.RegisterValueChangedCallback(OnPaletteEdit);
                palette.Add(entry);
            }
            else
            {
                var index = i;
                var entry = new Button(() =>
                {
                    paletteIndex = index;
                    var colors   = palette.Query <VisualElement>();
                    colors.ForEach(c => palette.Remove(c));
                    DrawPalette();
                });
                entry.style.backgroundImage = EditorGUIUtility.whiteTexture;
                entry.style.unityBackgroundImageTintColor = (Color)pixelAsset.Palette.Colors[i];
                entry.style.width      = entry.style.height = 16;
                entry.style.marginLeft = entry.style.marginRight = 1;
                entry.style.marginTop  = entry.style.marginBottom = 1;
                palette.Add(entry);
            }
        }
        DrawFrames();
        // palette.style.height = (pixelAsset.Palette.Colors.Length / 4) * 18;
    }
        public ColorRGBASlotControlView(ColorRGBAMaterialSlot slot)
        {
            styleSheets.Add(Resources.Load <StyleSheet>("Styles/Controls/ColorRGBASlotControlView"));
            m_Slot = slot;
            var colorField = new ColorField {
                value = slot.value, showEyeDropper = false
            };

            colorField.RegisterValueChangedCallback(OnValueChanged);
            Add(colorField);
        }
Esempio n. 12
0
        void Init()
        {
            ColorField field = new ColorField()
            {
                value = config.value != null ? (Color)config.value : new Color(),
            };

            field.RegisterValueChangedCallback((e) => {
                config.OnValueChanged(e.newValue);
                MarkDirtyRepaint();
            });
            Add(field);
        }
Esempio n. 13
0
        public FoldoutColorField()
        {
            m_ColorField      = new ColorField();
            m_ColorField.name = "field";
            m_ColorField.AddToClassList(k_FieldClassName);
            m_ColorField.RegisterValueChangedCallback((e) => m_MixedValueLine.style.display = DisplayStyle.None);
            header.hierarchy.Add(m_ColorField);

            m_MixedValueLine      = new VisualElement();
            m_MixedValueLine.name = "mixed-value-line";
            m_MixedValueLine.AddToClassList(k_MixedValueLineClassName);
            m_ColorField.Q <IMGUIContainer>().hierarchy.Add(m_MixedValueLine);
        }
        public ColorRGBSlotControlView(ColorRGBMaterialSlot slot)
        {
            styleSheets.Add(Resources.Load <StyleSheet>("Styles/Controls/ColorRGBSlotControlView"));
            m_Slot = slot;
            var colorField = new ColorField
            {
                value          = new Color(slot.value.x, slot.value.y, slot.value.z, 0),
                showEyeDropper = false, showAlpha = false, hdr = (slot.colorMode == ColorMode.HDR)
            };

            colorField.RegisterValueChangedCallback(OnValueChanged);
            Add(colorField);
        }
Esempio n. 15
0
        public ColorField AddColorField(Color value = new Color(), bool alternate = false, bool secondAlternate = false, bool thirdAlternate = false)
        {
            ColorField el = new ColorField();

            el.value = value;
            el.AddToClassList("list-item-input");
            el.AddToClassList("list-item-color-input");
            AddAlternates(el, alternate, secondAlternate, thirdAlternate);
            el.RegisterValueChangedCallback(e => {
                eventManager.Raise <ListItemInputChange>(new ListItemInputChange(el));
            });
            this.Add(el);
            return(el);
        }
Esempio n. 16
0
        public override void OnActivate(string searchContext, VisualElement root)
        {
            var padRect = new VisualElement();
            int padding = 10;

            padRect.style.paddingBottom = padding;
            padRect.style.paddingLeft   = padding;
            padRect.style.paddingRight  = padding;
            padRect.style.paddingTop    = padding - 5;
            root.Add(padRect);

            var title = new Label("Notch Solution");

            title.style.fontSize = 15;
            title.style.unityFontStyleAndWeight = FontStyle.Bold;
            padRect.Add(title);

            var repo = new Label("https://github.com/5argon/NotchSolution");

            repo.style.paddingBottom           = 15;
            repo.style.unityFontStyleAndWeight = FontStyle.Bold;
            repo.RegisterCallback((MouseDownEvent ev) =>
            {
                System.Diagnostics.Process.Start("https://github.com/5argon/NotchSolution");
            });
            padRect.Add(repo);

            var devicesPath = new TextField("Device Directory");

            devicesPath.SetEnabled(false);
            devicesPath.value = NotchSimulatorUtility.DevicesFolder;
            padRect.Add(devicesPath);

            var colorField = new ColorField("Prefab mode overlay color");

            colorField.value = Settings.Instance.PrefabModeOverlayColor;
            colorField.RegisterValueChangedCallback(ev =>
            {
                var settings = Settings.Instance;
                settings.PrefabModeOverlayColor = ev.newValue;
                settings.Save();
                NotchSimulator.UpdateAllMockups();
                NotchSimulator.UpdateSimulatorTargets();
            });
            padRect.Add(colorField);
        }
        protected override void InitExtended()
        {
            colorField = this.Q <ColorField>("label-color-value");

            colorField.RegisterValueChangedCallback((cEvent) =>
            {
                var index = ((SemanticSegmentationLabelConfigEditor)m_LabelConfigEditor).IndexOfGivenColorInSerializedLabelsArray(cEvent.newValue);

                if (index != -1 && index != indexInList)
                {
                    //The listview recycles child visual elements and that causes the RegisterValueChangedCallback event to be called when scrolling.
                    //Therefore, we need to make sure we are not in this code block just because of scrolling, but because the user is actively changing one of the labels.
                    //The index check is for this purpose.

                    Debug.LogWarning("A label with the chosen color " + cEvent.newValue + " has already been added to this label configuration.");
                }
            });
        }
Esempio n. 18
0
        public override VisualElement CreatePropertyGUI(SerializedProperty property)
        {
            var name     = GetNameProperty(property);
            var settings = GetSettingsProperty(property);
            var val      = GetValProperty(property);
            var mode     = (ColorParameter.ColorMode)settings.FindPropertyRelative(nameof(ColorParameter.ColorSettings.mode)).intValue;

            var colorField = new ColorField(name.stringValue)
            {
                value = val.colorValue, hdr = mode == ColorParameter.ColorMode.HDR
            };

            colorField.RegisterValueChangedCallback(e => {
                val.colorValue = e.newValue;
                ApplyModifiedProperties(property);
            });
            return(colorField);
        }
Esempio n. 19
0
        public override void Enable()
        {
            base.Enable();
            colorNode = nodeTarget as ColorNode;

            var colorField = new ColorField()
            {
                label = "Color",
                value = colorNode.color
            };

            colorField.RegisterValueChangedCallback(e => {
                owner.RegisterCompleteObjectUndo("Updated Color " + e.newValue);
                NotifyNodeChanged();
                colorNode.color = e.newValue;
            });

            controlsContainer.Add(colorField);
        }
Esempio n. 20
0
        private void OnFetchCallbackFinish()
        {
            //todo -- unsubscribe
            ruleConfig?.SetEnabled(enabledToggle.value);
            enabledToggle?.UnregisterValueChangedCallback(onEnableToggled);
            enabledToggle?.RegisterValueChangedCallback(onEnableToggled);
            FieldAndIconPair(largeIconField, largeIconDisplay);
            FieldAndIconPair(smallIconField, smallIconDisplay);
            FieldAndIconPair(textBackgroundField, textBackgroundDisplay);

            ruleType.RegisterValueChangedCallback(OnRuleTypeChanged);

            if (btn_Apply != null)
            {
                btn_Apply.clickable.clicked += () => OnApply?.Invoke();
            }
            if (btn_Cancel != null)
            {
                btn_Cancel.clickable.clicked += () => OnCancel?.Invoke();
            }
            if (btn_Reset != null)
            {
                btn_Reset.clickable.clicked += () => OnReset?.Invoke();
            }
            if (btn_Settings != null)
            {
                btn_Settings.clickable.clicked += () => OnSettings?.Invoke();
            }
            if (btn_Delete != null)
            {
                btn_Delete.clickable.clicked += () => OnDelete?.Invoke();
            }

            SetSampleTextColor(textColor.value);
            textColor.RegisterValueChangedCallback(evt => { SetSampleTextColor(evt.newValue); });

            void SetSampleTextColor(Color color)
            {
                sampleText.style.color = color;
            }
        }
Esempio n. 21
0
        internal VisualElement CreateGUI(
            ValueChangedCallback valueChangedCallback,
            Color fieldToDraw,
            string labelName,
            out VisualElement propertyColorField,
            int indentLevel = 0)
        {
            var colorField = new ColorField {
                value = fieldToDraw, showEyeDropper = false, hdr = false
            };

            if (valueChangedCallback != null)
            {
                colorField.RegisterValueChangedCallback(evt => { valueChangedCallback((Color)evt.newValue); });
            }

            propertyColorField = colorField;

            var defaultRow = new PropertyRow(PropertyDrawerUtils.CreateLabel(labelName, indentLevel));

            defaultRow.Add(propertyColorField);
            return(defaultRow);
        }
Esempio n. 22
0
        public void Initialize(BaseGraphView graphView, CommentBlock block)
        {
            commentBlock = block;
            owner        = graphView;

            title = block.title;
            SetPosition(block.position);

            headerContainer.Q <TextField>().RegisterCallback <ChangeEvent <string> >(TitleChangedCallback);
            titleLabel = headerContainer.Q <Label>();

            colorField = new ColorField {
                value = commentBlock.color, name = "headerColorPicker"
            };
            colorField.RegisterValueChangedCallback(e =>
            {
                UpdateCommentBlockColor(e.newValue);
            });
            UpdateCommentBlockColor(commentBlock.color);

            headerContainer.Add(colorField);

            InitializeInnerNodes();
        }
Esempio n. 23
0
        public TextShadowStyleField(string label) : base(label)
        {
            AddToClassList(s_FieldClassName);

            styleSheets.Add(BuilderPackageUtilities.LoadAssetAtPath <StyleSheet>(s_UssPath));

            var template = BuilderPackageUtilities.LoadAssetAtPath <VisualTreeAsset>(s_UxmlPath);

            template.CloneTree(this);

            m_OffsetXField    = this.Q <DimensionStyleField>(s_OffsetXFieldName);
            m_OffsetYField    = this.Q <DimensionStyleField>(s_OffsetYFieldName);
            m_BlurRadiusField = this.Q <DimensionStyleField>(s_BlurRadiusFieldName);
            m_ColorField      = this.Q <ColorField>(s_ColorFieldName);

            m_OffsetXField.RegisterValueChangedCallback(e =>
            {
                UpdateTextShadowField();
                e.StopPropagation();
            });
            m_OffsetYField.RegisterValueChangedCallback(e =>
            {
                UpdateTextShadowField();
                e.StopPropagation();
            });
            m_BlurRadiusField.RegisterValueChangedCallback(e =>
            {
                UpdateTextShadowField();
                e.StopPropagation();
            });
            m_ColorField.RegisterValueChangedCallback(e =>
            {
                UpdateTextShadowField();
                e.StopPropagation();
            });
        }
Esempio n. 24
0
        public override void OnActivate(string searchContext, VisualElement root)
        {
            var padRect = new VisualElement();
            int padding = 10;

            padRect.style.paddingBottom = padding;
            padRect.style.paddingLeft   = padding;
            padRect.style.paddingRight  = padding;
            padRect.style.paddingTop    = padding - 5;
            root.Add(padRect);

            var title = new Label("Notch Solution");

            title.style.fontSize = 15;
            title.style.unityFontStyleAndWeight = FontStyle.Bold;
            padRect.Add(title);

            var repo = new Label("https://github.com/5argon/NotchSolution");

            repo.style.paddingBottom           = 15;
            repo.style.unityFontStyleAndWeight = FontStyle.Bold;
            repo.RegisterCallback((MouseDownEvent ev) =>
            {
                System.Diagnostics.Process.Start("https://github.com/5argon/NotchSolution");
            });
            padRect.Add(repo);

            var colorField = new ColorField("Prefab mode overlay color");

            colorField.value = NotchSolutionUtility.PrefabModeOverlayColor;
            colorField.RegisterValueChangedCallback(ev =>
            {
                NotchSolutionUtility.PrefabModeOverlayColor = ev.newValue;
                NotchSimulator.UpdateAllMockups();
                NotchSimulator.UpdateSimulatorTargets();
            });
            padRect.Add(colorField);

            string shortcutString = ShortcutManager.instance.GetShortcutBinding(NotchSolutionShortcuts.switchNarrowestWidestShortcut).ToString();
            string text           = $"This feature allows you to press {shortcutString} to quick switch between 2 aspect ratio choices. Commonly I would often switch between the longest phone like LG G7 and widest device like an iPad as I design. The index is counted from the top choice where 0 equals Free Aspect.";

            var box     = new Box();
            var helpBox = new Label(text);

            helpBox.style.whiteSpace = WhiteSpace.Normal;
            box.style.paddingTop     = 5;
            box.style.paddingLeft    = 5;
            box.style.paddingRight   = 5;
            box.style.paddingBottom  = 2;
            box.style.marginTop      = 10;
            box.style.marginBottom   = 10;
            box.Add(helpBox);
            padRect.Add(box);

            //TODO : Reflect to `GameViewSizes.instance` and request all sizes to draw a nicer drop down menu instead of index number.

            var narrowest = new IntegerField("Narrowest aspect index");

            narrowest.value = NotchSolutionUtility.NarrowestAspectIndex;
            narrowest.RegisterValueChangedCallback(ev =>
            {
                narrowest.value = Mathf.Max(0, ev.newValue); //go to -1 and the game view crashes..
                NotchSolutionUtility.NarrowestAspectIndex = ev.newValue;
                NotchSimulator.UpdateAllMockups();
                NotchSimulator.UpdateSimulatorTargets();
            });
            padRect.Add(narrowest);

            var widest = new IntegerField("Widest aspect index");

            widest.value = NotchSolutionUtility.WidestAspectIndex;
            widest.RegisterValueChangedCallback(ev =>
            {
                widest.value = Mathf.Max(0, ev.newValue);
                NotchSolutionUtility.WidestAspectIndex = ev.newValue;
                NotchSimulator.UpdateAllMockups();
                NotchSimulator.UpdateSimulatorTargets();
            });
            padRect.Add(widest);
        }
        private void OnEnable()
        {
            m_RootTemplate = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>(BehaviorTreeGraphWindow.c_WindowPath + "Settings.uxml");
            rootVisualElement.Add(m_RootTemplate.CloneTree());

            m_DimLevel               = rootVisualElement.Q <Slider>("Slider_Inactive_Dim");
            m_ColorField             = rootVisualElement.Q <ColorField>("clr_BorderHighlight");
            m_MiniMap                = rootVisualElement.Q <Toggle>("bool_MiniMap");
            m_LastTimestamp          = rootVisualElement.Q <Toggle>("bool_LastEvalTimestamp");
            m_SuccessIcon            = rootVisualElement.Q <ObjectField>("successIcon");
            m_RunningIcon            = rootVisualElement.Q <ObjectField>("runningIcon");
            m_FailureIcon            = rootVisualElement.Q <ObjectField>("failureIcon");
            m_MainNode               = rootVisualElement.Q <ObjectField>("mainNodeSelector");
            m_OverrideNode           = rootVisualElement.Q <ObjectField>("overrideNodeSelector");
            m_BaseNode               = new SettingNodeRow(BehaviorTreeGraphWindow.SettingsData.DataFile.DefaultStyleProperties, SettingNodeType.Base);
            m_MainNodesContainer     = rootVisualElement.Q <VisualElement>("mainNodesContainer");
            m_OverrideNodesContainer = rootVisualElement.Q <VisualElement>("overridesContainer");

            rootVisualElement.Q <VisualElement>("baseNodesContainer").Add(m_BaseNode);

            m_MainNode.objectType     = typeof(MonoScript);
            m_OverrideNode.objectType = typeof(MonoScript);
            m_SuccessIcon.objectType  = typeof(Sprite);
            m_RunningIcon.objectType  = typeof(Sprite);
            m_FailureIcon.objectType  = typeof(Sprite);

            m_MiniMap.RegisterValueChangedCallback((e) => { ToggleMiniMap(e.newValue); });
            m_LastTimestamp.RegisterValueChangedCallback((e) => { BehaviorTreeGraphWindow.SettingsData.SetLastEvalTimeStamp(e.newValue); });
            m_DimLevel.RegisterValueChangedCallback((e) => { BehaviorTreeGraphWindow.SettingsData.SetDimLevel(e.newValue); });
            m_ColorField.RegisterValueChangedCallback((e) => { BehaviorTreeGraphWindow.SettingsData.SetBorderHighlightColor(e.newValue); });
            m_SuccessIcon.RegisterValueChangedCallback((e) => { BehaviorTreeGraphWindow.SettingsData.UpdateGeneralcon(e.newValue as Sprite, IconType.Success); });
            m_RunningIcon.RegisterValueChangedCallback((e) => { BehaviorTreeGraphWindow.SettingsData.UpdateGeneralcon(e.newValue as Sprite, IconType.Running); });
            m_FailureIcon.RegisterValueChangedCallback((e) => { BehaviorTreeGraphWindow.SettingsData.UpdateGeneralcon(e.newValue as Sprite, IconType.Failure); });
            m_OverrideNode.RegisterValueChangedCallback((e) =>
            {
                if (e.newValue != null)
                {
                    SettingNodeRow newRow = new SettingNodeRow(new NodeProperty()
                    {
                        Script = e.newValue as MonoScript
                    }, SettingNodeType.Override);
                    m_OverrideNodesContainer.Add(newRow);
                    newRow.PlaceBehind(m_OverrideNode);

                    m_OverrideNode.value = null;
                }
            });
            m_MainNode.RegisterValueChangedCallback((e) =>
            {
                if (e.newValue != null)
                {
                    SettingNodeRow newRow = new SettingNodeRow(new NodeProperty()
                    {
                        Script = e.newValue as MonoScript
                    }, SettingNodeType.Main);
                    m_MainNodesContainer.Add(newRow);
                    newRow.PlaceBehind(m_MainNode);

                    m_MainNode.value = null;
                }
            });

            DisplaySettings();
        }
Esempio n. 26
0
        internal static SettingsProvider CreateProjectSettingsProvider()
        {
            return(new SettingsProvider("Preferences/Assembly Tools", SettingsScope.User)
            {
                activateHandler = (s, element) =>
                {
                    element.Add(new Label("History Directory"));
                    var histDir = new TextField();
                    histDir.name = "History Directory";
                    histDir.value = HistoryDirectory;
                    histDir.RegisterValueChangedCallback(evt => HistoryDirectory = evt.newValue);
                    histDir.tooltip = "Where to store the log files for compilation events. Relative to the Assets directory.";
                    element.Add(histDir);

                    element.Add(new Label("Node Layout File"));
                    var nodeFile = new TextField();
                    nodeFile.name = "Node Layout File";
                    nodeFile.value = NodeLayoutFile;
                    nodeFile.RegisterValueChangedCallback(evt => NodeLayoutFile = evt.newValue);
                    element.Add(nodeFile);

                    element.Add(new Label("Max History"));
                    var maxHist = new IntegerField();
                    maxHist.value = MaxHistorySize;
                    maxHist.RegisterValueChangedCallback(evt =>
                    {
                        var value = evt.newValue;
                        if (value < 0)
                        {
                            value = 0;
                            maxHist.SetValueWithoutNotify(value);
                        }

                        MaxHistorySize = value;
                    });
                    element.Add(maxHist);

                    element.Add(new Label("Editor Node Color"));
                    var editorNodeColor = new ColorField();
                    editorNodeColor.name = "Editor Node Color";
                    editorNodeColor.value = EditorNodeColor;
                    editorNodeColor.RegisterValueChangedCallback(evt =>
                    {
                        EditorNodeColor = evt.newValue;
                        if (NodePreferenceChanged != null)
                        {
                            NodePreferenceChanged();
                        }
                    });
                    element.Add(editorNodeColor);

                    element.Add(new Label("Player Node Color"));
                    var playerNodeColor = new ColorField();
                    playerNodeColor.name = "Player Node Color";
                    playerNodeColor.value = PlayerNodeColor;
                    playerNodeColor.RegisterValueChangedCallback(evt =>
                    {
                        PlayerNodeColor = evt.newValue;
                        if (NodePreferenceChanged != null)
                        {
                            NodePreferenceChanged();
                        }
                    });
                    element.Add(playerNodeColor);

                    element.Add(new Label("Test Node Color"));
                    var testNodeColor = new ColorField();
                    testNodeColor.name = "Test Node Color";
                    testNodeColor.value = TestNodeColor;
                    testNodeColor.RegisterValueChangedCallback(evt =>
                    {
                        TestNodeColor = evt.newValue;
                        if (NodePreferenceChanged != null)
                        {
                            NodePreferenceChanged();
                        }
                    });
                    element.Add(testNodeColor);
                }
            });
        }
Esempio n. 27
0
        public VisualElement GetDefaultInspector()
        {
            VisualElement inspector = new VisualElement()
            {
                name = "inspector"
            };

            VisualElement header = new VisualElement()
            {
                name = "inspector-header"
            };

            header.Add(new Image()
            {
                image = CoreEditorUtils.LoadIcon(@"Packages/com.unity.render-pipelines.core/Editor/LookDev/Icons/", "Environment", forceLowRes: true)
            });
            environmentName           = new TextField();
            environmentName.isDelayed = true;
            environmentName.RegisterValueChangedCallback(evt =>
            {
                string path      = AssetDatabase.GetAssetPath(environment);
                environment.name = evt.newValue;
                AssetDatabase.SetLabels(environment, new string[] { evt.newValue });
                EditorUtility.SetDirty(environment);
                AssetDatabase.ImportAsset(path);
                environmentName.name = environment.name;
            });
            header.Add(environmentName);
            inspector.Add(header);

            Foldout foldout = new Foldout()
            {
                text = "Environment Settings"
            };

            skyCubemapField = new ObjectField("Sky with Sun")
            {
                tooltip = "A cubemap that will be used as the sky."
            };
            skyCubemapField.allowSceneObjects = false;
            skyCubemapField.objectType        = typeof(Cubemap);
            skyCubemapField.RegisterValueChangedCallback(evt =>
            {
                var tmp = environment.sky.cubemap;
                RegisterChange(ref tmp, evt.newValue as Cubemap);
                environment.sky.cubemap = tmp;
                latlong.image           = GetLatLongThumbnailTexture(environment, k_SkyThumbnailWidth);
            });
            foldout.Add(skyCubemapField);

            shadowCubemapField = new ObjectField("Sky without Sun")
            {
                tooltip = "[Optional] A cubemap that will be used to compute self shadowing.\nIt should be the same sky without the sun.\nIf nothing is provided, the sky with sun will be used with lower intensity."
            };
            shadowCubemapField.allowSceneObjects = false;
            shadowCubemapField.objectType        = typeof(Cubemap);
            shadowCubemapField.RegisterValueChangedCallback(evt =>
            {
                var tmp = environment.shadow.cubemap;
                RegisterChange(ref tmp, evt.newValue as Cubemap);
                environment.shadow.cubemap = tmp;
                latlong.image = GetLatLongThumbnailTexture(environment, k_SkyThumbnailWidth);
            });
            foldout.Add(shadowCubemapField);

            skyRotationOffset = new FloatField("Rotation")
            {
                tooltip = "Rotation offset on the longitude of the sky."
            };
            skyRotationOffset.RegisterValueChangedCallback(evt
                                                           => RegisterChange(ref environment.sky.rotation, Environment.Shadow.ClampLongitude(evt.newValue), skyRotationOffset, updatePreview: true));
            foldout.Add(skyRotationOffset);

            skyExposureField = new FloatField("Exposure")
            {
                tooltip = "The exposure to apply with this sky."
            };
            skyExposureField.RegisterValueChangedCallback(evt
                                                          => RegisterChange(ref environment.sky.exposure, evt.newValue));
            foldout.Add(skyExposureField);
            var style = foldout.Q <Toggle>().style;

            style.marginLeft = 3;
            style.unityFontStyleAndWeight = FontStyle.Bold;
            inspector.Add(foldout);

            sunPosition = new Vector2Field("Sun Position")
            {
                tooltip = "The sun position as (Longitude, Latitude)\nThe button compute brightest position in the sky with sun."
            };
            sunPosition.Q("unity-x-input").Q <FloatField>().formatString = "n1";
            sunPosition.Q("unity-y-input").Q <FloatField>().formatString = "n1";
            sunPosition.RegisterValueChangedCallback(evt =>
            {
                var tmpContainer = new Vector2(
                    environment.shadow.sunLongitude,
                    environment.shadow.sunLatitude);
                var tmpNewValue = new Vector2(
                    Environment.Shadow.ClampLongitude(evt.newValue.x),
                    Environment.Shadow.ClampLatitude(evt.newValue.y));
                RegisterChange(ref tmpContainer, tmpNewValue, sunPosition);
                environment.shadow.sunLongitude = tmpContainer.x;
                environment.shadow.sunLatitude  = tmpContainer.y;
            });
            foldout.Add(sunPosition);

            Button sunToBrightess = new Button(() =>
            {
                ResetToBrightestSpot(environment);
                sunPosition.SetValueWithoutNotify(new Vector2(
                                                      Environment.Shadow.ClampLongitude(environment.shadow.sunLongitude),
                                                      Environment.Shadow.ClampLatitude(environment.shadow.sunLatitude)));
            })
            {
                name = "sunToBrightestButton"
            };

            sunToBrightess.Add(new Image()
            {
                image = CoreEditorUtils.LoadIcon(@"Packages/com.unity.render-pipelines.core/Editor/LookDev/Icons/", "SunPosition", forceLowRes: true)
            });
            sunToBrightess.AddToClassList("sun-to-brightest-button");
            var vector2Input = sunPosition.Q(className: "unity-vector2-field__input");

            vector2Input.Remove(sunPosition.Q(className: "unity-composite-field__field-spacer"));
            vector2Input.Add(sunToBrightess);

            shadowColor = new ColorField("Shadow Tint")
            {
                tooltip = "The wanted shadow tint to be used when computing shadow."
            };
            shadowColor.RegisterValueChangedCallback(evt
                                                     => RegisterChange(ref environment.shadow.color, evt.newValue));
            foldout.Add(shadowColor);

            style            = foldout.Q <Toggle>().style;
            style.marginLeft = 3;
            style.unityFontStyleAndWeight = FontStyle.Bold;
            inspector.Add(foldout);

            return(inspector);
        }
Esempio n. 28
0
        BuilderStyleRow CreateAttributeRow(UxmlAttributeDescription attribute)
        {
            var attributeType = attribute.GetType();

            // Generate field label.
            var             fieldLabel = BuilderNameUtilities.ConvertDashToHuman(attribute.name);
            BindableElement fieldElement;

            if (attribute is UxmlStringAttributeDescription)
            {
                // Hard-coded
                if (attribute.name.Equals("value") && currentVisualElement is EnumField enumField)
                {
                    var uiField = new EnumField("Value");
                    if (null != enumField.value)
                    {
                        uiField.Init(enumField.value, enumField.includeObsoleteValues);
                    }
                    else
                    {
                        uiField.SetValueWithoutNotify(null);
                    }
                    uiField.RegisterValueChangedCallback(evt =>
                                                         PostAttributeValueChange(uiField, uiField.value.ToString()));
                    fieldElement = uiField;
                }
                else if (attribute.name.Equals("value") && currentVisualElement is TagField tagField)
                {
                    var uiField = new TagField("Value");
                    uiField.RegisterValueChangedCallback(evt =>
                                                         PostAttributeValueChange(uiField, uiField.value.ToString()));
                    fieldElement = uiField;
                }
                else
                {
                    var uiField = new TextField(fieldLabel);
                    if (attribute.name.Equals("name") || attribute.name.Equals("view-data-key"))
                    {
                        uiField.RegisterValueChangedCallback(e =>
                        {
                            OnValidatedAttributeValueChange(e, BuilderNameUtilities.attributeRegex,
                                                            BuilderConstants.AttributeValidationSpacialCharacters);
                        });
                    }
                    else if (attribute.name.Equals("binding-path"))
                    {
                        uiField.RegisterValueChangedCallback(e =>
                        {
                            OnValidatedAttributeValueChange(e, BuilderNameUtilities.bindingPathAttributeRegex,
                                                            BuilderConstants.BindingPathAttributeValidationSpacialCharacters);
                        });
                    }
                    else
                    {
                        uiField.RegisterValueChangedCallback(OnAttributeValueChange);
                    }

                    if (attribute.name.Equals("text") || attribute.name.Equals("label"))
                    {
                        uiField.multiline = true;
                        uiField.AddToClassList(BuilderConstants.InspectorMultiLineTextFieldClassName);
                    }

                    fieldElement = uiField;
                }
            }
            else if (attribute is UxmlFloatAttributeDescription)
            {
                var uiField = new FloatField(fieldLabel);
                uiField.RegisterValueChangedCallback(OnAttributeValueChange);
                fieldElement = uiField;
            }
            else if (attribute is UxmlDoubleAttributeDescription)
            {
                var uiField = new DoubleField(fieldLabel);
                uiField.RegisterValueChangedCallback(OnAttributeValueChange);
                fieldElement = uiField;
            }
            else if (attribute is UxmlIntAttributeDescription)
            {
                if (attribute.name.Equals("value") && currentVisualElement is LayerField)
                {
                    var uiField = new LayerField("Value");
                    uiField.RegisterValueChangedCallback(OnAttributeValueChange);
                    fieldElement = uiField;
                }
                else if (attribute.name.Equals("value") && currentVisualElement is LayerMaskField)
                {
                    var uiField = new LayerMaskField("Value");
                    uiField.RegisterValueChangedCallback(OnAttributeValueChange);
                    fieldElement = uiField;
                }
                else
                {
                    var uiField = new IntegerField(fieldLabel);
                    uiField.RegisterValueChangedCallback(OnAttributeValueChange);
                    fieldElement = uiField;
                }
            }
            else if (attribute is UxmlLongAttributeDescription)
            {
                var uiField = new LongField(fieldLabel);
                uiField.RegisterValueChangedCallback(OnAttributeValueChange);
                fieldElement = uiField;
            }
            else if (attribute is UxmlBoolAttributeDescription)
            {
                var uiField = new Toggle(fieldLabel);
                uiField.RegisterValueChangedCallback(OnAttributeValueChange);
                fieldElement = uiField;
            }
            else if (attribute is UxmlColorAttributeDescription)
            {
                var uiField = new ColorField(fieldLabel);
                uiField.RegisterValueChangedCallback(OnAttributeValueChange);
                fieldElement = uiField;
            }
            else if (attributeType.IsGenericType &&
                     !attributeType.GetGenericArguments()[0].IsEnum &&
                     attributeType.GetGenericArguments()[0] is Type)
            {
                var desiredType = attributeType.GetGenericArguments()[0];

                var uiField = new TextField(fieldLabel)
                {
                    isDelayed = true
                };

                var completer = new FieldSearchCompleter <TypeInfo>(uiField);
                uiField.RegisterCallback <AttachToPanelEvent, FieldSearchCompleter <TypeInfo> >((evt, c) =>
                {
                    // When possible, the popup should have the same width as the input field, so that the auto-complete
                    // characters will try to match said input field.
                    c.popup.anchoredControl = ((VisualElement)evt.target).Q(className: "unity-text-field__input");
                }, completer);
                completer.matcherCallback    += (str, info) => info.value.IndexOf(str, StringComparison.OrdinalIgnoreCase) >= 0;
                completer.itemHeight          = 36;
                completer.dataSourceCallback += () =>
                {
                    return(TypeCache.GetTypesDerivedFrom(desiredType)
                           .Where(t => !t.IsGenericType)
                           // Remove UIBuilder types from the list
                           .Where(t => t.Assembly != GetType().Assembly)
                           .Select(GetTypeInfo));
                };
                completer.getTextFromDataCallback += info => info.value;
                completer.makeItem    = () => s_TypeNameItemPool.Get();
                completer.destroyItem = e =>
                {
                    if (e is BuilderAttributeTypeName typeItem)
                    {
                        s_TypeNameItemPool.Release(typeItem);
                    }
                };
                completer.bindItem = (v, i) =>
                {
                    if (v is BuilderAttributeTypeName l)
                    {
                        l.SetType(completer.results[i].type, completer.textField.text);
                    }
                };

                uiField.RegisterValueChangedCallback(e => OnValidatedTypeAttributeChange(e, desiredType));

                fieldElement = uiField;
                uiField.RegisterCallback <DetachFromPanelEvent, FieldSearchCompleter <TypeInfo> >((evt, c) =>
                {
                    c.popup.RemoveFromHierarchy();
                }, completer);
                uiField.userData = completer;
            }
            else if (attributeType.IsGenericType && attributeType.GetGenericArguments()[0].IsEnum)
            {
                var propInfo         = attributeType.GetProperty("defaultValue");
                var defaultEnumValue = propInfo.GetValue(attribute, null) as Enum;

                if (defaultEnumValue.GetType().GetCustomAttribute <FlagsAttribute>() == null)
                {
                    // Create and initialize the EnumField.
                    var uiField = new EnumField(fieldLabel);
                    uiField.Init(defaultEnumValue);

                    uiField.RegisterValueChangedCallback(OnAttributeValueChange);
                    fieldElement = uiField;
                }
                else
                {
                    // Create and initialize the EnumField.
                    var uiField = new EnumFlagsField(fieldLabel);
                    uiField.Init(defaultEnumValue);

                    uiField.RegisterValueChangedCallback(OnAttributeValueChange);
                    fieldElement = uiField;
                }
            }
            else
            {
                var uiField = new TextField(fieldLabel);
                uiField.RegisterValueChangedCallback(OnAttributeValueChange);
                fieldElement = uiField;
            }

            // Create row.
            var styleRow = new BuilderStyleRow();

            styleRow.Add(fieldElement);

            // Link the field.
            fieldElement.SetProperty(BuilderConstants.InspectorLinkedStyleRowVEPropertyName, styleRow);
            fieldElement.SetProperty(BuilderConstants.InspectorLinkedAttributeDescriptionVEPropertyName, attribute);

            // Set initial value.
            RefreshAttributeField(fieldElement);

            // Setup field binding path.
            fieldElement.bindingPath = attribute.name;
            fieldElement.tooltip     = attribute.name;

            // Context menu.
            fieldElement.AddManipulator(new ContextualMenuManipulator(BuildAttributeFieldContextualMenu));

            return(styleRow);
        }
        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;
        }
        BuilderStyleRow CreateAttributeRow(UxmlAttributeDescription attribute)
        {
            var attributeType = attribute.GetType();

            // Generate field label.
            var             fieldLabel = BuilderNameUtilities.ConvertDashToHuman(attribute.name);
            BindableElement fieldElement;

            if (attribute is UxmlStringAttributeDescription)
            {
                var uiField = new TextField(fieldLabel);
                if (attribute.name.Equals("name") || attribute.name.Equals("view-data-key"))
                {
                    uiField.RegisterValueChangedCallback(e =>
                    {
                        OnValidatedAttributeValueChange(e, BuilderNameUtilities.AttributeRegex, BuilderConstants.AttributeValidationSpacialCharacters);
                    });
                }
                else if (attribute.name.Equals("binding-path"))
                {
                    uiField.RegisterValueChangedCallback(e =>
                    {
                        OnValidatedAttributeValueChange(e, BuilderNameUtilities.BindingPathAttributeRegex, BuilderConstants.BindingPathAttributeValidationSpacialCharacters);
                    });
                }
                else
                {
                    uiField.RegisterValueChangedCallback(OnAttributeValueChange);
                }

                if (attribute.name.Equals("text"))
                {
                    uiField.multiline = true;
                    uiField.AddToClassList(BuilderConstants.InspectorMultiLineTextFieldClassName);
                }

                fieldElement = uiField;
            }
            else if (attribute is UxmlFloatAttributeDescription)
            {
                var uiField = new FloatField(fieldLabel);
                uiField.RegisterValueChangedCallback(OnAttributeValueChange);
                fieldElement = uiField;
            }
            else if (attribute is UxmlDoubleAttributeDescription)
            {
                var uiField = new DoubleField(fieldLabel);
                uiField.RegisterValueChangedCallback(OnAttributeValueChange);
                fieldElement = uiField;
            }
            else if (attribute is UxmlIntAttributeDescription)
            {
                var uiField = new IntegerField(fieldLabel);
                uiField.RegisterValueChangedCallback(OnAttributeValueChange);
                fieldElement = uiField;
            }
            else if (attribute is UxmlLongAttributeDescription)
            {
                var uiField = new LongField(fieldLabel);
                uiField.RegisterValueChangedCallback(OnAttributeValueChange);
                fieldElement = uiField;
            }
            else if (attribute is UxmlBoolAttributeDescription)
            {
                var uiField = new Toggle(fieldLabel);
                uiField.RegisterValueChangedCallback(OnAttributeValueChange);
                fieldElement = uiField;
            }
            else if (attribute is UxmlColorAttributeDescription)
            {
                var uiField = new ColorField(fieldLabel);
                uiField.RegisterValueChangedCallback(OnAttributeValueChange);
                fieldElement = uiField;
            }
            else if (attributeType.IsGenericType &&
                     !attributeType.GetGenericArguments()[0].IsEnum &&
                     attributeType.GetGenericArguments()[0] is Type)
            {
                var uiField = new TextField(fieldLabel);
                uiField.isDelayed = true;
                uiField.RegisterValueChangedCallback(e =>
                {
                    OnValidatedTypeAttributeChange(e, attributeType.GetGenericArguments()[0]);
                });
                fieldElement = uiField;
            }
            else if (attributeType.IsGenericType && attributeType.GetGenericArguments()[0].IsEnum)
            {
                var propInfo  = attributeType.GetProperty("defaultValue");
                var enumValue = propInfo.GetValue(attribute, null) as Enum;

                // Create and initialize the EnumField.
                var uiField = new EnumField(fieldLabel);
                uiField.Init(enumValue);

                uiField.RegisterValueChangedCallback(OnAttributeValueChange);
                fieldElement = uiField;
            }
            else
            {
                var uiField = new TextField(fieldLabel);
                uiField.RegisterValueChangedCallback(OnAttributeValueChange);
                fieldElement = uiField;
            }

            // Create row.
            var styleRow = new BuilderStyleRow();

            styleRow.Add(fieldElement);

            // Link the field.
            fieldElement.SetProperty(BuilderConstants.InspectorLinkedStyleRowVEPropertyName, styleRow);
            fieldElement.SetProperty(BuilderConstants.InspectorLinkedAttributeDescriptionVEPropertyName, attribute);

            // Set initial value.
            RefreshAttributeField(fieldElement);

            // Setup field binding path.
            fieldElement.bindingPath = attribute.name;

            // Tooltip.
            var label = fieldElement.Q <Label>();

            if (label != null)
            {
                label.tooltip = attribute.name;
            }
            else
            {
                fieldElement.tooltip = attribute.name;
            }

            // Context menu.
            fieldElement.AddManipulator(new ContextualMenuManipulator(BuildAttributeFieldContextualMenu));

            return(styleRow);
        }