Пример #1
0
        public static Texture2D GetAssetPreviewFromPath(string path, FetchPreviewOptions previewOptions)
        {
            var tex = AssetDatabase.LoadAssetAtPath <Texture2D>(path);

            if (tex)
            {
                return(tex);
            }

            if (!previewOptions.HasFlag(FetchPreviewOptions.Large))
            {
                var assetType = AssetDatabase.GetMainAssetTypeAtPath(path);
                if (assetType == typeof(AudioClip))
                {
                    return(GetAssetThumbnailFromPath(path));
                }
            }

            var obj = AssetDatabase.LoadMainAssetAtPath(path);

            if (obj == null)
            {
                return(null);
            }
            return(GetAssetPreview(obj, previewOptions));
        }
Пример #2
0
        public static Texture2D GetAssetPreview(UnityEngine.Object obj, FetchPreviewOptions previewOptions)
        {
            var preview = AssetPreview.GetAssetPreview(obj);

            if (preview == null || previewOptions.HasFlag(FetchPreviewOptions.Large))
            {
                var largePreview = AssetPreview.GetMiniThumbnail(obj);
                if (preview == null || (largePreview != null && largePreview.width > preview.width))
                {
                    preview = largePreview;
                }
            }
            return(preview);
        }
Пример #3
0
        public static Texture2D GetAssetPreviewFromPath(string path, Vector2 previewSize, FetchPreviewOptions previewOptions)
        {
            var obj = AssetDatabase.LoadAssetAtPath <UnityEngine.Object>(path);

            if (obj == null)
            {
                return(null);
            }
            var preview = AssetPreview.GetAssetPreview(obj);

            if (preview == null || previewOptions.HasFlag(FetchPreviewOptions.Large))
            {
                var largePreview = AssetPreview.GetMiniThumbnail(obj);
                if (preview == null || (largePreview != null && largePreview.width > preview.width))
                {
                    preview = largePreview;
                }
            }
            return(preview);
        }
Пример #4
0
        private static Texture2D FetchPreview(SearchItem item, FetchPreviewOptions options)
        {
            if (!GlobalObjectId.TryParse(item.id, out var gid))
            {
                return(null);
            }

            if (options.HasFlag(FetchPreviewOptions.Large))
            {
                var go = GlobalObjectId.GlobalObjectIdentifierToObjectSlow(gid) as GameObject;
                if (go)
                {
                    return(AssetPreview.GetAssetPreview(go));
                }
            }

            var sourceAssetPath = AssetDatabase.GUIDToAssetPath(gid.assetGUID.ToString());

            return(AssetDatabase.GetCachedIcon(sourceAssetPath) as Texture2D);
        }
Пример #5
0
        private static Texture2D FetchPreview(SearchItem item, SearchContext context, Vector2 size, FetchPreviewOptions options)
        {
            if (!options.HasFlag(FetchPreviewOptions.Large))
            {
                return(null);
            }

            var doc = (AssetDocument)item.data;

            if (s_PackagesKey != null)
            {
                if (doc.productDetail == null)
                {
                    var productId = Convert.ToInt32(doc.id);
                    RequestProductDetailsInfo(new[] { productId }, (detail, error) =>
                    {
                        if (error != null || detail.results.Length == 0)
                        {
                            return;
                        }
                        doc.productDetail = detail.results[0];
                        doc.images        = new[] { doc.productDetail.mainImage.big }.Concat(
                            doc.productDetail.images.Where(img => img.type == "screenshot").Select(imgDesc => imgDesc.imageUrl)).ToArray();
                    });
                }
            }

            if (doc.productDetail?.images.Length > 0)
            {
                return(doc.lastPreview = FetchImage(doc.images, true, s_Previews) ?? doc.lastPreview);
            }

            if (doc.key_images.Length > 0)
            {
                return(doc.lastPreview = FetchImage(doc.key_images, true, s_Previews) ?? doc.lastPreview);
            }

            return(doc.lastPreview = FetchImage(doc.icon, true, s_Previews) ?? doc.lastPreview);
        }