Beispiel #1
0
            public ObjectFieldDisplay(ObjectField objectField)
            {
                m_ObjectIcon = new Image {
                    scaleMode = ScaleMode.ScaleAndCrop, pickingMode = PickingMode.Ignore
                };
                m_ObjectLabel = new Label {
                    pickingMode = PickingMode.Ignore
                };
                m_ObjectField = objectField;

                Update();

                Add(m_ObjectIcon);
                Add(m_ObjectLabel);
            }
Beispiel #2
0
 public ObjectFieldDisplay(ObjectField objectField)
 {
     this.m_ObjectIcon = new Image
     {
         scaleMode   = ScaleMode.ScaleAndCrop,
         pickingMode = PickingMode.Ignore
     };
     this.m_ObjectLabel = new Label
     {
         pickingMode = PickingMode.Ignore
     };
     this.m_ObjectField = objectField;
     this.Update();
     base.Add(this.m_ObjectIcon);
     base.Add(this.m_ObjectLabel);
 }
Beispiel #3
0
        private VisualElement CreateFieldFromProperty(SerializedProperty property)
        {
            var propertyType = property.propertyType;

            if (EditorGUI.HasVisibleChildFields(property))
            {
                return(CreateFoldout(property));
            }

            switch (propertyType)
            {
            case SerializedPropertyType.Integer:
                return(CreateLabeledField(new IntegerField(), property));

            case SerializedPropertyType.Boolean:
                return(CreateLabeledField(new Toggle(), property));

            case SerializedPropertyType.Float:
                return(CreateLabeledField(new FloatField(), property));

            case SerializedPropertyType.String:
                return(CreateLabeledField(new TextField(), property));

            case SerializedPropertyType.Color:
                return(CreateLabeledField(new ColorField(), property));

            case SerializedPropertyType.ObjectReference:
            {
                var  field        = new ObjectField();
                Type requiredType = null;

                // Checking if the target ExtendsANativeType() avoids a native error when
                // getting the type about: "type is not a supported pptr value"
                var target = property.serializedObject.targetObject;
                if (NativeClassExtensionUtilities.ExtendsANativeType(target))
                {
                    ScriptAttributeUtility.GetFieldInfoFromProperty(property, out requiredType);
                }

                if (requiredType == null)
                {
                    requiredType = typeof(UnityEngine.Object);
                }

                field.objectType = requiredType;
                return(CreateLabeledField(field, property));
            }

            case SerializedPropertyType.LayerMask:
                return(CreateLabeledField(new LayerMaskField(), property));

            case SerializedPropertyType.Enum:
            {
                var field = new PopupField <string>(property.enumDisplayNames.ToList(), property.enumValueIndex);
                field.index = property.enumValueIndex;
                return(CreateLabeledField(field, property));
            }

            case SerializedPropertyType.Vector2:
                return(CreateLabeledField(new Vector2Field(), property));

            case SerializedPropertyType.Vector3:
                return(CreateLabeledField(new Vector3Field(), property));

            case SerializedPropertyType.Vector4:
                return(CreateLabeledField(new Vector4Field(), property));

            case SerializedPropertyType.Rect:
                return(CreateLabeledField(new RectField(), property));

            case SerializedPropertyType.ArraySize:
            {
                var field = new IntegerField();
                field.SetValueWithoutNotify(property.intValue); // This avoids the OnValueChanged/Rebind feedback loop.
                field.isDelayed = true;                         // To match IMGUI. Also, focus is lost anyway due to the rebind.
                field.OnValueChanged((e) => { UpdateArrayFoldout(e, this, m_ParentPropertyField); });
                return(CreateLabeledField(field, property));
            }

            case SerializedPropertyType.Character:
            {
                var field = new TextField();
                field.maxLength = 1;
                return(CreateLabeledField(field, property));
            }

            case SerializedPropertyType.AnimationCurve:
                return(CreateLabeledField(new CurveField(), property));

            case SerializedPropertyType.Bounds:
                return(CreateLabeledField(new BoundsField(), property));

            case SerializedPropertyType.Gradient:
                return(CreateLabeledField(new GradientField(), property));

            case SerializedPropertyType.Quaternion:
                return(null);

            case SerializedPropertyType.ExposedReference:
                return(null);

            case SerializedPropertyType.FixedBufferSize:
                return(null);

            case SerializedPropertyType.Vector2Int:
                return(CreateLabeledField(new Vector2IntField(), property));

            case SerializedPropertyType.Vector3Int:
                return(CreateLabeledField(new Vector3IntField(), property));

            case SerializedPropertyType.RectInt:
                return(CreateLabeledField(new RectIntField(), property));

            case SerializedPropertyType.BoundsInt:
                return(CreateLabeledField(new BoundsIntField(), property));

            case SerializedPropertyType.Generic:
            default:
                return(null);
            }
        }
Beispiel #4
0
 public ObjectFieldSelector(ObjectField objectField)
 {
     m_ObjectField = objectField;
 }