예제 #1
0
        public virtual void Fetch(long productId)
        {
            if (!m_UnityConnect.isUserLoggedIn)
            {
                onFetchDetailsError?.Invoke(new UIError(UIErrorCode.AssetStoreAuthorizationError, L10n.Tr("User not logged in.")));
                return;
            }

            var productIdString = productId.ToString();
            var purchaseInfo    = m_AssetStoreCache.GetPurchaseInfo(productIdString);

            if (purchaseInfo != null)
            {
                FetchInternal(productId, purchaseInfo);
            }
            else
            {
                // when the purchase info is not available for a package (either it's not fetched yet or just not available altogether)
                // we'll try to fetch the purchase info first and then call the `FetchInternal`.
                // In the case where a package not purchased, `purchaseInfo` will still be null,
                // but the generated `AssetStorePackage` in the end will contain an error.
                var fetchOperation = new AssetStoreListOperation(m_UnityConnect, m_AssetStoreRestAPI);
                var queryArgs      = new PurchasesQueryArgs {
                    productIds = new List <long> {
                        productId
                    }
                };
                fetchOperation.onOperationSuccess += op =>
                {
                    purchaseInfo = fetchOperation.result.list.FirstOrDefault();
                    if (purchaseInfo != null)
                    {
                        var updatedPackages = new List <IPackage>();
                        m_AssetStoreCache.SetPurchaseInfo(purchaseInfo);
                    }
                    ;
                    FetchInternal(productId, purchaseInfo);
                };
                fetchOperation.Start(queryArgs);
            }
        }
예제 #2
0
        public virtual void ListPurchases(PurchasesQueryArgs queryArgs, bool fetchDetails = true)
        {
            RefreshLocalInfos();
            if (queryArgs.startIndex == 0)
            {
                RefreshProductUpdateDetails();
            }

            m_ListOperation = m_ListOperation ?? new AssetStoreListOperation(m_UnityConnect, m_AssetStoreRestAPI);
            m_ListOperation.onOperationSuccess += op =>
            {
                var result = m_ListOperation.result;
                if (result.list.Count > 0)
                {
                    var updatedPackages = new List <IPackage>();
                    foreach (var purchaseInfo in result.list)
                    {
                        var productIdString = purchaseInfo.productId.ToString();
                        var oldPurchaseInfo = m_AssetStoreCache.GetPurchaseInfo(productIdString);
                        m_AssetStoreCache.SetPurchaseInfo(purchaseInfo);

                        // create a placeholder before fetching data from the cloud for the first time
                        var productInfo = m_AssetStoreCache.GetProductInfo(productIdString);
                        if (productInfo == null)
                        {
                            updatedPackages.Add(new PlaceholderPackage(productIdString, purchaseInfo.displayName, PackageType.AssetStore, PackageTag.None, PackageProgress.Refreshing));
                        }
                        else if (oldPurchaseInfo != null)
                        {
                            // for now, `tags` is the only component in `purchase info` that can be updated over time, so we only check for changes there
                            var oldTags = oldPurchaseInfo.tags ?? Enumerable.Empty <string>();
                            var newTags = purchaseInfo.tags ?? Enumerable.Empty <string>();
                            if (!oldTags.SequenceEqual(newTags))
                            {
                                updatedPackages.Add(new AssetStorePackage(m_AssetStoreUtils, m_IOProxy, purchaseInfo, productInfo, m_AssetStoreCache.GetLocalInfo(productInfo.id)));
                            }
                        }
                    }

                    if (updatedPackages.Any())
                    {
                        onPackagesChanged?.Invoke(updatedPackages);
                    }

                    if (fetchDetails)
                    {
                        FetchDetails(result.productIds);
                    }
                }

                foreach (var cat in result.categories)
                {
                    m_AssetStoreCache.SetCategory(cat.name, cat.count);
                }

                onProductListFetched?.Invoke(result, fetchDetails);
            };

            onListOperation?.Invoke(m_ListOperation);
            m_ListOperation.Start(queryArgs);
        }