public override void ValidateProperty(SerializedProperty property) { MinValueAttribute minValueAttribute = PropertyUtility.GetAttribute <MinValueAttribute>(property); if (property.propertyType == SerializedPropertyType.Integer) { if (property.intValue < minValueAttribute.MinValue) { property.intValue = (int)minValueAttribute.MinValue; } } else if (property.propertyType == SerializedPropertyType.Float) { if (property.floatValue < minValueAttribute.MinValue) { property.floatValue = minValueAttribute.MinValue; } } else { string warning = minValueAttribute.GetType().Name + " can be used only on int or float fields"; EditorGUILayout.HelpBox(warning, MessageType.Warning); Debug.LogWarning(warning, PropertyUtility.GetTargetObject(property)); } }
public override void ValidateProperty(SerializedProperty property) { if (_cachedMinValueAttribute == null) { _cachedMinValueAttribute = PropertyUtility.GetAttribute <MinValueAttribute>(property); } MinValueAttribute minValueAttribute = _cachedMinValueAttribute; if (property.propertyType == SerializedPropertyType.Integer) { if (property.intValue < minValueAttribute.MinValue) { property.intValue = (int)minValueAttribute.MinValue; } } else if (property.propertyType == SerializedPropertyType.Float) { if (property.floatValue < minValueAttribute.MinValue) { property.floatValue = minValueAttribute.MinValue; } } else if (property.propertyType == SerializedPropertyType.Vector2) { property.vector2Value = Vector2.Max(property.vector2Value, new Vector2(minValueAttribute.MinValue, minValueAttribute.MinValue)); } else if (property.propertyType == SerializedPropertyType.Vector3) { property.vector3Value = Vector3.Max(property.vector3Value, new Vector3(minValueAttribute.MinValue, minValueAttribute.MinValue, minValueAttribute.MinValue)); } else if (property.propertyType == SerializedPropertyType.Vector4) { property.vector4Value = Vector4.Max(property.vector4Value, new Vector4(minValueAttribute.MinValue, minValueAttribute.MinValue, minValueAttribute.MinValue, minValueAttribute.MinValue)); } else if (property.propertyType == SerializedPropertyType.Vector2Int) { property.vector2IntValue = Vector2Int.Max(property.vector2IntValue, new Vector2Int((int)minValueAttribute.MinValue, (int)minValueAttribute.MinValue)); } else if (property.propertyType == SerializedPropertyType.Vector3Int) { property.vector3IntValue = Vector3Int.Max(property.vector3IntValue, new Vector3Int((int)minValueAttribute.MinValue, (int)minValueAttribute.MinValue, (int)minValueAttribute.MinValue)); } else { string warning = minValueAttribute.GetType().Name + " can be used only on int, float, Vector or VectorInt fields"; Debug.LogWarning(warning, property.serializedObject.targetObject); } }
public override void ValidateProperty(SerializedProperty property) { MinValueAttribute minValueAttribute = PropertyUtility.GetAttribute <MinValueAttribute>(property); if (property.propertyType == SerializedPropertyType.Integer) { if (property.intValue < minValueAttribute.MinValue) { property.intValue = (int)minValueAttribute.MinValue; } } else if (property.propertyType == SerializedPropertyType.Float) { if (property.floatValue < minValueAttribute.MinValue) { property.floatValue = minValueAttribute.MinValue; } } else { string warning = minValueAttribute.GetType().Name + " 只作用于整型和单精度浮点型字段!"; EditorDrawUtility.DrawHelpBox(warning, MessageType.Warning, context: PropertyUtility.GetTargetObject(property), logToConsole: false); } }
public override void ValidateProperty(SerializedProperty property, bool drawField) { MinValueAttribute minValueAttribute = PropertyUtility.GetAttribute <MinValueAttribute>(property); if (property.propertyType == SerializedPropertyType.Integer) { if (property.intValue < minValueAttribute.MinValue) { property.intValue = (int)minValueAttribute.MinValue; } } else if (property.propertyType == SerializedPropertyType.Float) { if (property.floatValue < minValueAttribute.MinValue) { property.floatValue = minValueAttribute.MinValue; } } else { string warning = minValueAttribute.GetType().Name + " can be used only on int or float fields"; EditorDrawUtility.DrawHelpBox(warning, MessageType.Warning, logToConsole: true, context: PropertyUtility.GetTargetObject(property)); } }