Ejemplo n.º 1
0
        private static AssetStoreResponse ParseContent(AsyncHTTPClient job)
        {
            AssetStoreResponse assetStoreResponse = new AssetStoreResponse();

            assetStoreResponse.job  = job;
            assetStoreResponse.dict = null;
            assetStoreResponse.ok   = false;
            AsyncHTTPClient.State state = job.state;
            string text = job.text;

            if (!AsyncHTTPClient.IsSuccess(state))
            {
                Console.WriteLine(text);
                return(assetStoreResponse);
            }
            string text2;
            string str;

            assetStoreResponse.dict = AssetStoreClient.ParseJSON(text, out text2, out str);
            if (text2 == "error")
            {
                Debug.LogError("Request error (" + text2 + "): " + str);
                return(assetStoreResponse);
            }
            assetStoreResponse.ok = true;
            return(assetStoreResponse);
        }
Ejemplo n.º 2
0
        /*
         * Parse the HTTP response as a JSON string and into a AssetStoreResponse object.
         */
        static AssetStoreResponse ParseContent(IAsyncHTTPClient job)
        {
            AssetStoreResponse resp = new AssetStoreResponse();

            resp.job  = job;
            resp.dict = null;
            resp.ok   = false;
            AsyncHTTPClient.State state = job.state;
            string content = job.text;

            if (!AsyncHTTPClient.IsSuccess(state))
            {
                Console.WriteLine(content);
                // Debug.Log("Request error: " + content);
                return(resp); // abort
            }

            string status;
            string message;

            resp.dict = ParseJSON(content, out status, out message);
            if (status == "error")
            {
                Debug.LogError("Request error (" + status + "): " + message);
                return(resp);
            }
            resp.ok = true;
            return(resp);
        }
Ejemplo n.º 3
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();
        }
Ejemplo n.º 4
0
        private static IntPtr SubmitClientRequest(string tag, string url, string[] headers, string method, string data, AsyncHTTPClient.RequestDoneCallback doneDelegate, [DefaultValue("null")] AsyncHTTPClient.RequestProgressCallback progressDelegate)
        {
            IntPtr result;

            AsyncHTTPClient.INTERNAL_CALL_SubmitClientRequest(tag, url, headers, method, data, doneDelegate, progressDelegate, out result);
            return(result);
        }
Ejemplo n.º 5
0
        private static AssetStoreResponse ParseContent(AsyncHTTPClient job)
        {
            AssetStoreResponse assetStoreResponse = new AssetStoreResponse();

            assetStoreResponse.job  = job;
            assetStoreResponse.dict = (Dictionary <string, JSONValue>)null;
            assetStoreResponse.ok   = false;
            AsyncHTTPClient.State state = job.state;
            string text = job.text;

            if (!AsyncHTTPClient.IsSuccess(state))
            {
                Console.WriteLine(text);
                return(assetStoreResponse);
            }
            string status;
            string message;

            assetStoreResponse.dict = AssetStoreClient.ParseJSON(text, out status, out message);
            if (status == "error")
            {
                Debug.LogError((object)("Request error (" + status + "): " + message));
                return(assetStoreResponse);
            }
            assetStoreResponse.ok = true;
            return(assetStoreResponse);
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
        // 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);
        }
Ejemplo n.º 8
0
        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);
        }
Ejemplo n.º 9
0
        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);
        }
Ejemplo n.º 10
0
 public static void AbortSize(int size)
 {
     AsyncHTTPClient.AbortByTag("previewSize-" + size.ToString());
     foreach (KeyValuePair <string, CachedAssetStoreImage> pair in CachedAssetStoreImages)
     {
         if (pair.Value.requestedWidth == size)
         {
             pair.Value.requestedWidth = -1;
             pair.Value.client         = null;
         }
     }
 }
Ejemplo n.º 11
0
 public static void AbortSize(int size)
 {
     AsyncHTTPClient.AbortByTag("previewSize-" + size.ToString());
     foreach (KeyValuePair <string, AssetStorePreviewManager.CachedAssetStoreImage> current in AssetStorePreviewManager.CachedAssetStoreImages)
     {
         if (current.Value.requestedWidth == size)
         {
             current.Value.requestedWidth = -1;
             current.Value.client         = null;
         }
     }
 }
Ejemplo n.º 12
0
        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++;
                    }
                }
                else
                {
                    if (cached.image != null)
                    {
                        UnityEngine.Object.DestroyImmediate(cached.image);
                    }
                    cached.image = c.texture;
                    AssetStorePreviewManager.s_NeedsRepaint = true;
                    AssetStorePreviewManager.Instance.m_Success++;
                }
            };
            return(client);
        }
