public void FetchDetails(IEnumerable <long> productIds)
            {
                var countProduct = productIds.Count();

                if (countProduct == 0)
                {
                    return;
                }

                onFetchDetailsStart?.Invoke();

                foreach (var id in productIds)
                {
                    AssetStoreRestAPI.instance.GetProductDetail(id, productDetail =>
                    {
                        AssetStorePackage package = null;
                        var error = productDetail.GetString("errorMessage");
                        if (string.IsNullOrEmpty(error))
                        {
                            var productInfo = AssetStoreProductInfo.ParseProductInfo(id.ToString(), productDetail);
                            if (productInfo == null)
                            {
                                package = new AssetStorePackage(id.ToString(), new UIError(UIErrorCode.AssetStoreClientError, "Error parsing product details."));
                            }
                            else
                            {
                                var purchaseInfo   = m_PurchaseInfos.Get(productInfo.id);
                                var oldProductInfo = m_ProductInfos.Get(productInfo.id);
                                if (oldProductInfo == null || oldProductInfo.versionId != productInfo.versionId || oldProductInfo.versionString != productInfo.versionString)
                                {
                                    if (string.IsNullOrEmpty(productInfo.packageName))
                                    {
                                        package = new AssetStorePackage(purchaseInfo, productInfo, m_LocalInfos.Get(productInfo.id));
                                    }
                                    else
                                    {
                                        UpmClient.instance.FetchForProduct(productInfo.id, productInfo.packageName);
                                    }
                                    m_ProductInfos[productInfo.id] = productInfo;
                                }
                            }
                        }
                        else
                        {
                            package = new AssetStorePackage(id.ToString(), new UIError(UIErrorCode.AssetStoreClientError, error));
                        }

                        if (package != null)
                        {
                            onPackagesChanged?.Invoke(new[] { package });
                        }

                        countProduct--;
                        if (countProduct == 0)
                        {
                            onFetchDetailsFinish?.Invoke();
                        }
                    });
                }
            }
Beispiel #2
0
        public virtual void FetchDetails(IEnumerable <long> productIds)
        {
            var countProduct = productIds.Count();

            if (countProduct == 0)
            {
                return;
            }

            onFetchDetailsStart?.Invoke();

            foreach (var id in productIds)
            {
                m_AssetStoreRestAPI.GetProductDetail(id, productDetail =>
                {
                    AssetStorePackage package = null;
                    var error = productDetail.GetString("errorMessage");
                    if (string.IsNullOrEmpty(error))
                    {
                        var productInfo = AssetStoreProductInfo.ParseProductInfo(m_AssetStoreUtils, id.ToString(), productDetail);
                        if (productInfo == null)
                        {
                            package = new AssetStorePackage(m_AssetStoreUtils, m_IOProxy, id.ToString(), new UIError(UIErrorCode.AssetStoreClientError, L10n.Tr("Error parsing product details.")));
                        }
                        else
                        {
                            var oldProductInfo = m_AssetStoreCache.GetProductInfo(productInfo.id);
                            if (oldProductInfo == null || oldProductInfo.versionId != productInfo.versionId || oldProductInfo.versionString != productInfo.versionString)
                            {
                                if (string.IsNullOrEmpty(productInfo.packageName))
                                {
                                    package = new AssetStorePackage(m_AssetStoreUtils, m_IOProxy, m_AssetStoreCache.GetPurchaseInfo(productInfo.id), productInfo, m_AssetStoreCache.GetLocalInfo(productInfo.id));
                                }
                                else
                                {
                                    m_UpmClient.FetchForProduct(productInfo.id, productInfo.packageName);
                                }
                                m_AssetStoreCache.SetProductInfo(productInfo);
                            }
                        }
                    }
                    else
                    {
                        m_AssetStoreCache.RemoveProductInfo(id.ToString());
                        package = new AssetStorePackage(m_AssetStoreUtils, m_IOProxy, id.ToString(), new UIError(UIErrorCode.AssetStoreClientError, error));
                    }

                    if (package != null)
                    {
                        onPackagesChanged?.Invoke(new[] { package });
                    }

                    countProduct--;
                    if (countProduct == 0)
                    {
                        onFetchDetailsFinish?.Invoke();
                    }
                });
            }
        }