示例#1
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);
        }
        // Create a pending HTTP GET request to the server
        static AsyncHTTPClient CreateJSONRequest(string url, DoneCallback callback)
        {
            AsyncHTTPClient client = new AsyncHTTPClient(url);

            client.header["X-Unity-Session"] = ActiveOrUnauthSessionID + GetToken();
            client.doneCallback = WrapJsonCallback(callback);
            client.Begin();
            return(client);
        }
        private static AsyncHTTPClient CreateJSONRequestDelete(string url, AssetStoreClient.DoneCallback callback)
        {
            AsyncHTTPClient asyncHttpClient = new AsyncHTTPClient(url, "DELETE");

            asyncHttpClient.header["X-Unity-Session"] = AssetStoreClient.ActiveOrUnauthSessionID + AssetStoreClient.GetToken();
            asyncHttpClient.doneCallback = AssetStoreClient.WrapJsonCallback(callback);
            asyncHttpClient.Begin();
            return(asyncHttpClient);
        }
        private static AsyncHTTPClient CreateJSONRequestPost(string url, Dictionary <string, string> param, AssetStoreClient.DoneCallback callback)
        {
            AsyncHTTPClient asyncHttpClient = new AsyncHTTPClient(url);

            asyncHttpClient.header["X-Unity-Session"] = AssetStoreClient.ActiveOrUnauthSessionID + AssetStoreClient.GetToken();
            asyncHttpClient.postDictionary            = param;
            asyncHttpClient.doneCallback = AssetStoreClient.WrapJsonCallback(callback);
            asyncHttpClient.Begin();
            return(asyncHttpClient);
        }
        internal static void LoginWithCredentials(string username, string password, bool rememberMe, DoneLoginCallback callback)
        {
            if (sLoginState == LoginState.IN_PROGRESS)
            {
                Debug.LogError("Tried to login with credentials while already in progress of logging in");
                return;
            }
            sLoginState     = LoginState.IN_PROGRESS;
            RememberSession = rememberMe;
            string url = AssetStoreUrl + "/login?skip_terms=1";

            AssetStoreClient.sLoginErrorMessage = null;
            AsyncHTTPClient client = new AsyncHTTPClient(url.Replace("http://", "https://"));

            client.postData = "user="******"&pass="******"X-Unity-Session"] = kUnauthSessionID + GetToken();
            client.doneCallback = WrapLoginCallback(callback);
            client.Begin();
        }
 internal static void LoginWithCredentials(string username, string password, bool rememberMe, AssetStoreClient.DoneLoginCallback callback)
 {
     if (AssetStoreClient.sLoginState == AssetStoreClient.LoginState.IN_PROGRESS)
     {
         Debug.LogError((object)"Tried to login with credentials while already in progress of logging in");
     }
     else
     {
         AssetStoreClient.sLoginState     = AssetStoreClient.LoginState.IN_PROGRESS;
         AssetStoreClient.RememberSession = rememberMe;
         string str = AssetStoreClient.AssetStoreUrl + "/login?skip_terms=1";
         AssetStoreClient.sLoginErrorMessage = (string)null;
         AsyncHTTPClient asyncHttpClient = new AsyncHTTPClient(str.Replace("http://", "https://"));
         asyncHttpClient.postData = "user="******"&pass="******"X-Unity-Session"] = "26c4202eb475d02864b40827dfff11a14657aa41" + AssetStoreClient.GetToken();
         asyncHttpClient.doneCallback = AssetStoreClient.WrapLoginCallback(callback);
         asyncHttpClient.Begin();
     }
 }
        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();
        }
 internal static void LoginWithRememberedSession(AssetStoreClient.DoneLoginCallback callback)
 {
     if (AssetStoreClient.sLoginState == AssetStoreClient.LoginState.IN_PROGRESS)
     {
         Debug.LogError((object)"Tried to login with remembered session while already in progress of logging in");
     }
     else
     {
         AssetStoreClient.sLoginState = AssetStoreClient.LoginState.IN_PROGRESS;
         if (!AssetStoreClient.RememberSession)
         {
             AssetStoreClient.SavedSessionID = string.Empty;
         }
         string _toUrl = AssetStoreClient.AssetStoreUrl + "/login?skip_terms=1&reuse_session=" + AssetStoreClient.SavedSessionID;
         AssetStoreClient.sLoginErrorMessage = (string)null;
         AsyncHTTPClient asyncHttpClient = new AsyncHTTPClient(_toUrl);
         asyncHttpClient.header["X-Unity-Session"] = "26c4202eb475d02864b40827dfff11a14657aa41" + AssetStoreClient.GetToken();
         asyncHttpClient.doneCallback = AssetStoreClient.WrapLoginCallback(callback);
         asyncHttpClient.Begin();
     }
 }
        /*
         * Tries to login using a remembered session
         */
        internal static void LoginWithRememberedSession(DoneLoginCallback callback)
        {
            if (sLoginState == LoginState.IN_PROGRESS)
            {
                Debug.LogError("Tried to login with remembered session while already in progress of logging in");
                return;
            }
            sLoginState = LoginState.IN_PROGRESS;

            // Make sure the session is not present if we're not allowed to use it
            if (!RememberSession)
            {
                SavedSessionID = "";
            }

            string url = AssetStoreUrl + "/login?skip_terms=1&reuse_session=" + SavedSessionID;

            AssetStoreClient.sLoginErrorMessage = null;
            AsyncHTTPClient client = new AsyncHTTPClient(url);

            client.header["X-Unity-Session"] = kUnauthSessionID + GetToken();
            client.doneCallback = WrapLoginCallback(callback);
            client.Begin();
        }
		private static AsyncHTTPClient CreateJSONRequestDelete(string url, AssetStoreClient.DoneCallback callback)
		{
			AsyncHTTPClient asyncHTTPClient = new AsyncHTTPClient(url, "DELETE");
			asyncHTTPClient.header["X-Unity-Session"] = AssetStoreClient.ActiveOrUnauthSessionID + AssetStoreClient.GetToken();
			asyncHTTPClient.doneCallback = AssetStoreClient.WrapJsonCallback(callback);
			asyncHTTPClient.Begin();
			return asyncHTTPClient;
		}
 public static void AddAsset(AssetStoreAsset searchResult, Texture2D placeholderPreviewImage)
 {
     if (placeholderPreviewImage != null)
     {
         searchResult.previewImage = AssetStoreAssetSelection.ScaleImage(placeholderPreviewImage, 256, 256);
     }
     searchResult.previewInfo          = null;
     searchResult.previewBundleRequest = null;
     if (!string.IsNullOrEmpty(searchResult.dynamicPreviewURL) && searchResult.previewBundle == null)
     {
         searchResult.disposed = false;
         AsyncHTTPClient client = new AsyncHTTPClient(searchResult.dynamicPreviewURL);
         client.doneCallback = delegate(AsyncHTTPClient c)
         {
             if (!client.IsSuccess())
             {
                 Console.WriteLine("Error downloading dynamic preview: " + client.text);
                 searchResult.dynamicPreviewURL = null;
                 AssetStoreAssetSelection.DownloadStaticPreview(searchResult);
                 return;
             }
             AssetStoreAsset firstAsset = AssetStoreAssetSelection.GetFirstAsset();
             if (searchResult.disposed || firstAsset == null || searchResult.id != firstAsset.id)
             {
                 return;
             }
             try
             {
                 AssetBundleCreateRequest cr = AssetBundle.LoadFromMemoryAsync(c.bytes);
                 cr.DisableCompatibilityChecks();
                 searchResult.previewBundleRequest = cr;
                 EditorApplication.CallbackFunction callback = null;
                 double startTime = EditorApplication.timeSinceStartup;
                 callback = delegate
                 {
                     AssetStoreUtils.UpdatePreloading();
                     if (!cr.isDone)
                     {
                         double timeSinceStartup = EditorApplication.timeSinceStartup;
                         if (timeSinceStartup - startTime > 10.0)
                         {
                             EditorApplication.update = (EditorApplication.CallbackFunction)Delegate.Remove(EditorApplication.update, callback);
                             Console.WriteLine("Timed out fetch live preview bundle " + (searchResult.dynamicPreviewURL ?? "<n/a>"));
                         }
                         return;
                     }
                     EditorApplication.update = (EditorApplication.CallbackFunction)Delegate.Remove(EditorApplication.update, callback);
                     AssetStoreAsset firstAsset2 = AssetStoreAssetSelection.GetFirstAsset();
                     if (!searchResult.disposed && firstAsset2 != null && searchResult.id == firstAsset2.id)
                     {
                         searchResult.previewBundle = cr.assetBundle;
                         if (cr.assetBundle == null || cr.assetBundle.mainAsset == null)
                         {
                             searchResult.dynamicPreviewURL = null;
                             AssetStoreAssetSelection.DownloadStaticPreview(searchResult);
                         }
                         else
                         {
                             searchResult.previewAsset = searchResult.previewBundle.mainAsset;
                         }
                     }
                 };
                 EditorApplication.update = (EditorApplication.CallbackFunction)Delegate.Combine(EditorApplication.update, callback);
             }
             catch (Exception ex)
             {
                 Console.Write(ex.Message);
                 Debug.Log(ex.Message);
             }
         };
         client.Begin();
     }
     else if (!string.IsNullOrEmpty(searchResult.staticPreviewURL))
     {
         AssetStoreAssetSelection.DownloadStaticPreview(searchResult);
     }
     AssetStoreAssetSelection.AddAssetInternal(searchResult);
     AssetStoreAssetSelection.RefreshFromServer(null);
 }
		internal static void LoginWithCredentials(string username, string password, bool rememberMe, AssetStoreClient.DoneLoginCallback callback)
		{
			if (AssetStoreClient.sLoginState == AssetStoreClient.LoginState.IN_PROGRESS)
			{
				Debug.LogError("Tried to login with credentials while already in progress of logging in");
				return;
			}
			AssetStoreClient.sLoginState = AssetStoreClient.LoginState.IN_PROGRESS;
			AssetStoreClient.RememberSession = rememberMe;
			string text = AssetStoreClient.AssetStoreUrl + "/login?skip_terms=1";
			AssetStoreClient.sLoginErrorMessage = null;
			AsyncHTTPClient asyncHTTPClient = new AsyncHTTPClient(text.Replace("http://", "https://"));
			asyncHTTPClient.postData = "user="******"&pass="******"X-Unity-Session"] = "26c4202eb475d02864b40827dfff11a14657aa41" + AssetStoreClient.GetToken();
			asyncHTTPClient.doneCallback = AssetStoreClient.WrapLoginCallback(callback);
			asyncHTTPClient.Begin();
		}
		internal static void LoginWithRememberedSession(AssetStoreClient.DoneLoginCallback callback)
		{
			if (AssetStoreClient.sLoginState == AssetStoreClient.LoginState.IN_PROGRESS)
			{
				Debug.LogError("Tried to login with remembered session while already in progress of logging in");
				return;
			}
			AssetStoreClient.sLoginState = AssetStoreClient.LoginState.IN_PROGRESS;
			if (!AssetStoreClient.RememberSession)
			{
				AssetStoreClient.SavedSessionID = string.Empty;
			}
			string toUrl = AssetStoreClient.AssetStoreUrl + "/login?skip_terms=1&reuse_session=" + AssetStoreClient.SavedSessionID;
			AssetStoreClient.sLoginErrorMessage = null;
			AsyncHTTPClient asyncHTTPClient = new AsyncHTTPClient(toUrl);
			asyncHTTPClient.header["X-Unity-Session"] = "26c4202eb475d02864b40827dfff11a14657aa41" + AssetStoreClient.GetToken();
			asyncHTTPClient.doneCallback = AssetStoreClient.WrapLoginCallback(callback);
			asyncHTTPClient.Begin();
		}
		private static AsyncHTTPClient CreateJSONRequestPost(string url, Dictionary<string, string> param, AssetStoreClient.DoneCallback callback)
		{
			AsyncHTTPClient asyncHTTPClient = new AsyncHTTPClient(url);
			asyncHTTPClient.header["X-Unity-Session"] = AssetStoreClient.ActiveOrUnauthSessionID + AssetStoreClient.GetToken();
			asyncHTTPClient.postDictionary = param;
			asyncHTTPClient.doneCallback = AssetStoreClient.WrapJsonCallback(callback);
			asyncHTTPClient.Begin();
			return asyncHTTPClient;
		}
