public override void OnActivate(string searchContext, VisualElement rootElement)
        {
            // TODO: Switch to use uxml/uss for this.
            var root = new VisualElement();

            rootElement.Add(root);
            var title = new Label(Title);

            title.style.unityFontStyleAndWeight = FontStyle.Bold;
            title.style.marginTop      = 1;
            title.style.fontSize       = 19;
            title.style.unityTextAlign = TextAnchor.MiddleLeft;
            title.style.height         = 26;
            root.Add(title);

            Resources.Templates.Settings.AddStyles(rootElement);
            foreach (var kvp in s_Settings)
            {
                if (kvp.Value.All(w => w.Internal) && !Unsupported.IsDeveloperMode())
                {
                    continue;
                }

                var label = new Label {
                    text = kvp.Key
                };
                label.style.unityFontStyleAndWeight = FontStyle.Bold;
                root.Add(label);

                foreach (var wrapper in kvp.Value)
                {
                    if (wrapper.Internal && !Unsupported.IsDeveloperMode())
                    {
                        continue;
                    }

                    var setting = wrapper.Setting;
                    var element = new PropertyElement();
                    element.style.marginLeft = -3;
                    element.SetAttributeFilter(AttributeFilter);
                    element.SetTarget(setting);
                    element.OnChanged += (propertyElement, path) => setting.OnSettingChanged(path);
                    root.Add(element);
                    element.RegisterCallback <GeometryChangedEvent>(evt =>
                                                                    StylingUtility.AlignInspectorLabelWidth(element));
                }
            }
            root.AddToClassList("unity-inspector-element");
            root.style.paddingLeft = 10;

            base.OnActivate(searchContext, rootElement);
        }
Пример #2
0
        public void PropertyElement_WithAttributeFilter_FiltersHierarchyGeneration()
        {
            var element = new PropertyElement();

            element.SetTarget(new FilterByAttribute());
            Assert.That(element.contentContainer.childCount, Is.EqualTo(4));
            Assert.That(element[0], Is.InstanceOf <IntegerField>());
            Assert.That(element[1], Is.InstanceOf <TextField>());
            Assert.That(element[2], Is.InstanceOf <DoubleField>());
            Assert.That(element[3], Is.InstanceOf <FloatField>());

            element.SetAttributeFilter(attributes => null == attributes.OfType <HideAttribute>().FirstOrDefault());

            Assert.That(element.contentContainer.childCount, Is.EqualTo(1));
            Assert.That(element[0], Is.InstanceOf <FloatField>());
        }