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();
                        }
                    });
                }
            }
示例#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();
                    }
                });
            }
        }
            private void OnProductPackageChanged(string productId, IPackage package)
            {
                var fetchedInfo = m_FetchedInfos.Get(productId);

                if (fetchedInfo != null)
                {
                    var assetStorePackage = new AssetStorePackage(fetchedInfo, package as UpmPackage);
                    onPackagesChanged?.Invoke(new[] { assetStorePackage });
                }
            }
        private void OnProductPackageChanged(string productId, IPackage package)
        {
            var purchaseInfo = m_AssetStoreCache.GetPurchaseInfo(productId);
            var productInfo  = m_AssetStoreCache.GetProductInfo(productId);

            if (productInfo != null)
            {
                var assetStorePackage = new AssetStorePackage(m_AssetStoreUtils, m_IOProxy, purchaseInfo, productInfo, package as UpmPackage);
                onPackagesChanged?.Invoke(new[] { assetStorePackage });
            }
        }
            private void OnProductPackageChanged(string productId, IPackage package)
            {
                var purchaseInfo = m_PurchaseInfos.Get(productId);
                var productInfo  = m_ProductInfos.Get(productId);

                if (productInfo != null)
                {
                    var assetStorePackage = new AssetStorePackage(purchaseInfo, productInfo, package as UpmPackage);
                    onPackagesChanged?.Invoke(new[] { assetStorePackage });
                }
            }
            private void OnLocalInfoRemoved(AssetStoreLocalInfo localInfo)
            {
                var fetchedInfo = m_FetchedInfos.Get(localInfo.id);

                if (fetchedInfo == null)
                {
                    return;
                }
                var package = new AssetStorePackage(fetchedInfo, (AssetStoreLocalInfo)null);

                onPackagesChanged?.Invoke(new[] { package });
            }
            private void OnProductPackageFetchError(string productId, Error error)
            {
                var fetchedInfo = m_FetchedInfos.Get(productId);

                if (fetchedInfo != null)
                {
                    var assetStorePackage        = new AssetStorePackage(fetchedInfo);
                    var assetStorePackageVersion = assetStorePackage.versions.primary as AssetStorePackageVersion;
                    assetStorePackageVersion.SetUpmPackageFetchError(error);
                    onPackagesChanged?.Invoke(new[] { assetStorePackage });
                }
            }
        private void OnProductPackageFetchError(string productId, UIError error)
        {
            var purchaseInfo = m_AssetStoreCache.GetPurchaseInfo(productId);
            var productInfo  = m_AssetStoreCache.GetProductInfo(productId);

            if (productInfo != null)
            {
                var assetStorePackage        = new AssetStorePackage(m_AssetStoreUtils, m_IOProxy, purchaseInfo, productInfo);
                var assetStorePackageVersion = assetStorePackage.versions.primary as AssetStorePackageVersion;
                assetStorePackageVersion.SetUpmPackageFetchError(error);
                onPackagesChanged?.Invoke(new[] { assetStorePackage });
            }
        }
            private void OnLocalInfoRemoved(AssetStoreLocalInfo localInfo)
            {
                var purchaseInfo = m_PurchaseInfos.Get(localInfo.id);
                var productInfo  = m_ProductInfos.Get(localInfo.id);

                if (productInfo == null)
                {
                    return;
                }
                var package = new AssetStorePackage(purchaseInfo, productInfo, (AssetStoreLocalInfo)null);

                onPackagesChanged?.Invoke(new[] { package });
            }