Ejemplo n.º 13
0
 public void Begin()
 {
     if (this.IsAborted())
     {
         this.state = AsyncHTTPClient.State.ABORTED;
     }
     else
     {
         if (this.m_Method == string.Empty)
         {
             this.m_Method = "GET";
         }
         this.m_Handle = AsyncHTTPClient.SubmitClientRequest(this.tag, this.m_ToUrl, this.header.Select <KeyValuePair <string, string>, string>((Func <KeyValuePair <string, string>, string>)(kv => string.Format("{0}: {1}", (object)kv.Key, (object)kv.Value))).ToArray <string>(), this.m_Method, this.m_FromData, new AsyncHTTPClient.RequestDoneCallback(this.Done), new AsyncHTTPClient.RequestProgressCallback(this.Progress));
     }
 }
Ejemplo n.º 14
0
 public void Begin()
 {
     if (this.IsAborted())
     {
         this.state = AsyncHTTPClient.State.ABORTED;
         return;
     }
     if (this.m_Method == string.Empty)
     {
         this.m_Method = "GET";
     }
     string[] headers = (from kv in this.header
                         select string.Format("{0}: {1}", kv.Key, kv.Value)).ToArray <string>();
     this.m_Handle = AsyncHTTPClient.SubmitClientRequest(this.tag, this.m_ToUrl, headers, this.m_Method, this.m_FromData, new AsyncHTTPClient.RequestDoneCallback(this.Done), new AsyncHTTPClient.RequestProgressCallback(this.Progress));
 }
 public static void AbortSize(int size)
 {
     AsyncHTTPClient.AbortByTag("previewSize-" + size.ToString());
     using (Dictionary <string, AssetStorePreviewManager.CachedAssetStoreImage> .Enumerator enumerator = AssetStorePreviewManager.CachedAssetStoreImages.GetEnumerator())
     {
         while (enumerator.MoveNext())
         {
             KeyValuePair <string, AssetStorePreviewManager.CachedAssetStoreImage> current = enumerator.Current;
             if (current.Value.requestedWidth == size)
             {
                 current.Value.requestedWidth = -1;
                 current.Value.client         = (AsyncHTTPClient)null;
             }
         }
     }
 }
        // Abort fetching all previews with the specified size
        public static void AbortSize(int size)
        {
            AsyncHTTPClient.AbortByTag("previewSize-" + size);

            // Mark any pending requests for that width in the cases as invalid
            // now that requests has been aborted.
            foreach (KeyValuePair <string, CachedAssetStoreImage> kv in AssetStorePreviewManager.CachedAssetStoreImages)
            {
                if (kv.Value.requestedWidth != size)
                {
                    continue;
                }
                kv.Value.requestedWidth = -1;
                kv.Value.client         = null;
            }
        }
Ejemplo n.º 17
0
 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();
     }
 }
Ejemplo n.º 18
0
        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();
        }
        private static AsyncHTTPClient SetupTextureDownload(CachedAssetStoreImage cached, string url, string tag)
        {
            AsyncHTTPClient client = new AsyncHTTPClient(url);

            cached.client       = client;
            client.tag          = tag;
            client.doneCallback = delegate(IAsyncHTTPClient c) {
                // Debug.Log("Got image " + EditorApplication.timeSinceStartup.ToString());
                cached.client = null;
                if (!client.IsSuccess())
                {
                    if (client.state != AsyncHTTPClient.State.ABORTED)
                    {
                        string err = "error " + client.text + " " + client.state + " '" + url + "'";
                        if (ObjectListArea.s_Debug)
                        {
                            Debug.LogError(err);
                        }
                        else
                        {
                            System.Console.Write(err);
                        }
                    }
                    else
                    {
                        Instance.m_Aborted++;
                    }
                    return;
                }

                // In the case of refetch because of resize first destroy the current image
                if (cached.image != null)
                {
                    Object.DestroyImmediate(cached.image);
                }

                cached.image = c.texture;

                s_NeedsRepaint = true;
                Instance.m_Success++;
            };
            return(client);
        }
        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();
        }
Ejemplo n.º 21
0
 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();
     }
 }
