#pragma warning restore 414 public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext cc) { base.Init(ve, bag, cc); if (EnumFieldHelpers.ExtractValue(bag, cc, out var resEnumType, out var resEnumValue, out var resIncludeObsoleteValues)) { EnumFlagsField enumField = (EnumFlagsField)ve; enumField.Init(resEnumValue, resIncludeObsoleteValues); }
private VisualElement CreateFieldFromProperty(SerializedProperty property) { var propertyType = property.propertyType; if (EditorGUI.HasVisibleChildFields(property, true)) { return(CreateFoldout(property)); } TrimChildrenContainerSize(0); m_ChildrenContainer = null; switch (propertyType) { case SerializedPropertyType.Integer: if (property.type == "long") { return(ConfigureField <LongField, long>(new LongField(), property)); } return(ConfigureField <IntegerField, int>(new IntegerField(), property)); case SerializedPropertyType.Boolean: return(ConfigureField <Toggle, bool>(new Toggle(), property)); case SerializedPropertyType.Float: return(ConfigureField <FloatField, float>(new FloatField(), property)); case SerializedPropertyType.String: return(ConfigureField <TextField, string>(new TextField(), property)); case SerializedPropertyType.Color: return(ConfigureField <ColorField, Color>(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(ConfigureField <ObjectField, UnityEngine.Object>(field, property)); } case SerializedPropertyType.LayerMask: return(ConfigureField <LayerMaskField, int>(new LayerMaskField(), property)); case SerializedPropertyType.Enum: { Type enumType; ScriptAttributeUtility.GetFieldInfoFromProperty(property, out enumType); if (enumType.IsDefined(typeof(FlagsAttribute), false)) { var field = new EnumFlagsField(); field.choices = property.enumDisplayNames.ToList(); field.value = (Enum)Enum.ToObject(enumType, property.intValue); return(ConfigureField <EnumFlagsField, Enum>(field, property)); } else { var field = new PopupField <string>(property.enumDisplayNames.ToList(), property.enumValueIndex); field.index = property.enumValueIndex; return(ConfigureField <PopupField <string>, string>(field, property)); } } case SerializedPropertyType.Vector2: return(ConfigureField <Vector2Field, Vector2>(new Vector2Field(), property)); case SerializedPropertyType.Vector3: return(ConfigureField <Vector3Field, Vector3>(new Vector3Field(), property)); case SerializedPropertyType.Vector4: return(ConfigureField <Vector4Field, Vector4>(new Vector4Field(), property)); case SerializedPropertyType.Rect: return(ConfigureField <RectField, Rect>(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.RegisterValueChangedCallback((e) => { UpdateArrayFoldout(e, this, m_ParentPropertyField); }); return(ConfigureField <IntegerField, int>(field, property)); } case SerializedPropertyType.Character: { var field = new TextField(); field.maxLength = 1; return(ConfigureField <TextField, string>(field, property)); } case SerializedPropertyType.AnimationCurve: return(ConfigureField <CurveField, AnimationCurve>(new CurveField(), property)); case SerializedPropertyType.Bounds: return(ConfigureField <BoundsField, Bounds>(new BoundsField(), property)); case SerializedPropertyType.Gradient: return(ConfigureField <GradientField, Gradient>(new GradientField(), property)); case SerializedPropertyType.Quaternion: return(null); case SerializedPropertyType.ExposedReference: return(null); case SerializedPropertyType.FixedBufferSize: return(null); case SerializedPropertyType.Vector2Int: return(ConfigureField <Vector2IntField, Vector2Int>(new Vector2IntField(), property)); case SerializedPropertyType.Vector3Int: return(ConfigureField <Vector3IntField, Vector3Int>(new Vector3IntField(), property)); case SerializedPropertyType.RectInt: return(ConfigureField <RectIntField, RectInt>(new RectIntField(), property)); case SerializedPropertyType.BoundsInt: return(ConfigureField <BoundsIntField, BoundsInt>(new BoundsIntField(), property)); #if UNITY_2021_1_OR_NEWER case SerializedPropertyType.Hash128: return(ConfigureField <Hash128Field, Hash128>(new Hash128Field(), property)); #endif case SerializedPropertyType.Generic: default: return(null); } }