Ejemplo n.º 1
0
        public InlineField(SerializedProperty property, bool showMemberLabels)
        {
            var childContainer = new VisualElement();

            childContainer.AddToClassList(ChildrenUssClassName);

            if (!showMemberLabels)
            {
                var label = new FieldContainer(property.displayName);
                label.AddToClassList(LabelUssClassName);
                Add(label);
            }

            foreach (var child in property.Children())
            {
                var field = new PropertyField(child);
                if (!showMemberLabels)
                {
                    field.SetFieldLabel(null);
                }

                childContainer.Add(field);
            }

            Add(childContainer);
            AddToClassList(UssClassName);
            this.AddStyleSheet(Stylesheet);
        }
Ejemplo n.º 2
0
        public override VisualElement CreatePropertyGUI(SerializedProperty property)
        {
            var showMemberLabels = (attribute as InlineAttribute).ShowMemberLabels;

            var container      = new VisualElement();
            var childContainer = new VisualElement();

            childContainer.AddToClassList(ChildrenUssClassName);

            if (!showMemberLabels)
            {
                var label = new FieldContainer(property.displayName, this.GetTooltip());
                label.AddToClassList(LabelUssClassName);
                container.Add(label);
            }

            foreach (var child in property.Children())
            {
                var field = new PropertyField(child);
                if (!showMemberLabels)
                {
                    field.SetLabel(null);
                }

                childContainer.Add(field);
            }

            container.Add(childContainer);
            container.AddToClassList(UssClassName);
            container.AddStyleSheet(Configuration.ElementsPath, Stylesheet);

            return(container);
        }
Ejemplo n.º 3
0
        public VisualElement CreateElement(object value)
        {
            if (_drawer != null)
            {
                return(_drawer.CreatePropertyGUI(_property));
            }
            else
            {
                var container = new VisualElement();

                foreach (var child in _property.Children())
                {
                    var field = new PropertyField(child);
                    field.Bind(_property.serializedObject);                     // this is only called automatically when the inspector is first created
                    container.Add(field);
                }

                return(container);
            }
        }
        public static void SetToDefault(this SerializedProperty property)
        {
            if (property.isArray)
            {
                property.ClearArray();
            }
            else if (property.hasChildren && property.propertyType != SerializedPropertyType.ManagedReference)
            {
                foreach (var child in property.Children())
                {
                    child.SetToDefault();
                }
            }
            else
            {
                switch (property.propertyType)
                {
                case SerializedPropertyType.Generic: break;

                case SerializedPropertyType.Integer: property.intValue = default; break;

                case SerializedPropertyType.Boolean: property.boolValue = default; break;

                case SerializedPropertyType.Float: property.floatValue = default; break;

                case SerializedPropertyType.String: property.stringValue = string.Empty; break;

                case SerializedPropertyType.Color: property.colorValue = default; break;

                case SerializedPropertyType.ObjectReference: property.objectReferenceValue = default; break;

                case SerializedPropertyType.LayerMask: property.intValue = 0; break;

                case SerializedPropertyType.Enum: property.enumValueIndex = 0; break;

                case SerializedPropertyType.Vector2: property.vector2Value = default; break;

                case SerializedPropertyType.Vector3: property.vector3Value = default; break;

                case SerializedPropertyType.Vector4: property.vector4Value = default; break;

                case SerializedPropertyType.Rect: property.rectValue = default; break;

                case SerializedPropertyType.ArraySize: property.intValue = 0; break;

                case SerializedPropertyType.Character: property.intValue = default; break;

                case SerializedPropertyType.AnimationCurve: property.animationCurveValue = default; break;

                case SerializedPropertyType.Bounds: property.boundsValue = default; break;

                case SerializedPropertyType.Gradient: property.SetGradientValue(default); break;

                case SerializedPropertyType.Quaternion: property.quaternionValue = default; break;

                case SerializedPropertyType.ExposedReference: property.exposedReferenceValue = default; break;

                case SerializedPropertyType.FixedBufferSize: property.intValue = 0; break;

                case SerializedPropertyType.Vector2Int: property.vector2IntValue = default; break;

                case SerializedPropertyType.Vector3Int: property.vector3IntValue = default; break;

                case SerializedPropertyType.RectInt: property.rectIntValue = default; break;

                case SerializedPropertyType.BoundsInt: property.boundsIntValue = default; break;

                case SerializedPropertyType.ManagedReference: property.managedReferenceValue = default; break;
                }
            }
        }