UnityEditor.AssetPreview.GetAssetPreview C# (CSharp) Method

GetAssetPreview() public static method

Returns a preview texture for an asset.

public static GetAssetPreview ( Object asset ) : Texture2D
asset Object
return UnityEngine.Texture2D
        public static Texture2D GetAssetPreview(Object asset)
        {
            if (asset != null)
            {
                return GetAssetPreview(asset.GetInstanceID());
            }
            return null;
        }

Same methods

AssetPreview::GetAssetPreview ( int instanceID ) : Texture2D
AssetPreview::GetAssetPreview ( int instanceID, int clientID ) : Texture2D

Usage Example

コード例 #1
0
        private static void DrawObjectFieldLargeThumb(Rect position, int id, Object obj, GUIContent content)
        {
            GUIStyle thumbStyle = EditorStyles.objectFieldThumb;

            thumbStyle.Draw(position, GUIContent.none, id, DragAndDrop.activeControlID == id, position.Contains(Event.current.mousePosition));

            if (obj != null && !showMixedValue)
            {
                bool isCubemap = obj is Cubemap;
                bool isSprite  = obj is Sprite;
                Rect thumbRect = thumbStyle.padding.Remove(position);

                if (isCubemap || isSprite)
                {
                    Texture2D t2d = AssetPreview.GetAssetPreview(obj);
                    if (t2d != null)
                    {
                        if (isSprite || t2d.alphaIsTransparency)
                        {
                            DrawTextureTransparent(thumbRect, t2d);
                        }
                        else
                        {
                            DrawPreviewTexture(thumbRect, t2d);
                        }
                    }
                    else
                    {
                        // Preview not loaded -> Draw icon
                        thumbRect.x += (thumbRect.width - content.image.width) / 2f;
                        thumbRect.y += (thumbRect.height - content.image.width) / 2f;
                        GUIStyle.none.Draw(thumbRect, content.image, false, false, false, false);

                        // Keep repaint until the object field has a proper preview
                        HandleUtility.Repaint();
                    }
                }
                else
                {
                    // Draw texture
                    Texture2D t2d = content.image as Texture2D;
                    if (t2d != null && t2d.alphaIsTransparency)
                    {
                        DrawTextureTransparent(thumbRect, t2d);
                    }
                    else
                    {
                        DrawPreviewTexture(thumbRect, content.image);
                    }
                }
            }
            else
            {
                GUIStyle s2 = thumbStyle.name + "Overlay";
                BeginHandleMixedValueContentColor();

                s2.Draw(position, content, id);
                EndHandleMixedValueContentColor();
            }
            GUIStyle s3 = thumbStyle.name + "Overlay2";

            s3.Draw(position, s_Select, id);
        }
All Usage Examples Of UnityEditor.AssetPreview::GetAssetPreview