public override VisualElement CreatePropertyGUI(SerializedProperty property) { var popup = attribute as PopupAttribute; if (property.propertyType == SerializedPropertyType.Integer) { if (popup.IntValues != null && popup.IntValues.Count > 0) { if (popup.Options != null && popup.Options.Count != popup.IntValues.Count) { Debug.LogWarningFormat(_invalidOptionsWarning, property.propertyPath); } var field = new PopupField <int>(property.displayName, popup.IntValues, defaultIndex: 0, FormatInt, FormatInt); return(field.ConfigureProperty(property)); } else { Debug.LogErrorFormat(_invalidIntValuesError, property.propertyPath); } } else if (property.propertyType == SerializedPropertyType.Float) { if (popup.FloatValues != null && popup.FloatValues.Count > 0) { if (popup.Options != null && popup.Options.Count != popup.FloatValues.Count) { Debug.LogWarningFormat(_invalidOptionsWarning, property.propertyPath); } var field = new PopupField <float>(property.displayName, popup.FloatValues, defaultIndex: 0, FormatFloat, FormatFloat); return(field.ConfigureProperty(property)); } else { Debug.LogErrorFormat(_invalidFloatValuesError, property.propertyPath); } } else if (property.propertyType == SerializedPropertyType.String) { if (popup.Options != null && popup.Options.Count > 0) { var field = new PopupField <string>(property.displayName, popup.Options, 0); return(field.ConfigureProperty(property)); } else { Debug.LogErrorFormat(_invalidOptionsError, property.propertyPath); } } else { Debug.LogErrorFormat(_invalidTypeError, property.propertyPath); } return(new FieldContainer(property.displayName)); }
private VisualElement CreatePopup <T>(SerializedProperty property, PopupAttribute popupAttribute, List <T> defaultValues) { var popup = new PopupField <T>(); void setValues(List <T> values) => popup.SetValues(values); void setValuesWithOptions(PopupValues <T> options) => popup.SetValues(options.Values, options.Options); if (!ReflectionHelper.SetupValueSourceCallback(popupAttribute.ValuesSource, fieldInfo.DeclaringType, property, popup, defaultValues, popupAttribute.AutoUpdate, setValues)) { var defaultOptions = new PopupValues <T> { Values = defaultValues, Options = popupAttribute.Options }; if (!ReflectionHelper.SetupValueSourceCallback(popupAttribute.ValuesSource, fieldInfo.DeclaringType, property, popup, defaultOptions, popupAttribute.AutoUpdate, setValuesWithOptions)) { Debug.LogWarningFormat(_invalidValuesSourceError, property.propertyPath, nameof(PopupValues <T>), popupAttribute.ValuesSource); } } return(popup.ConfigureProperty(property)); }