示例#16
0
        public static void AddAsset(AssetStoreAsset searchResult, Texture2D placeholderPreviewImage)
        {
            if (placeholderPreviewImage != null)
            {
                searchResult.previewImage = ScaleImage(placeholderPreviewImage, 256, 256);
            }

            searchResult.previewInfo          = null;
            searchResult.previewBundleRequest = null;

            // Dynamic previews is asset bundles to be displayed in
            // the inspector. Static previews are images.
            if (!string.IsNullOrEmpty(searchResult.dynamicPreviewURL) && searchResult.previewBundle == null)
            {
                // Debug.Log("dyn url " + searchResult.disposed.ToString() + " " + searchResult.dynamicPreviewURL);
                searchResult.disposed = false;
                // searchResult.previewBundle = AssetBundle.CreateFromFile("/users/jonasd/test.unity3d");
                // searchResult.previewAsset = searchResult.previewBundle.mainAsset;

                // Request the asset bundle data from the url and register a callback
                AsyncHTTPClient client = new AsyncHTTPClient(searchResult.dynamicPreviewURL);
                client.doneCallback = delegate(IAsyncHTTPClient c) {
                    if (!client.IsSuccess())
                    {
                        System.Console.WriteLine("Error downloading dynamic preview: " + client.text);
                        // Try the static preview instead
                        searchResult.dynamicPreviewURL = null;
                        DownloadStaticPreview(searchResult);
                        return;
                    }

                    // We only suppport one asset so grab the first one
                    AssetStoreAsset sel = GetFirstAsset();

                    // Make sure that the selection hasn't changed meanwhile
                    if (searchResult.disposed || sel == null || searchResult.id != sel.id)
                    {
                        //Debug.Log("dyn disposed " + searchResult.disposed.ToString() + " " + (sel == null ? "null" : sel.id.ToString()) + " " + searchResult.id.ToString());
                        return;
                    }

                    // Go create the asset bundle in memory from the binary blob asynchronously
                    try
                    {
                        AssetBundleCreateRequest cr = AssetBundle.LoadFromMemoryAsync(c.bytes);

                        // Workaround: Don't subject the bundle to the usual compatibility checks.  We want
                        // to stay compatible with previews created in prior versions of Unity and with the
                        // stuff we put into previews, we should generally be able to still load the content
                        // in the editor.
                        cr.DisableCompatibilityChecks();

                        searchResult.previewBundleRequest = cr;
                        EditorApplication.CallbackFunction callback = null;

                        // The callback will be called each tick and check if the asset bundle is ready
                        double startTime = EditorApplication.timeSinceStartup;
                        callback = () => {
                            AssetStoreUtils.UpdatePreloading();

                            if (!cr.isDone)
                            {
                                double nowTime = EditorApplication.timeSinceStartup;
                                if (nowTime - startTime > 10.0)
                                {
                                    // Timeout. Stop polling
                                    EditorApplication.update -= callback;
                                    System.Console.WriteLine("Timed out fetch live preview bundle " +
                                                             (searchResult.dynamicPreviewURL ?? "<n/a>"));
                                    // Debug.Log("Not done Timed out" + cr.progress.ToString() );
                                }
                                else
                                {
                                    // Debug.Log("Not done " + cr.progress.ToString() );
                                }
                                return;
                            }

                            // Done cooking. Stop polling.
                            EditorApplication.update -= callback;

                            // Make sure that the selection hasn't changed meanwhile
                            AssetStoreAsset sel2 = GetFirstAsset();
                            if (searchResult.disposed || sel2 == null || searchResult.id != sel2.id)
                            {
                                // No problem. Just ignore.
                                // Debug.Log("dyn late disposed " + searchResult.disposed.ToString() + " " + (sel2 == null ? "null" : sel2.id.ToString()) + " " + searchResult.id.ToString());
                            }
                            else
                            {
                                searchResult.previewBundle = cr.assetBundle;
#pragma warning disable 618
                                if (cr.assetBundle == null || cr.assetBundle.mainAsset == null)
                                {
                                    // Failed downloading live preview. Fallback to static
                                    searchResult.dynamicPreviewURL = null;
                                    DownloadStaticPreview(searchResult);
                                }
                                else
                                {
                                    searchResult.previewAsset = searchResult.previewBundle.mainAsset;
                                }
#pragma warning restore 618
                            }
                        };

                        EditorApplication.update += callback;
                    }
                    catch (System.Exception e)
                    {
                        System.Console.Write(e.Message);
                        Debug.Log(e.Message);
                    }
                };
                client.Begin();
            }
            else if (!string.IsNullOrEmpty(searchResult.staticPreviewURL))
            {
                DownloadStaticPreview(searchResult);
            }

            // searchResult.previewBundle = null;
            AddAssetInternal(searchResult);

            RefreshFromServer(null);
        }
		public static void AddAsset(AssetStoreAsset searchResult, Texture2D placeholderPreviewImage)
		{
			if (placeholderPreviewImage != null)
			{
				searchResult.previewImage = AssetStoreAssetSelection.ScaleImage(placeholderPreviewImage, 256, 256);
			}
			searchResult.previewInfo = null;
			searchResult.previewBundleRequest = null;
			if (!string.IsNullOrEmpty(searchResult.dynamicPreviewURL) && searchResult.previewBundle == null)
			{
				searchResult.disposed = false;
				AsyncHTTPClient client = new AsyncHTTPClient(searchResult.dynamicPreviewURL);
				client.doneCallback = delegate(AsyncHTTPClient c)
				{
					if (!client.IsSuccess())
					{
						Console.WriteLine("Error downloading dynamic preview: " + client.text);
						searchResult.dynamicPreviewURL = null;
						AssetStoreAssetSelection.DownloadStaticPreview(searchResult);
						return;
					}
					AssetStoreAsset firstAsset = AssetStoreAssetSelection.GetFirstAsset();
					if (searchResult.disposed || firstAsset == null || searchResult.id != firstAsset.id)
					{
						return;
					}
					try
					{
						AssetBundleCreateRequest cr = AssetBundle.CreateFromMemory(c.bytes);
						cr.DisableCompatibilityChecks();
						searchResult.previewBundleRequest = cr;
						EditorApplication.CallbackFunction callback = null;
						double startTime = EditorApplication.timeSinceStartup;
						callback = delegate
						{
							AssetStoreUtils.UpdatePreloading();
							if (!cr.isDone)
							{
								double timeSinceStartup = EditorApplication.timeSinceStartup;
								if (timeSinceStartup - startTime > 10.0)
								{
									EditorApplication.update = (EditorApplication.CallbackFunction)Delegate.Remove(EditorApplication.update, callback);
									Console.WriteLine("Timed out fetch live preview bundle " + (searchResult.dynamicPreviewURL ?? "<n/a>"));
								}
								return;
							}
							EditorApplication.update = (EditorApplication.CallbackFunction)Delegate.Remove(EditorApplication.update, callback);
							AssetStoreAsset firstAsset2 = AssetStoreAssetSelection.GetFirstAsset();
							if (!searchResult.disposed && firstAsset2 != null && searchResult.id == firstAsset2.id)
							{
								searchResult.previewBundle = cr.assetBundle;
								if (cr.assetBundle == null || cr.assetBundle.mainAsset == null)
								{
									searchResult.dynamicPreviewURL = null;
									AssetStoreAssetSelection.DownloadStaticPreview(searchResult);
								}
								else
								{
									searchResult.previewAsset = searchResult.previewBundle.mainAsset;
								}
							}
						};
						EditorApplication.update = (EditorApplication.CallbackFunction)Delegate.Combine(EditorApplication.update, callback);
					}
					catch (Exception ex)
					{
						Console.Write(ex.Message);
						Debug.Log(ex.Message);
					}
				};
				client.Begin();
			}
			else
			{
				if (!string.IsNullOrEmpty(searchResult.staticPreviewURL))
				{
					AssetStoreAssetSelection.DownloadStaticPreview(searchResult);
				}
			}
			AssetStoreAssetSelection.AddAssetInternal(searchResult);
			AssetStoreAssetSelection.RefreshFromServer(null);
		}
        /**
         * Return a texture from a url that points to an image resource
         *
         * This method does not block but queues a request to fetch the image and return null.
         * When the image has been fetched this method will return the image texture downloaded.
         */
        public static CachedAssetStoreImage TextureFromUrl(string url, string label, int textureSize, GUIStyle labelStyle, GUIStyle iconStyle, bool onlyCached)
        {
            if (string.IsNullOrEmpty(url))
            {
                return(Instance.m_DummyItem);
            }

            CachedAssetStoreImage cached;
            bool newentry = true;

            if (CachedAssetStoreImages.TryGetValue(url, out cached))
            {
                cached.lastUsed = EditorApplication.timeSinceStartup;

                // Refetch the image if the size has changed and is not in the progress of being fetched
                bool refetchInitiated = cached.requestedWidth == textureSize;
                bool correctSize      = cached.image != null && cached.image.width == textureSize;

                bool cacheRequestAborted = cached.requestedWidth == -1;

                if ((correctSize || refetchInitiated || onlyCached) && !cacheRequestAborted)
                {
                    Instance.CacheHit++;

                    // Use cached image (that may be null) if we're in progress of fetching the image
                    // or if we have rendered the images correctly
                    //return cached;
                    bool fetchingImage       = cached.client != null;
                    bool labelDrawn          = cached.label == null;
                    bool valid               = fetchingImage || labelDrawn;
                    bool convPerTickExceeded = Instance.m_ConvertedThisTick > kMaxConvertionsPerTick;
                    s_NeedsRepaint = s_NeedsRepaint || convPerTickExceeded;
                    return((valid || convPerTickExceeded) ?
                           cached :
                           RenderEntry(cached, labelStyle, iconStyle));
                }
                //Debug.Log(string.Format("Found {0} {1} {2} {3}", correctSize, refetchInitiated, onlyCached, cacheRequestAborted));
                newentry = false;
                if (Downloading >= kMaxConcurrentDownloads)
                {
                    return(cached.image == null ? Instance.m_DummyItem : cached);
                }
            }
            else
            {
                if (onlyCached || Downloading >= kMaxConcurrentDownloads)
                {
                    return(Instance.m_DummyItem);
                }
                cached          = new CachedAssetStoreImage();
                cached.image    = null;
                cached.lastUsed = EditorApplication.timeSinceStartup;
                //Debug.Log("url is " + textureSize.ToString() + " " + url);
            }

            // Only set fetch time when there is not image in order to use it for
            // fading in the image when it becomes available
            if (cached.image == null)
            {
                cached.lastFetched = EditorApplication.timeSinceStartup;
            }

            cached.requestedWidth = textureSize;
            cached.label          = label;

            AsyncHTTPClient client = null;

            client = SetupTextureDownload(cached, url, "previewSize-" + textureSize);

            ExpireCacheEntries();

            if (newentry)
            {
                CachedAssetStoreImages.Add(url, cached);
            }

            client.Begin();

            Instance.Requested++;
            return(cached);
        }
		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();
		}