Exemple #1
0
        // 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 LoginAndInitiateBuySelected()
 {
     AssetStoreLoginWindow.Login("Please login to the Asset Store in order to get payment information about the package.", (AssetStoreLoginWindow.LoginCallback)(errorMessage =>
     {
         if (errorMessage != null)
         {
             return;
         }
         AssetStoreAssetSelection.RefreshFromServer((AssetStoreAssetSelection.AssetsRefreshed)(() => this.InitiateBuySelected(false)));
     }));
 }
        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);
            }
        }
Exemple #4
0
 private void LoginAndInitiateBuySelected()
 {
     AssetStoreLoginWindow.Login("Please login to the Asset Store in order to get payment information about the package.", delegate(string errorMessage)
     {
         if (errorMessage == null)
         {
             AssetStoreAssetSelection.RefreshFromServer(delegate
             {
                 this.InitiateBuySelected(false);
             });
         }
     });
 }
Exemple #5
0
        public override void OnPreviewSettings()
        {
            AssetStoreAsset firstAsset = AssetStoreAssetSelection.GetFirstAsset();

            if (firstAsset != null)
            {
                EditorWrapper previewEditor = this.previewEditor;
                if (previewEditor != null && firstAsset.HasLivePreview)
                {
                    previewEditor.OnPreviewSettings();
                }
            }
        }
Exemple #6
0
 private void LoginAndImport(AssetStoreAsset asset)
 {
     AssetStoreLoginWindow.Login("Please login to the Asset Store in order to get download information for the package.", delegate(string errorMessage)
     {
         if (errorMessage == null)
         {
             AssetStoreAssetSelection.RefreshFromServer(delegate
             {
                 AssetStoreInstaBuyWindow.ShowAssetStoreInstaBuyWindowBuilding(asset);
             });
         }
     });
 }
Exemple #7
0
 public static void AddAsset(AssetStoreAsset searchResult, Texture2D placeholderPreviewImage)
 {
     // ISSUE: object of a compiler-generated type is created
     // ISSUE: variable of a compiler-generated type
     AssetStoreAssetSelection.\u003CAddAsset\u003Ec__AnonStorey4E assetCAnonStorey4E = new AssetStoreAssetSelection.\u003CAddAsset\u003Ec__AnonStorey4E();
     // ISSUE: reference to a compiler-generated field
     assetCAnonStorey4E.searchResult = searchResult;
     if ((Object)placeholderPreviewImage != (Object)null)
     {
         // ISSUE: reference to a compiler-generated field
         assetCAnonStorey4E.searchResult.previewImage = AssetStoreAssetSelection.ScaleImage(placeholderPreviewImage, 256, 256);
     }
     // ISSUE: reference to a compiler-generated field
     assetCAnonStorey4E.searchResult.previewInfo = (AssetStoreAsset.PreviewInfo)null;
     // ISSUE: reference to a compiler-generated field
     assetCAnonStorey4E.searchResult.previewBundleRequest = (AssetBundleCreateRequest)null;
     // ISSUE: reference to a compiler-generated field
     // ISSUE: reference to a compiler-generated field
     if (!string.IsNullOrEmpty(assetCAnonStorey4E.searchResult.dynamicPreviewURL) && (Object)assetCAnonStorey4E.searchResult.previewBundle == (Object)null)
     {
         // ISSUE: object of a compiler-generated type is created
         // ISSUE: variable of a compiler-generated type
         AssetStoreAssetSelection.\u003CAddAsset\u003Ec__AnonStorey4D assetCAnonStorey4D = new AssetStoreAssetSelection.\u003CAddAsset\u003Ec__AnonStorey4D();
         // ISSUE: reference to a compiler-generated field
         assetCAnonStorey4D.\u003C\u003Ef__ref\u002478 = assetCAnonStorey4E;
         // ISSUE: reference to a compiler-generated field
         assetCAnonStorey4E.searchResult.disposed = false;
         // ISSUE: reference to a compiler-generated field
         // ISSUE: reference to a compiler-generated field
         assetCAnonStorey4D.client = new AsyncHTTPClient(assetCAnonStorey4E.searchResult.dynamicPreviewURL);
         // ISSUE: reference to a compiler-generated field
         // ISSUE: reference to a compiler-generated method
         assetCAnonStorey4D.client.doneCallback = new AsyncHTTPClient.DoneCallback(assetCAnonStorey4D.\u003C\u003Em__8A);
         // ISSUE: reference to a compiler-generated field
         assetCAnonStorey4D.client.Begin();
     }
     else
     {
         // ISSUE: reference to a compiler-generated field
         if (!string.IsNullOrEmpty(assetCAnonStorey4E.searchResult.staticPreviewURL))
         {
             // ISSUE: reference to a compiler-generated field
             AssetStoreAssetSelection.DownloadStaticPreview(assetCAnonStorey4E.searchResult);
         }
     }
     // ISSUE: reference to a compiler-generated field
     AssetStoreAssetSelection.AddAssetInternal(assetCAnonStorey4E.searchResult);
     AssetStoreAssetSelection.RefreshFromServer((AssetStoreAssetSelection.AssetsRefreshed)null);
 }
