private static void ExpireCacheEntries()
 {
     while (CacheFull)
     {
         string key = null;
         CachedAssetStoreImage image = null;
         foreach (KeyValuePair <string, CachedAssetStoreImage> pair in CachedAssetStoreImages)
         {
             if ((image == null) || (image.lastUsed > pair.Value.lastUsed))
             {
                 image = pair.Value;
                 key   = pair.Key;
             }
         }
         CachedAssetStoreImages.Remove(key);
         AssetStorePreviewManager instance = Instance;
         instance.m_CacheRemove++;
         if (image == null)
         {
             Debug.LogError("Null entry found while removing cache entry");
             break;
         }
         if (image.client != null)
         {
             image.client.Abort();
             image.client = null;
         }
         if (image.image != null)
         {
             UnityEngine.Object.DestroyImmediate(image.image);
         }
     }
 }
Beispiel #2
0
        static void DownloadStaticPreview(AssetStoreAsset searchResult)
        {
            AsyncHTTPClient client = new AsyncHTTPClient(searchResult.staticPreviewURL);

            client.doneCallback = delegate(IAsyncHTTPClient c) {
                if (!client.IsSuccess())
                {
                    System.Console.WriteLine("Error downloading static preview: " + client.text);
                    // Debug.LogError("Error downloading static preview: " + client.text);
                    return;
                }

                // Need to put the texture through some scaling magic in order for the
                // TextureInspector to be able to show it.
                // TODO: This is a workaround and should be fixed.
                Texture2D srcTex = c.texture;
                Texture2D tex    = new Texture2D(srcTex.width, srcTex.height, TextureFormat.RGB24, false, true);
                AssetStorePreviewManager.ScaleImage(tex.width, tex.height, srcTex, tex, null);
                // tex.Compress(true);
                searchResult.previewImage = tex;

                Object.DestroyImmediate(srcTex);
                AssetStoreAssetInspector.Instance.Repaint();
            };
            client.Begin();
        }
        public static AssetStorePreviewManager.CachedAssetStoreImage TextureFromUrl(string url, string label, int textureSize, GUIStyle labelStyle, GUIStyle iconStyle, bool onlyCached)
        {
            if (string.IsNullOrEmpty(url))
            {
                return(AssetStorePreviewManager.Instance.m_DummyItem);
            }
            bool flag = true;

            AssetStorePreviewManager.CachedAssetStoreImage cachedAssetStoreImage;
            if (AssetStorePreviewManager.CachedAssetStoreImages.TryGetValue(url, out cachedAssetStoreImage))
            {
                cachedAssetStoreImage.lastUsed = EditorApplication.timeSinceStartup;
                bool flag2 = cachedAssetStoreImage.requestedWidth == textureSize;
                bool flag3 = cachedAssetStoreImage.image != null && cachedAssetStoreImage.image.width == textureSize;
                bool flag4 = cachedAssetStoreImage.requestedWidth == -1;
                if ((flag3 || flag2 || onlyCached) && !flag4)
                {
                    AssetStorePreviewManager.Instance.CacheHit++;
                    bool flag5 = cachedAssetStoreImage.client != null;
                    bool flag6 = cachedAssetStoreImage.label == null;
                    bool flag7 = flag5 || flag6;
                    bool flag8 = AssetStorePreviewManager.Instance.m_ConvertedThisTick > 1;
                    AssetStorePreviewManager.s_NeedsRepaint = (AssetStorePreviewManager.s_NeedsRepaint || flag8);
                    return((!flag7 && !flag8) ? AssetStorePreviewManager.RenderEntry(cachedAssetStoreImage, labelStyle, iconStyle) : cachedAssetStoreImage);
                }
                flag = false;
                if (AssetStorePreviewManager.Downloading >= 15)
                {
                    return((!(cachedAssetStoreImage.image == null)) ? cachedAssetStoreImage : AssetStorePreviewManager.Instance.m_DummyItem);
                }
            }
            else
            {
                if (onlyCached || AssetStorePreviewManager.Downloading >= 15)
                {
                    return(AssetStorePreviewManager.Instance.m_DummyItem);
                }
                cachedAssetStoreImage          = new AssetStorePreviewManager.CachedAssetStoreImage();
                cachedAssetStoreImage.image    = null;
                cachedAssetStoreImage.lastUsed = EditorApplication.timeSinceStartup;
            }
            if (cachedAssetStoreImage.image == null)
            {
                cachedAssetStoreImage.lastFetched = EditorApplication.timeSinceStartup;
            }
            cachedAssetStoreImage.requestedWidth = textureSize;
            cachedAssetStoreImage.label          = label;
            AsyncHTTPClient asyncHTTPClient = AssetStorePreviewManager.SetupTextureDownload(cachedAssetStoreImage, url, "previewSize-" + textureSize);

            AssetStorePreviewManager.ExpireCacheEntries();
            if (flag)
            {
                AssetStorePreviewManager.CachedAssetStoreImages.Add(url, cachedAssetStoreImage);
            }
            asyncHTTPClient.Begin();
            AssetStorePreviewManager.Instance.Requested++;
            return(cachedAssetStoreImage);
        }
            AssetStorePreviewManager.CachedAssetStoreImage GetIconForAssetStoreAsset(AssetStoreAsset assetStoreResource)
            {
                if (!string.IsNullOrEmpty(assetStoreResource.staticPreviewURL))
                {
                    m_Owner.LastScrollTime++;
                    AssetStorePreviewManager.CachedAssetStoreImage item = AssetStorePreviewManager.TextureFromUrl(assetStoreResource.staticPreviewURL, assetStoreResource.name, m_Owner.gridSize, s_Styles.resultsGridLabel, s_Styles.previewBg, false);
                    return(item);
                }

                return(null);
            }
 private static CachedAssetStoreImage RenderEntry(CachedAssetStoreImage cached, GUIStyle labelStyle, GUIStyle iconStyle)
 {
     if ((cached.label != null) && (cached.image != null))
     {
         Texture2D image = cached.image;
         cached.image = new Texture2D(cached.requestedWidth, cached.requestedWidth, TextureFormat.RGB24, false, true);
         ScaleImage(cached.requestedWidth, cached.requestedWidth, image, cached.image, iconStyle);
         UnityEngine.Object.DestroyImmediate(image);
         cached.label = null;
         AssetStorePreviewManager instance = Instance;
         instance.m_ConvertedThisTick++;
     }
     return(cached);
 }
        private static AssetStorePreviewManager.CachedAssetStoreImage RenderEntry(AssetStorePreviewManager.CachedAssetStoreImage cached, GUIStyle labelStyle, GUIStyle iconStyle)
        {
            if (cached.label == null || (Object)cached.image == (Object)null)
            {
                return(cached);
            }
            Texture2D image = cached.image;

            cached.image = new Texture2D(cached.requestedWidth, cached.requestedWidth, TextureFormat.RGB24, false, true);
            AssetStorePreviewManager.ScaleImage(cached.requestedWidth, cached.requestedWidth, image, cached.image, iconStyle);
            Object.DestroyImmediate((Object)image);
            cached.label = (string)null;
            ++AssetStorePreviewManager.Instance.m_ConvertedThisTick;
            return(cached);
        }
