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, context: PropertyUtility.GetTargetObject(property));
                    }
                }
            }
            else
            {
                string warning = property.name + " doesn't have an asset preview";
                EditorDrawUtility.DrawHelpBox(warning, MessageType.Warning, context: PropertyUtility.GetTargetObject(property));
            }
        }
Beispiel #2
0
        public override void DrawProperty(SerializedProperty property)
        {
            EditorGUILayout.PropertyField(property, true);

            if (property.propertyType == SerializedPropertyType.ObjectReference)
            {
                if (property.objectReferenceValue != null)
                {
                    Texture2D previewTexture = AssetPreview.GetAssetPreview(property.objectReferenceValue);
                    if (previewTexture != null)
                    {
                        ShowAssetPreviewAttribute showAssetPreviewAttribute = PropertyUtility.GetAttributes <ShowAssetPreviewAttribute>(property)[0];
                        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
                    {
                        this.DrawWarningBox(property.name + " doesn't have an asset preview", property);
                    }
                }
            }
            else
            {
                this.DrawWarningBox(property.name + " doesn't have an asset preview", property);
            }
        }
Beispiel #3
0
        private Vector2 GetAssetPreviewSize(SerializedProperty property)
        {
            Texture2D previewTexture = GetAssetPreview(property);

            if (previewTexture == null)
            {
                return(Vector2.zero);
            }
            else
            {
                int targetWidth  = ShowAssetPreviewAttribute.DefaultWidth;
                int targetHeight = ShowAssetPreviewAttribute.DefaultHeight;

                ShowAssetPreviewAttribute showAssetPreviewAttribute = PropertyUtility.GetAttribute <ShowAssetPreviewAttribute>(property);
                if (showAssetPreviewAttribute != null)
                {
                    targetWidth  = showAssetPreviewAttribute.Width;
                    targetHeight = showAssetPreviewAttribute.Height;
                }

                int width  = Mathf.Clamp(targetWidth, 0, previewTexture.width);
                int height = Mathf.Clamp(targetHeight, 0, previewTexture.height);

                return(new Vector2(width, height));
            }
        }
Beispiel #4
0
        private void DrawPreview(SerializedProperty property, ShowAssetPreviewAttribute attribute)
        {
            if (property.propertyType == SerializedPropertyType.ObjectReference && property.objectReferenceValue != null)
            {
                Texture2D previewTexture = AssetPreview.GetAssetPreview(property.objectReferenceValue);
                if (previewTexture != null)
                {
                    var width  = Mathf.Clamp(attribute.Size, 0, previewTexture.width);
                    var height = Mathf.Clamp(attribute.Size, 0, previewTexture.height);

                    GUILayout.BeginVertical();
                    EditorDrawUtility.DrawWithAlign(attribute.Align, () =>
                    {
                        if (previewTexture != null)
                        {
                            GUILayout.Label(previewTexture, GUILayout.MaxWidth(width), GUILayout.MaxHeight(height));
                        }
                    });
                    GUILayout.EndVertical();
                }
                else
                {
                    EditorDrawUtility.DrawHelpBox($"{property.name} doesn't have an asset preview");
                }
            }
            else
            {
                EditorDrawUtility.DrawHelpBox($"{property.name} doesn't have an asset preview");
            }
        }
        private Vector2 GetAssetPreviewSize(SerializedProperty property, ShowAssetPreviewAttribute assetPreviewAttribute)
        {
            Texture2D previewTexture = GetAssetPreview(property);

            if (previewTexture == null)
            {
                return(Vector2.zero);
            }
            else
            {
                int width  = Mathf.Clamp(assetPreviewAttribute.Width, 0, previewTexture.width);
                int height = Mathf.Clamp(assetPreviewAttribute.Height, 0, previewTexture.height);

                return(new Vector2(width, height));
            }
        }
Beispiel #6
0
        private Rect DrawPreview(Rect rect, SerializedProperty property, ShowAssetPreviewAttribute attribute)
        {
            if (property.propertyType == SerializedPropertyType.ObjectReference && property.objectReferenceValue != null)
            {
                Texture2D previewTexture = AssetPreview.GetAssetPreview(property.objectReferenceValue);
                if (previewTexture != null)
                {
                    var textureRatio = (float)previewTexture.width / previewTexture.height;

                    var width  = Mathf.Clamp(attribute.Size, 0, previewTexture.width);
                    var height = Mathf.Clamp((int)(attribute.Size / textureRatio), 0, previewTexture.height);

                    switch (attribute.Align)
                    {
                    case Align.Left:
                        rect = new Rect(rect.x + 5, rect.y + 5, width, height);
                        break;

                    case Align.Center:
                        rect = new Rect(Screen.width / 2f - width / 2f, rect.y + 5, width, height);
                        break;

                    case Align.Right:
                        rect = new Rect(Screen.width - width - 29, rect.y + 5, width, height);
                        break;
                    }

                    GUI.Label(new Rect(rect.x, rect.y, rect.width, rect.height), previewTexture);
                }
                else
                {
                    EditorDrawUtility.DrawHelpBox(new Rect(rect.x, rect.y, rect.width, 40),
                                                  $"{property.name} doesn't have an asset preview");
                }
            }
            else
            {
                EditorDrawUtility.DrawHelpBox(new Rect(rect.x, rect.y, rect.width, 40), $"{property.name} doesn't have an asset preview");
            }

            return(rect);
        }