Exemple #8
0
        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 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();
        }
Exemple #11
0
        public override void OnPreviewSettings()
        {
            AssetStoreAsset asset = AssetStoreAssetSelection.GetFirstAsset();

            if (asset == null)
            {
                return;
            }

            EditorWrapper editor = previewEditor;

            if (editor != null && asset.HasLivePreview)
            {
                editor.OnPreviewSettings();
            }
        }
Exemple #12
0
        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("");
        }
Exemple #13
0
        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 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();
        }
Exemple #15
0
        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();
            }
        }
Exemple #16
0
        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);
        }
Exemple #17
0
        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();
            }
        }
Exemple #18
0
        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();
            }
        }
Exemple #19
0
        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();
                    }
                }
            }
        }
            protected override void DrawInternal(int itemIdx, int endItem, float yOffset)
            {
                int endContainerItem = m_Assets.Count;
                int startItemIdx     = itemIdx;

                // The seperator bar is drawn before all items
                yOffset += kGroupSeparatorHeight;

                bool isRepaintEvent = Event.current.type == EventType.Repaint;

                Rect r;

                if (ListMode)
                {
                    // Draw row
                    //position.width = Mathf.Max (position.width, 500); // For some reason the icon is clipped if the rect cannot contain both the text and icon so make sure its large
                    for (; itemIdx < endItem && itemIdx < endContainerItem; itemIdx++)
                    {
                        r = m_Grid.CalcRect(itemIdx, yOffset);
                        // Mouse event handling
                        int clicks = HandleMouse(r);
                        if (clicks != 0)
                        {
                            m_Owner.SetSelection(m_Assets[itemIdx], clicks == 2);
                        }

                        if (isRepaintEvent)
                        {
                            bool selected = !AssetStoreAssetSelection.Empty && AssetStoreAssetSelection.ContainsAsset(m_Assets[itemIdx].id);
                            DrawLabel(r, m_Assets[itemIdx], selected);
                        }
                    }
                }
                else
                {
                    // First loop over assets to draw icons and the loop again to
                    // draw labels. Two loops in order to get rid of too many
                    // expensive setShader calls.
                    for (; itemIdx < endItem && itemIdx < endContainerItem; itemIdx++)
                    {
                        r = m_Grid.CalcRect(itemIdx, yOffset);

                        // Mouse event handling
                        int clicks = HandleMouse(r);
                        if (clicks != 0)
                        {
                            m_Owner.SetSelection(m_Assets[itemIdx], clicks == 2);
                        }

                        if (isRepaintEvent)
                        {
                            Rect position = new Rect(r.x, r.y, r.width, r.height - s_Styles.resultsGridLabel.fixedHeight);
                            DrawIcon(position, m_Assets[itemIdx]);
                        }
                    }
                    itemIdx = startItemIdx;

                    // Labels
                    if (isRepaintEvent)
                    {
                        for (; itemIdx < endItem && itemIdx < endContainerItem; itemIdx++)
                        {
                            r = m_Grid.CalcRect(itemIdx, yOffset);
                            bool selected = !AssetStoreAssetSelection.Empty && AssetStoreAssetSelection.ContainsAsset(m_Assets[itemIdx].id);
                            DrawLabel(r, m_Assets[itemIdx], selected);
                        }
                    }
                }

                // "Show more" button if more asset can by found in asset store
                if (ItemsAvailable <= (m_Grid.rows * m_Grid.columns))
                {
                    return; // no more items to fetch from A$ server
                }
                r = new Rect(m_Owner.GetVisibleWidth() - m_ShowMoreDims.x - 6,
                             yOffset + m_Grid.height + kMoreButtonOffset,
                             m_ShowMoreDims.x,
                             m_ShowMoreDims.y);

                if (ItemsAvailable > (m_Grid.rows * m_Grid.columns) &&
                    ItemsAvailable >= Assets.Count &&
                    Assets.Count < kMaxQueryItems)
                {
                    Event evt = Event.current;
                    switch (evt.type)
                    {
                    case EventType.MouseDown:
                        if (evt.button == 0 && r.Contains(evt.mousePosition))
                        {
                            if (ListMode)
                            {
                                ItemsWantedShown += kMoreRowsAddedListMode;
                            }
                            else
                            {
                                // Try to make sure that we have full rows of preview
                                // after the update. Partly filled rows can occur when resizing the
                                // listarea or when we reached the limit of results from server.
                                int itemsNeededToFillLastRow = m_Grid.columns - (ItemCount % m_Grid.columns);
                                itemsNeededToFillLastRow = itemsNeededToFillLastRow % m_Grid.columns;
                                ItemsWantedShown        += (kMoreRowsAdded * m_Grid.columns) + itemsNeededToFillLastRow;
                            }
                            if (NeedItems)     // Check that we need to fetch it since we might already have it prefetched
                            {
                                m_Owner.QueryAssetStore();
                            }
                            evt.Use();
                        }
                        break;

                    case EventType.Repaint:
                    {
                        EditorStyles.miniButton.Draw(r, "More", false, false, false, false);
                    }
                    break;
                    }
                }
            }
