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); }
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(); }
/* * 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); }
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); }
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); }
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(); }
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); }
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; }
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); }
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); }