Beispiel #7
0
            virtual protected void DrawHeader(float yOffset, bool collapsable)
            {
                const int foldoutSpacing = 3;
                Rect      rect           = new Rect(0, GetHeaderYPosInScrollArea(yOffset), m_Owner.GetVisibleWidth(), kGroupSeparatorHeight - 1);

                DrawHeaderBackground(rect, yOffset == 0);

                // Draw the group toggle
                rect.x += 7;
                if (collapsable)
                {
                    bool oldVisible = Visible;
                    Visible = GUI.Toggle(rect, Visible, GUIContent.none, s_Styles.groupFoldout);
                    if (oldVisible ^ Visible)
                    {
                        visiblePreference = Visible;
                    }
                }

                // Draw title
                GUIStyle textStyle = s_Styles.groupHeaderLabel;

                if (collapsable)
                {
                    rect.x += s_Styles.groupFoldout.fixedWidth + foldoutSpacing;
                }
                rect.y += 1;
                if (!string.IsNullOrEmpty(m_GroupSeparatorTitle))
                {
                    GUI.Label(rect, m_GroupSeparatorTitle, textStyle);
                }

                if (s_Debug)
                {
                    Rect r2 = rect;
                    r2.x += 120;
                    GUI.Label(r2, AssetStorePreviewManager.StatsString());
                }

                rect.y -= 1;

                // Only draw counts if we have room for it
                if (m_Owner.GetVisibleWidth() > 150)
                {
                    DrawItemCount(rect);
                }
            }