Exemple #21
0
        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);
 }
        /**
         * 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
                                                                      );
            }
        }
 public static void RefreshFromServer(AssetStoreAssetSelection.AssetsRefreshed callback)
 {
   // ISSUE: object of a compiler-generated type is created
   // ISSUE: variable of a compiler-generated type
   AssetStoreAssetSelection.\u003CRefreshFromServer\u003Ec__AnonStorey51 serverCAnonStorey51 = new AssetStoreAssetSelection.\u003CRefreshFromServer\u003Ec__AnonStorey51();
   // ISSUE: reference to a compiler-generated field
   serverCAnonStorey51.callback = callback;
   if (AssetStoreAssetSelection.s_SelectedAssets.Count == 0)
     return;
   List<AssetStoreAsset> assets = new List<AssetStoreAsset>();
   using (Dictionary<int, AssetStoreAsset>.Enumerator enumerator = AssetStoreAssetSelection.s_SelectedAssets.GetEnumerator())
   {
     while (enumerator.MoveNext())
     {
       KeyValuePair<int, AssetStoreAsset> current = enumerator.Current;
       assets.Add(current.Value);
     }
   }
   // ISSUE: reference to a compiler-generated method
   AssetStoreClient.AssetsInfo(assets, new AssetStoreResultBase<AssetStoreAssetsInfo>.Callback(serverCAnonStorey51.\u003C\u003Em__8C));
 }
Exemple #25
0
        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();
        }
		public static void RefreshFromServer(AssetStoreAssetSelection.AssetsRefreshed callback)
		{
			if (AssetStoreAssetSelection.s_SelectedAssets.Count == 0)
			{
				return;
			}
			List<AssetStoreAsset> list = new List<AssetStoreAsset>();
			foreach (KeyValuePair<int, AssetStoreAsset> current in AssetStoreAssetSelection.s_SelectedAssets)
			{
				list.Add(current.Value);
			}
			AssetStoreClient.AssetsInfo(list, delegate(AssetStoreAssetsInfo results)
			{
				AssetStoreAssetInspector.paymentAvailability = AssetStoreAssetInspector.PaymentAvailability.ServiceDisabled;
				if (results.error != null && results.error != string.Empty)
				{
					Console.WriteLine("Error performing Asset Store Info search: " + results.error);
					AssetStoreAssetInspector.OfflineNoticeEnabled = true;
					if (callback != null)
					{
						callback();
					}
					return;
				}
				AssetStoreAssetInspector.OfflineNoticeEnabled = false;
				if (results.status == AssetStoreAssetsInfo.Status.Ok)
				{
					AssetStoreAssetInspector.paymentAvailability = AssetStoreAssetInspector.PaymentAvailability.Ok;
				}
				else
				{
					if (results.status == AssetStoreAssetsInfo.Status.BasketNotEmpty)
					{
						AssetStoreAssetInspector.paymentAvailability = AssetStoreAssetInspector.PaymentAvailability.BasketNotEmpty;
					}
					else
					{
						if (results.status == AssetStoreAssetsInfo.Status.AnonymousUser)
						{
							AssetStoreAssetInspector.paymentAvailability = AssetStoreAssetInspector.PaymentAvailability.AnonymousUser;
						}
					}
				}
				AssetStoreAssetInspector.s_PurchaseMessage = results.message;
				AssetStoreAssetInspector.s_PaymentMethodCard = results.paymentMethodCard;
				AssetStoreAssetInspector.s_PaymentMethodExpire = results.paymentMethodExpire;
				AssetStoreAssetInspector.s_PriceText = results.priceText;
				AssetStoreAssetInspector.Instance.Repaint();
				if (callback != null)
				{
					callback();
				}
			});
		}