Ejemplo n.º 22
0
        /*
         * 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();
        }
Ejemplo n.º 23
0
 public void Abort()
 {
     this.state = AsyncHTTPClient.State.ABORTED;
     AsyncHTTPClient.AbortByHandle(this.m_Handle);
 }
Ejemplo n.º 24
0
 public static bool IsDone(AsyncHTTPClient.State state)
 {
   switch (state)
   {
     case AsyncHTTPClient.State.DONE_OK:
     case AsyncHTTPClient.State.DONE_FAILED:
     case AsyncHTTPClient.State.ABORTED:
     case AsyncHTTPClient.State.TIMEOUT:
       return true;
     default:
       return false;
   }
 }
Ejemplo n.º 25
0
 public static bool IsSuccess(AsyncHTTPClient.State state)
 {
   return state == AsyncHTTPClient.State.DONE_OK;
 }
Ejemplo n.º 26
0
 private void Done(AsyncHTTPClient.State status, int i_ResponseCode)
 {
   this.state = status;
   this.responseCode = i_ResponseCode;
   if (this.doneCallback != null)
     this.doneCallback(this);
   this.m_Handle = (IntPtr) 0;
 }
Ejemplo n.º 27
0
		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();
		}
Ejemplo n.º 28
0
		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();
		}
Ejemplo n.º 29
0
 private static IntPtr SubmitClientRequest(string tag, string url, string[] headers, string method, string data, AsyncHTTPClient.RequestDoneCallback doneDelegate)
 {
   AsyncHTTPClient.RequestProgressCallback progressDelegate = (AsyncHTTPClient.RequestProgressCallback) null;
   return AsyncHTTPClient.SubmitClientRequest(tag, url, headers, method, data, doneDelegate, progressDelegate);
 }
Ejemplo n.º 30
0
 public bool IsDone()
 {
     return(AsyncHTTPClient.IsDone(this.state));
 }
Ejemplo n.º 31
0
 private static extern IntPtr SubmitClientRequest(string tag, string url, string[] headers, string method, string data, AsyncHTTPClient.RequestDoneCallback doneDelegate, [DefaultValue("null")] AsyncHTTPClient.RequestProgressCallback progressDelegate);
        /**
         * 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);
        }
Ejemplo n.º 33
0
		private static AssetStoreResponse ParseContent(AsyncHTTPClient job)
		{
			AssetStoreResponse assetStoreResponse = new AssetStoreResponse();
			assetStoreResponse.job = job;
			assetStoreResponse.dict = null;
			assetStoreResponse.ok = false;
			AsyncHTTPClient.State state = job.state;
			string text = job.text;
			if (!AsyncHTTPClient.IsSuccess(state))
			{
				Console.WriteLine(text);
				return assetStoreResponse;
			}
			string text2;
			string str;
			assetStoreResponse.dict = AssetStoreClient.ParseJSON(text, out text2, out str);
			if (text2 == "error")
			{
				Debug.LogError("Request error (" + text2 + "): " + str);
				return assetStoreResponse;
			}
			assetStoreResponse.ok = true;
			return assetStoreResponse;
		}
		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);
		}
 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);
 }
 private static AssetStoreResponse ParseContent(AsyncHTTPClient job)
 {
   AssetStoreResponse assetStoreResponse = new AssetStoreResponse();
   assetStoreResponse.job = job;
   assetStoreResponse.dict = (Dictionary<string, JSONValue>) null;
   assetStoreResponse.ok = false;
   AsyncHTTPClient.State state = job.state;
   string text = job.text;
   if (!AsyncHTTPClient.IsSuccess(state))
   {
     Console.WriteLine(text);
     return assetStoreResponse;
   }
   string status;
   string message;
   assetStoreResponse.dict = AssetStoreClient.ParseJSON(text, out status, out message);
   if (status == "error")
   {
     Debug.LogError((object) ("Request error (" + status + "): " + message));
     return assetStoreResponse;
   }
   assetStoreResponse.ok = true;
   return assetStoreResponse;
 }
Ejemplo n.º 37
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);
        }
Ejemplo n.º 38
0
 private void Progress(AsyncHTTPClient.State status, int bytesDone, int bytesTotal)
 {
   this.state = status;
   if (this.statusCallback == null)
     return;
   this.statusCallback(status, bytesDone, bytesTotal);
 }
Ejemplo n.º 39
0
 private static IntPtr SubmitClientRequest(string tag, string url, string[] headers, string method, string data, AsyncHTTPClient.RequestDoneCallback doneDelegate)
 {
     AsyncHTTPClient.RequestProgressCallback progressDelegate = null;
     return(AsyncHTTPClient.SubmitClientRequest(tag, url, headers, method, data, doneDelegate, progressDelegate));
 }
Ejemplo n.º 40
0
		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;
		}
		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;
		}
Ejemplo n.º 42
0
		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 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();
		}