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) { AssetPreviewAttribute showAssetPreviewAttribute = PropertyUtility.GetAttribute <AssetPreviewAttribute>(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 + " 没有一个资源预览!"; EditorDrawUtility.DrawHelpBox(warning, MessageType.Warning, context: PropertyUtility.GetTargetObject(property), logToConsole: false); } } } else { string warning = property.name + " 没有一个资源预览!"; EditorDrawUtility.DrawHelpBox(warning, MessageType.Warning, context: PropertyUtility.GetTargetObject(property), logToConsole: false); } }
// Make your own IMGUI based GUI for the property public override void OnGUI(Rect _position, SerializedProperty _property, GUIContent _label) { AssetPreviewAttribute _attribute = (AssetPreviewAttribute)attribute; _attribute.Fodlout = EditorGUIEnhanced.AssetPreviewField(_position, _property, _label, _attribute.Fodlout); }
/*************************** ******* METHODS ******* **************************/ // Specify how tall the GUI for this decorator is in pixels public override float GetPropertyHeight(SerializedProperty _property, GUIContent _label) { AssetPreviewAttribute _attribute = (AssetPreviewAttribute)attribute; return(EditorGUIUtilityEnhanced.GetAssetPreviewPropertyHeight(_property, _attribute.Fodlout, _attribute.Aspect)); }