Beispiel #8
0
 private static AssetStorePreviewManager.CachedAssetStoreImage RenderEntry(AssetStorePreviewManager.CachedAssetStoreImage cached, GUIStyle labelStyle, GUIStyle iconStyle)
 {
     AssetStorePreviewManager.CachedAssetStoreImage result;
     if (cached.label == null || cached.image == null)
     {
         result = cached;
     }
     else
     {
         Texture2D image = cached.image;
         cached.image = new Texture2D(cached.requestedWidth, cached.requestedWidth, TextureFormat.RGB24, false, true);
         AssetStorePreviewManager.ScaleImage(cached.requestedWidth, cached.requestedWidth, image, cached.image, iconStyle);
         UnityEngine.Object.DestroyImmediate(image);
         cached.label = null;
         AssetStorePreviewManager.Instance.m_ConvertedThisTick++;
         result = cached;
     }
     return(result);
 }
        private static void DownloadStaticPreview(AssetStoreAsset searchResult)
        {
            AsyncHTTPClient client = new AsyncHTTPClient(searchResult.staticPreviewURL);

            client.doneCallback = delegate(AsyncHTTPClient c)
            {
                if (!client.IsSuccess())
                {
                    Console.WriteLine("Error downloading static preview: " + client.text);
                    return;
                }
                Texture2D texture   = c.texture;
                Texture2D texture2D = new Texture2D(texture.width, texture.height, TextureFormat.RGB24, false, true);
                AssetStorePreviewManager.ScaleImage(texture2D.width, texture2D.height, texture, texture2D, null);
                searchResult.previewImage = texture2D;
                UnityEngine.Object.DestroyImmediate(texture);
                AssetStoreAssetInspector.Instance.Repaint();
            };
            client.Begin();
        }
		private static AssetStorePreviewManager.CachedAssetStoreImage RenderEntry(AssetStorePreviewManager.CachedAssetStoreImage cached, GUIStyle labelStyle, GUIStyle iconStyle)
		{
			if (cached.label == null || cached.image == null)
			{
				return cached;
			}
			Texture2D image = cached.image;
			cached.image = new Texture2D(cached.requestedWidth, cached.requestedWidth, TextureFormat.RGB24, false, true);
			AssetStorePreviewManager.ScaleImage(cached.requestedWidth, cached.requestedWidth, image, cached.image, iconStyle);
			UnityEngine.Object.DestroyImmediate(image);
			cached.label = null;
			AssetStorePreviewManager.Instance.m_ConvertedThisTick++;
			return cached;
		}
		private static AsyncHTTPClient SetupTextureDownload(AssetStorePreviewManager.CachedAssetStoreImage cached, string url, string tag)
		{
			AsyncHTTPClient client = new AsyncHTTPClient(url);
			cached.client = client;
			client.tag = tag;
			client.doneCallback = delegate(AsyncHTTPClient c)
			{
				cached.client = null;
				if (!client.IsSuccess())
				{
					if (client.state != AsyncHTTPClient.State.ABORTED)
					{
						string text = string.Concat(new string[]
						{
							"error ",
							client.text,
							" ",
							client.state.ToString(),
							" '",
							url,
							"'"
						});
						if (ObjectListArea.s_Debug)
						{
							Debug.LogError(text);
						}
						else
						{
							Console.Write(text);
						}
					}
					else
					{
						AssetStorePreviewManager.Instance.m_Aborted++;
					}
					return;
				}
				if (cached.image != null)
				{
					UnityEngine.Object.DestroyImmediate(cached.image);
				}
				cached.image = c.texture;
				AssetStorePreviewManager.s_NeedsRepaint = true;
				AssetStorePreviewManager.Instance.m_Success++;
			};
			return client;
		}
 private static AssetStorePreviewManager.CachedAssetStoreImage RenderEntry(AssetStorePreviewManager.CachedAssetStoreImage cached, GUIStyle labelStyle, GUIStyle iconStyle)
 {
   if (cached.label == null || (Object) cached.image == (Object) null)
     return cached;
   Texture2D image = cached.image;
   cached.image = new Texture2D(cached.requestedWidth, cached.requestedWidth, TextureFormat.RGB24, false, true);
   AssetStorePreviewManager.ScaleImage(cached.requestedWidth, cached.requestedWidth, image, cached.image, iconStyle);
   Object.DestroyImmediate((Object) image);
   cached.label = (string) null;
   ++AssetStorePreviewManager.Instance.m_ConvertedThisTick;
   return cached;
 }
 private static AsyncHTTPClient SetupTextureDownload(AssetStorePreviewManager.CachedAssetStoreImage cached, string url, string tag)
 {
   // ISSUE: object of a compiler-generated type is created
   // ISSUE: variable of a compiler-generated type
   AssetStorePreviewManager.\u003CSetupTextureDownload\u003Ec__AnonStorey5A downloadCAnonStorey5A = new AssetStorePreviewManager.\u003CSetupTextureDownload\u003Ec__AnonStorey5A();
   // ISSUE: reference to a compiler-generated field
   downloadCAnonStorey5A.cached = cached;
   // ISSUE: reference to a compiler-generated field
   downloadCAnonStorey5A.url = url;
   // ISSUE: reference to a compiler-generated field
   // ISSUE: reference to a compiler-generated field
   downloadCAnonStorey5A.client = new AsyncHTTPClient(downloadCAnonStorey5A.url);
   // ISSUE: reference to a compiler-generated field
   // ISSUE: reference to a compiler-generated field
   downloadCAnonStorey5A.cached.client = downloadCAnonStorey5A.client;
   // ISSUE: reference to a compiler-generated field
   downloadCAnonStorey5A.client.tag = tag;
   // ISSUE: reference to a compiler-generated field
   // ISSUE: reference to a compiler-generated method
   downloadCAnonStorey5A.client.doneCallback = new AsyncHTTPClient.DoneCallback(downloadCAnonStorey5A.\u003C\u003Em__9B);
   // ISSUE: reference to a compiler-generated field
   return downloadCAnonStorey5A.client;
 }