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"; EditorDrawUtility.DrawHelpBox(warning, MessageType.Warning, logToConsole: true, context: PropertyUtility.GetTargetObject(property)); } }
public override void DrawProperty(SerializedProperty property) { EditorDrawUtility.DrawHeader(property); if (property.isArray) { if (!this.reorderableListsByPropertyName.ContainsKey(property.name)) { ReorderableList reorderableList = new ReorderableList(property.serializedObject, property, true, true, true, true) { drawHeaderCallback = (Rect rect) => { EditorGUI.LabelField(rect, string.Format("{0}: {1}", property.displayName, property.arraySize), EditorStyles.label); }, drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) => { var element = property.GetArrayElementAtIndex(index); rect.y += 2f; EditorGUI.PropertyField(new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight), element); } }; this.reorderableListsByPropertyName[property.name] = reorderableList; } this.reorderableListsByPropertyName[property.name].DoLayoutList(); } else { string warning = typeof(ReorderableListAttribute).Name + " can be used only on arrays or lists"; EditorDrawUtility.DrawHelpBox(warning, MessageType.Warning, logToConsole: true, context: PropertyUtility.GetTargetObject(property)); EditorDrawUtility.DrawPropertyField(property); } }
public override void ApplyPropertyMeta(SerializedProperty property, MetaAttribute metaAttribute) { InfoBoxAttribute infoBoxAttribute = (InfoBoxAttribute)metaAttribute; UnityEngine.Object target = PropertyUtility.GetTargetObject(property); if (!string.IsNullOrEmpty(infoBoxAttribute.VisibleIf)) { FieldInfo conditionField = ReflectionUtility.GetField(target, infoBoxAttribute.VisibleIf); if (conditionField != null && conditionField.FieldType == typeof(bool)) { if ((bool)conditionField.GetValue(target)) { this.DrawInfoBox(infoBoxAttribute.Text, infoBoxAttribute.Type); } return; } MethodInfo conditionMethod = ReflectionUtility.GetMethod(target, infoBoxAttribute.VisibleIf); if (conditionMethod != null && conditionMethod.ReturnType == typeof(bool) && conditionMethod.GetParameters().Length == 0) { if ((bool)conditionMethod.Invoke(target, null)) { this.DrawInfoBox(infoBoxAttribute.Text, infoBoxAttribute.Type); } return; } string warning = infoBoxAttribute.GetType().Name + " needs a valid boolean condition field or method name to work"; EditorDrawUtility.DrawHelpBox(warning, MessageType.Warning, logToConsole: true, context: PropertyUtility.GetTargetObject(property)); } else { this.DrawInfoBox(infoBoxAttribute.Text, infoBoxAttribute.Type); } }
public override void DrawProperty(SerializedProperty property) { EditorDrawUtility.DrawPropertyField(property); if (property.propertyType == SerializedPropertyType.ObjectReference) { if (property.objectReferenceValue != null) { Texture2D previewTexture = AssetPreview.GetAssetPreview(property.objectReferenceValue); if (previewTexture != null) { ShowAssetPreviewAttribute showAssetPreviewAttribute = PropertyUtility.GetAttribute <ShowAssetPreviewAttribute>(property); int width = Mathf.Clamp(showAssetPreviewAttribute.Width, 0, previewTexture.width); int height = Mathf.Clamp(showAssetPreviewAttribute.Height, 0, previewTexture.height); GUILayout.Label(previewTexture, GUILayout.MaxWidth(width), GUILayout.MaxHeight(height)); } else { string warning = property.name + " doesn't have an asset preview"; EditorDrawUtility.DrawHelpBox(warning, MessageType.Warning, logToConsole: true, context: PropertyUtility.GetTargetObject(property)); } } } else { string warning = property.name + " doesn't have an asset preview"; EditorDrawUtility.DrawHelpBox(warning, MessageType.Warning, logToConsole: true, context: PropertyUtility.GetTargetObject(property)); } }