// Callback for curl to call public void OnDownloadProgress(string id, string message, int bytes, int total) { AssetStoreAsset activeAsset = AssetStoreAssetSelection.GetFirstAsset(); if (activeAsset == null) { return; } AssetStoreAsset.PreviewInfo info = activeAsset.previewInfo; if (info == null) { return; } if (activeAsset.packageID.ToString() != id) { return; } if ((message == "downloading" || message == "connecting") && !OfflineNoticeEnabled) { info.downloadProgress = (float)bytes / (float)total; } else { info.downloadProgress = -1f; } Repaint(); }
private void InitiateBuySelected(bool firstAttempt) { AssetStoreAsset firstAsset = AssetStoreAssetSelection.GetFirstAsset(); if (firstAsset == null) { EditorUtility.DisplayDialog("No asset selected", "Please select asset before buying a package", "ok"); } else if (AssetStoreAssetInspector.paymentAvailability == AssetStoreAssetInspector.PaymentAvailability.AnonymousUser) { if (AssetStoreClient.LoggedIn()) { AssetStoreAssetSelection.RefreshFromServer(delegate { this.InitiateBuySelected(false); }); } else if (firstAttempt) { this.LoginAndInitiateBuySelected(); } } else if (AssetStoreAssetInspector.paymentAvailability == AssetStoreAssetInspector.PaymentAvailability.ServiceDisabled) { if (firstAsset.previewInfo == null) { return; } AssetStore.Open(string.Format("content/{0}/directpurchase", firstAsset.packageID)); } else if (AssetStoreAssetInspector.paymentAvailability == AssetStoreAssetInspector.PaymentAvailability.BasketNotEmpty) { if (firstAsset.previewInfo == null) { return; } if (firstAttempt) { AssetStoreAssetSelection.RefreshFromServer(delegate { this.InitiateBuySelected(false); }); } else { AssetStore.Open(string.Format("content/{0}/basketpurchase", firstAsset.packageID)); } } else { AssetStoreInstaBuyWindow.ShowAssetStoreInstaBuyWindow(firstAsset, AssetStoreAssetInspector.s_PurchaseMessage, AssetStoreAssetInspector.s_PaymentMethodCard, AssetStoreAssetInspector.s_PaymentMethodExpire, AssetStoreAssetInspector.s_PriceText); } }
public override void OnPreviewSettings() { AssetStoreAsset firstAsset = AssetStoreAssetSelection.GetFirstAsset(); if (firstAsset != null) { EditorWrapper previewEditor = this.previewEditor; if (previewEditor != null && firstAsset.HasLivePreview) { previewEditor.OnPreviewSettings(); } } }
public override string GetInfoString() { EditorWrapper previewEditor = this.previewEditor; AssetStoreAsset firstAsset = AssetStoreAssetSelection.GetFirstAsset(); if (firstAsset == null) { return("No item selected"); } if ((previewEditor != null) && firstAsset.HasLivePreview) { return(previewEditor.GetInfoString()); } return(string.Empty); }
public override void OnPreviewSettings() { AssetStoreAsset firstAsset = AssetStoreAssetSelection.GetFirstAsset(); if (firstAsset == null) { return; } EditorWrapper previewEditor = this.previewEditor; if (previewEditor == null || !firstAsset.HasLivePreview) { return; } previewEditor.OnPreviewSettings(); }
public override void OnPreviewSettings() { AssetStoreAsset asset = AssetStoreAssetSelection.GetFirstAsset(); if (asset == null) { return; } EditorWrapper editor = previewEditor; if (editor != null && asset.HasLivePreview) { editor.OnPreviewSettings(); } }
public void OnDownloadProgress(string id, string message, int bytes, int total) { AssetStoreAsset firstAsset = AssetStoreAssetSelection.GetFirstAsset(); if (firstAsset == null) { return; } AssetStoreAsset.PreviewInfo previewInfo = firstAsset.previewInfo; if (previewInfo == null || firstAsset.packageID.ToString() != id) { return; } previewInfo.downloadProgress = !(message == "downloading") && !(message == "connecting") || AssetStoreAssetInspector.OfflineNoticeEnabled ? -1f : (float)bytes / (float)total; this.Repaint(); }
public void Update() { AssetStoreAsset firstAsset = AssetStoreAssetSelection.GetFirstAsset(); bool flag = firstAsset != null && firstAsset.previewInfo != null && (firstAsset.previewInfo.buildProgress >= 0f || firstAsset.previewInfo.downloadProgress >= 0f); if ((firstAsset == null && this.lastAssetID != 0) || (firstAsset != null && this.lastAssetID != firstAsset.id) || flag) { this.lastAssetID = ((firstAsset != null) ? firstAsset.id : 0); base.Repaint(); } if (firstAsset != null && firstAsset.previewBundle != null) { firstAsset.previewBundle.Unload(false); firstAsset.previewBundle = null; base.Repaint(); } }
public override string GetInfoString() { EditorWrapper editor = previewEditor; AssetStoreAsset a = AssetStoreAssetSelection.GetFirstAsset(); if (a == null) { return("No item selected"); } if (editor != null && a.HasLivePreview) { return(editor.GetInfoString()); } return(""); }
public void Update() { AssetStoreAsset firstAsset = AssetStoreAssetSelection.GetFirstAsset(); bool flag = firstAsset != null && firstAsset.previewInfo != null && ((double)firstAsset.previewInfo.buildProgress >= 0.0 || (double)firstAsset.previewInfo.downloadProgress >= 0.0); if (firstAsset == null && this.lastAssetID != 0 || firstAsset != null && this.lastAssetID != firstAsset.id || flag) { this.lastAssetID = firstAsset != null ? firstAsset.id : 0; this.Repaint(); } if (firstAsset == null || !((Object)firstAsset.previewBundle != (Object)null)) { return; } firstAsset.previewBundle.Unload(false); firstAsset.previewBundle = (AssetBundle)null; this.Repaint(); }
public override void OnInteractivePreviewGUI(Rect r, GUIStyle background) { EditorWrapper previewEditor = this.previewEditor; if (previewEditor != null) { previewEditor.OnInteractivePreviewGUI(r, background); } AssetStoreAsset firstAsset = AssetStoreAssetSelection.GetFirstAsset(); if (firstAsset != null && !firstAsset.HasLivePreview && !string.IsNullOrEmpty(firstAsset.dynamicPreviewURL)) { GUIContent statusWheel = AssetStoreAssetInspector.StatusWheel; r.y += (r.height - (float)statusWheel.image.height) / 2f; r.x += (r.width - (float)statusWheel.image.width) / 2f; GUI.Label(r, AssetStoreAssetInspector.StatusWheel); base.Repaint(); } }
public override string GetInfoString() { EditorWrapper previewEditor = this.previewEditor; AssetStoreAsset firstAsset = AssetStoreAssetSelection.GetFirstAsset(); string result; if (firstAsset == null) { result = "No item selected"; } else if (previewEditor != null && firstAsset.HasLivePreview) { result = previewEditor.GetInfoString(); } else { result = ""; } return(result); }
public override void OnInteractivePreviewGUI(Rect r, GUIStyle background) { EditorWrapper editor = previewEditor; if (editor != null) { editor.OnInteractivePreviewGUI(r, background); } // If the live preview is not available yes the show a spinner AssetStoreAsset a = AssetStoreAssetSelection.GetFirstAsset(); if (a != null && !a.HasLivePreview && !string.IsNullOrEmpty(a.dynamicPreviewURL)) { GUIContent c = StatusWheel; r.y += (r.height - c.image.height) / 2f; r.x += (r.width - c.image.width) / 2f; GUI.Label(r, StatusWheel); Repaint(); } }
public void OnDownloadProgress(string id, string message, int bytes, int total) { AssetStoreAsset firstAsset = AssetStoreAssetSelection.GetFirstAsset(); if (firstAsset != null) { AssetStoreAsset.PreviewInfo previewInfo = firstAsset.previewInfo; if (previewInfo != null) { if (!(firstAsset.packageID.ToString() != id)) { if ((message == "downloading" || message == "connecting") && !AssetStoreAssetInspector.OfflineNoticeEnabled) { previewInfo.downloadProgress = (float)bytes / (float)total; } else { previewInfo.downloadProgress = -1f; } base.Repaint(); } } } }
public void Update() { // Repaint if asset has changed. // This has to be done here because the .target is always set to // this inspector when inspecting asset store assets. AssetStoreAsset a = AssetStoreAssetSelection.GetFirstAsset(); bool hasProgress = a != null && a.previewInfo != null && (a.previewInfo.buildProgress >= 0f || a.previewInfo.downloadProgress >= 0f); if ((a == null && lastAssetID != 0) || (a != null && lastAssetID != a.id) || hasProgress) { lastAssetID = a == null ? 0 : a.id; Repaint(); } // Repaint when the main asset of a possibly downloaded bundle is ready for preview if (a != null && a.previewBundle != null) { a.previewBundle.Unload(false); a.previewBundle = null; Repaint(); } }
public override void OnInspectorGUI() { if (AssetStoreAssetInspector.styles == null) { AssetStoreAssetInspector.s_SharedAssetStoreAssetInspector = this; AssetStoreAssetInspector.styles = new AssetStoreAssetInspector.Styles(); } AssetStoreAsset firstAsset = AssetStoreAssetSelection.GetFirstAsset(); AssetStoreAsset.PreviewInfo previewInfo = null; if (firstAsset != null) { previewInfo = firstAsset.previewInfo; } if (firstAsset != null) { base.target.name = string.Format("Asset Store: {0}", firstAsset.name); } else { base.target.name = "Asset Store"; } EditorGUILayout.BeginVertical(new GUILayoutOption[0]); bool enabled = GUI.enabled; GUI.enabled = (firstAsset != null && firstAsset.packageID != 0); if (AssetStoreAssetInspector.OfflineNoticeEnabled) { Color color = GUI.color; GUI.color = Color.yellow; GUILayout.Label("Network is offline", new GUILayoutOption[0]); GUI.color = color; } if (firstAsset != null) { string label = (firstAsset.className != null) ? firstAsset.className.Split(new char[] { ' ' }, 2)[0] : ""; bool flag = firstAsset.id == -firstAsset.packageID; if (flag) { label = "Package"; } if (firstAsset.HasLivePreview) { label = firstAsset.Preview.GetType().Name; } EditorGUILayout.LabelField("Type", label, new GUILayoutOption[0]); if (flag) { this.packageInfoShown = true; } else { EditorGUILayout.Separator(); this.packageInfoShown = EditorGUILayout.Foldout(this.packageInfoShown, "Part of package", true); } if (this.packageInfoShown) { EditorGUILayout.LabelField("Name", (previewInfo != null) ? previewInfo.packageName : "-", new GUILayoutOption[0]); EditorGUILayout.LabelField("Version", (previewInfo != null) ? previewInfo.packageVersion : "-", new GUILayoutOption[0]); string label2 = (previewInfo != null) ? ((firstAsset.price == null || !(firstAsset.price != "")) ? "free" : firstAsset.price) : "-"; EditorGUILayout.LabelField("Price", label2, new GUILayoutOption[0]); string label3 = (previewInfo == null || previewInfo.packageRating < 0) ? "-" : (previewInfo.packageRating.ToString() + " of 5"); EditorGUILayout.LabelField("Rating", label3, new GUILayoutOption[0]); EditorGUILayout.LabelField("Size", (previewInfo != null) ? AssetStoreAssetInspector.intToSizeString(previewInfo.packageSize) : "-", new GUILayoutOption[0]); string label4 = (previewInfo == null || previewInfo.packageAssetCount < 0) ? "-" : previewInfo.packageAssetCount.ToString(); EditorGUILayout.LabelField("Asset count", label4, new GUILayoutOption[0]); GUILayout.BeginHorizontal(new GUILayoutOption[0]); EditorGUILayout.PrefixLabel("Web page"); bool flag2 = previewInfo != null && previewInfo.packageShortUrl != null && previewInfo.packageShortUrl != ""; bool enabled2 = GUI.enabled; GUI.enabled = flag2; if (GUILayout.Button((!flag2) ? EditorGUIUtility.TempContent("-") : new GUIContent(previewInfo.packageShortUrl, "View in browser"), AssetStoreAssetInspector.styles.link, new GUILayoutOption[0])) { Application.OpenURL(previewInfo.packageShortUrl); } if (GUI.enabled) { EditorGUIUtility.AddCursorRect(GUILayoutUtility.GetLastRect(), MouseCursor.Link); } GUI.enabled = enabled2; GUILayout.EndHorizontal(); EditorGUILayout.LabelField("Publisher", (previewInfo != null) ? previewInfo.publisherName : "-", new GUILayoutOption[0]); } if (firstAsset.id != 0) { GUILayout.BeginHorizontal(new GUILayoutOption[0]); GUILayout.FlexibleSpace(); string text; if (previewInfo != null && previewInfo.isDownloadable) { text = "Import package"; } else { text = "Buy for " + firstAsset.price; } bool enabled3 = GUI.enabled; bool flag3 = previewInfo != null && previewInfo.buildProgress >= 0f; bool flag4 = previewInfo != null && previewInfo.downloadProgress >= 0f; if (flag3 || flag4 || previewInfo == null) { text = ""; GUI.enabled = false; } if (GUILayout.Button(text, new GUILayoutOption[] { GUILayout.Height(40f), GUILayout.Width(120f) })) { if (previewInfo.isDownloadable) { this.ImportPackage(firstAsset); } else { this.InitiateBuySelected(); } GUIUtility.ExitGUI(); } if (Event.current.type == EventType.Repaint) { Rect lastRect = GUILayoutUtility.GetLastRect(); lastRect.height -= 4f; float width = lastRect.width; lastRect.width = lastRect.height; lastRect.y += 2f; lastRect.x += 2f; if (flag3 || flag4) { lastRect.width = width - lastRect.height - 4f; lastRect.x += lastRect.height; EditorGUI.ProgressBar(lastRect, (!flag4) ? previewInfo.buildProgress : previewInfo.downloadProgress, (!flag4) ? "Building" : "Downloading"); } } GUI.enabled = enabled3; GUILayout.Space(4f); if (GUILayout.Button("Open Asset Store", new GUILayoutOption[] { GUILayout.Height(40f), GUILayout.Width(120f) })) { AssetStoreAssetInspector.OpenItemInAssetStore(firstAsset); GUIUtility.ExitGUI(); } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); } GUILayout.FlexibleSpace(); } EditorWrapper previewEditor = this.previewEditor; if (previewEditor != null && firstAsset != null && firstAsset.HasLivePreview) { previewEditor.OnAssetStoreInspectorGUI(); } GUI.enabled = enabled; EditorGUILayout.EndVertical(); }
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 override void OnInspectorGUI() { if (styles == null) { // Set the singleton in case the DrawEditors() has created this window s_SharedAssetStoreAssetInspector = this; styles = new Styles(); } AssetStoreAsset activeAsset = AssetStoreAssetSelection.GetFirstAsset(); AssetStoreAsset.PreviewInfo info = null; if (activeAsset != null) { info = activeAsset.previewInfo; } if (activeAsset != null) { target.name = string.Format("Asset Store: {0}", activeAsset.name); } else { target.name = "Asset Store"; } EditorGUILayout.BeginVertical(); bool guiEnabled = GUI.enabled; GUI.enabled = activeAsset != null && activeAsset.packageID != 0; if (OfflineNoticeEnabled) { Color col = GUI.color; GUI.color = Color.yellow; GUILayout.Label("Network is offline"); GUI.color = col; } if (activeAsset != null) { string typeName = activeAsset.className == null ? "" : activeAsset.className.Split(new char[] { ' ' }, 2)[0]; bool isPackage = activeAsset.id == -activeAsset.packageID; if (isPackage) { typeName = "Package"; } if (activeAsset.HasLivePreview) { typeName = activeAsset.Preview.GetType().Name; } EditorGUILayout.LabelField("Type", typeName); if (isPackage) { packageInfoShown = true; } else { EditorGUILayout.Separator(); packageInfoShown = EditorGUILayout.Foldout(packageInfoShown, "Part of package", true); } if (packageInfoShown) { EditorGUILayout.LabelField("Name", info == null ? "-" : info.packageName); EditorGUILayout.LabelField("Version", info == null ? "-" : info.packageVersion); string price = info == null ? "-" : (!string.IsNullOrEmpty(activeAsset.price) ? activeAsset.price : "free"); EditorGUILayout.LabelField("Price", price); string rating = info != null && info.packageRating >= 0 ? info.packageRating + " of 5" : "-"; EditorGUILayout.LabelField("Rating", rating); EditorGUILayout.LabelField("Size", info == null ? "-" : intToSizeString(info.packageSize)); string assetCount = info != null && info.packageAssetCount >= 0 ? info.packageAssetCount.ToString() : "-"; EditorGUILayout.LabelField("Asset count", assetCount); GUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("Web page"); bool hasPageUrl = info != null && info.packageShortUrl != null && info.packageShortUrl != ""; bool guiBefore = GUI.enabled; GUI.enabled = hasPageUrl; if (GUILayout.Button(hasPageUrl ? new GUIContent(info.packageShortUrl, "View in browser") : EditorGUIUtility.TempContent("-"), styles.link)) { Application.OpenURL(info.packageShortUrl); } if (GUI.enabled) { EditorGUIUtility.AddCursorRect(GUILayoutUtility.GetLastRect(), MouseCursor.Link); } GUI.enabled = guiBefore; GUILayout.EndHorizontal(); EditorGUILayout.LabelField("Publisher", info == null ? "-" : info.publisherName); } if (activeAsset.id != 0) { GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Open Asset Store", GUILayout.Height(40), GUILayout.Width(120))) { OpenItemInAssetStore(activeAsset); GUIUtility.ExitGUI(); } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); } GUILayout.FlexibleSpace(); } EditorWrapper editor = previewEditor; if (editor != null && activeAsset != null && activeAsset.HasLivePreview) { editor.OnAssetStoreInspectorGUI(); } GUI.enabled = guiEnabled; EditorGUILayout.EndVertical(); }
/** * Initiate a purchase of the selected package from the asset store. * The package will be the one that contains the currently selected asset. * * Since not all users may have allowed for single click purchases this can result * in two scenarios: * 1. single click allowed and a native purchase acknowledgement dialog appears to * finalize the purchase. * 2. single click is not allowed and the package is put to an asset store basket. * Then the asset store window is displayed with the basket open. */ void InitiateBuySelected(bool firstAttempt) { //Debug.Log("payavail " + paymentAvailability.ToString()); // Ask the asset store if the use has allowed single click payments AssetStoreAsset asset = AssetStoreAssetSelection.GetFirstAsset(); if (asset == null) { EditorUtility.DisplayDialog("No asset selected", "Please select asset before buying a package", "ok"); } else if (paymentAvailability == PaymentAvailability.AnonymousUser) { // Maybe the asset store window did a login already and we have a session key // then we just need to fetch the new info if (AssetStoreClient.LoggedIn()) { AssetStoreAssetSelection.RefreshFromServer(delegate() { InitiateBuySelected(false); }); } else if (firstAttempt) { LoginAndInitiateBuySelected(); } } else if (paymentAvailability == PaymentAvailability.ServiceDisabled) { // Use the asset store window to complete the purchase since single click is not possible if (asset.previewInfo == null) { return; } AssetStore.Open(string.Format("content/{0}/directpurchase", asset.packageID)); } else if (paymentAvailability == PaymentAvailability.BasketNotEmpty) { // Use the asset store window to complete the purchase since there is already \ // something in the users basket if (asset.previewInfo == null) { return; } // Maybe the basket has been emptied and this is a retry by the user if (firstAttempt) { AssetStoreAssetSelection.RefreshFromServer(delegate() { InitiateBuySelected(false); }); } else { AssetStore.Open(string.Format("content/{0}/basketpurchase", asset.packageID)); } } else { // Show single click window AssetStoreInstaBuyWindow.ShowAssetStoreInstaBuyWindow(asset, AssetStoreAssetInspector.s_PurchaseMessage, AssetStoreAssetInspector.s_PaymentMethodCard, AssetStoreAssetInspector.s_PaymentMethodExpire, AssetStoreAssetInspector.s_PriceText ); } }