예제 #1
0
        public void Start(PurchasesQueryArgs queryArgs = null)
        {
            m_QueryArgs    = queryArgs;
            m_IsInProgress = true;
            m_Timestamp    = DateTime.Now.Ticks;

            if (!ApplicationUtil.instance.isUserLoggedIn)
            {
                OnOperationError(new UIError(UIErrorCode.AssetStoreOperationError, L10n.Tr("User not logged in")));
                return;
            }

            AssetStoreRestAPI.instance.GetPurchases(queryArgs.ToString(), result =>
            {
                if (!ApplicationUtil.instance.isUserLoggedIn)
                {
                    OnOperationError(new UIError(UIErrorCode.AssetStoreOperationError, L10n.Tr("User not logged in")));
                    return;
                }

                m_Result = new AssetStorePurchases(this.queryArgs);
                m_Result.ParsePurchases(result);
                onOperationSuccess?.Invoke(this);

                FinalizedOperation();
            }, error => OnOperationError(error));
        }
예제 #2
0
            public void ListPurchases(PurchasesQueryArgs queryArgs, bool fetchDetails = true)
            {
                RefreshLocalInfos();
                if (queryArgs.startIndex == 0)
                {
                    RefreshProductUpdateDetails();
                }

                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 = AssetStoreCache.instance.GetPurchaseInfo(productIdString);
                            AssetStoreCache.instance.SetPurchaseInfo(purchaseInfo);

                            // create a placeholder before fetching data from the cloud for the first time
                            var productInfo = AssetStoreCache.instance.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(purchaseInfo, productInfo, AssetStoreCache.instance.GetLocalInfo(productInfo.id)));
                                }
                            }
                        }

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

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

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

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

                onListOperation?.Invoke(m_ListOperation);
                m_ListOperation.Start(queryArgs);
            }
예제 #3
0
            public void Refresh(RefreshOptions options, int pageSize = k_DefaultPageSize)
            {
                if (pageSize == 0)
                {
                    return;
                }

                // make sure the events are registered before actually calling the actual refresh functions
                // such that we don't lose any callbacks events
                UnregisterEvents();
                RegisterEvents();

                if ((options & RefreshOptions.UpmSearchOffline) != 0)
                {
                    UpmClient.instance.SearchAll(true);
                }
                if ((options & RefreshOptions.UpmSearch) != 0)
                {
                    UpmClient.instance.SearchAll();
                }
                if ((options & RefreshOptions.UpmListOffline) != 0)
                {
                    UpmClient.instance.List(true);
                }
                if ((options & RefreshOptions.UpmList) != 0)
                {
                    UpmClient.instance.List();
                }
                if ((options & RefreshOptions.Purchased) != 0)
                {
                    var queryArgs = new PurchasesQueryArgs
                    {
                        startIndex = 0,
                        limit      = pageSize,
                        searchText = string.Empty
                    };

                    IPage page;
                    if (m_Pages.TryGetValue(PackageFilterTab.AssetStore, out page))
                    {
                        queryArgs.statuses       = page.filters.statuses;
                        queryArgs.categories     = page.filters.categories;
                        queryArgs.labels         = page.filters.labels;
                        queryArgs.orderBy        = page.filters.orderBy;
                        queryArgs.isReverseOrder = page.filters.isReverseOrder;
                    }

                    AssetStoreClient.instance.ListPurchases(queryArgs, false);
                }
                if ((options & RefreshOptions.PurchasedOffline) != 0)
                {
                    AssetStoreClient.instance.RefreshLocal();
                }
            }
예제 #4
0
        public virtual void Refresh(RefreshOptions options, int pageSize = k_DefaultPageSize)
        {
            if (pageSize == 0)
            {
                return;
            }

            if ((options & RefreshOptions.UpmSearchOffline) != 0)
            {
                m_UpmClient.SearchAll(true);
            }
            if ((options & RefreshOptions.UpmSearch) != 0)
            {
                m_UpmClient.SearchAll();
            }
            if ((options & RefreshOptions.UpmListOffline) != 0)
            {
                m_UpmClient.List(true);
            }
            if ((options & RefreshOptions.UpmList) != 0)
            {
                m_UpmClient.List();
            }
            if ((options & RefreshOptions.Purchased) != 0)
            {
                var queryArgs = new PurchasesQueryArgs
                {
                    startIndex = 0,
                    limit      = pageSize,
                    searchText = string.Empty
                };

                IPage page;
                if (m_Pages.TryGetValue(PackageFilterTab.AssetStore, out page))
                {
                    queryArgs.statuses       = page.filters.statuses;
                    queryArgs.categories     = page.filters.categories;
                    queryArgs.labels         = page.filters.labels;
                    queryArgs.orderBy        = page.filters.orderBy;
                    queryArgs.isReverseOrder = page.filters.isReverseOrder;
                }

                m_AssetStoreClient.ListPurchases(queryArgs, false);
            }
            if ((options & RefreshOptions.PurchasedOffline) != 0)
            {
                m_AssetStoreClient.RefreshLocal();
            }
        }
예제 #5
0
        public void LoadMore(int numberOfPackages)
        {
            var isSearchMode = !string.IsNullOrEmpty(PackageFiltering.instance.currentSearchText);
            var productList  = isSearchMode ? m_FilteredList.searchList : m_FilteredList.baseList;

            if (productList.list.Count < productList.total)
            {
                var queryArgs = new PurchasesQueryArgs
                {
                    startIndex = productList.list.Count,
                    limit      = numberOfPackages,
                    searchText = PackageFiltering.instance.currentSearchText
                };
                AssetStoreClient.instance.ListPurchases(queryArgs, false);
            }
        }
예제 #6
0
 private void OnSearchTextChanged(string searchText)
 {
     // clear current search result & start new fetch
     if (!string.IsNullOrEmpty(searchText))
     {
         if (PackageFiltering.instance.currentFilterTab == PackageFilterTab.AssetStore)
         {
             var queryArgs = new PurchasesQueryArgs
             {
                 startIndex = 0,
                 limit      = k_DefaultPageSize,
                 searchText = searchText
             };
             AssetStoreClient.instance.ListPurchases(queryArgs, false);
         }
     }
     GetPageFromFilterTab().FilterBySearchText(searchText);
 }
예제 #7
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);
            }
        }
예제 #8
0
            public void Refresh(RefreshOptions options, int pageSize = 25)
            {
                if (pageSize == 0)
                {
                    return;
                }

                // make sure the events are registered before actually calling the actual refresh functions
                // such that we don't lose any callbacks events
                RegisterEvents();
                if ((options & RefreshOptions.UpmSearchOffline) != 0)
                {
                    UpmClient.instance.SearchAll(true);
                }
                if ((options & RefreshOptions.UpmSearch) != 0)
                {
                    UpmClient.instance.SearchAll();
                }
                if ((options & RefreshOptions.UpmListOffline) != 0)
                {
                    UpmClient.instance.List(true);
                }
                if ((options & RefreshOptions.UpmList) != 0)
                {
                    UpmClient.instance.List();
                }
                if ((options & RefreshOptions.Purchased) != 0)
                {
                    var queryArgs = new PurchasesQueryArgs
                    {
                        startIndex = 0,
                        limit      = pageSize,
                        searchText = string.Empty
                    };
                    AssetStoreClient.instance.ListPurchases(queryArgs, false);
                }
                if ((options & RefreshOptions.PurchasedOffline) != 0)
                {
                    AssetStoreClient.instance.RefreshLocal();
                }
            }
예제 #9
0
            public void ListPurchases(PurchasesQueryArgs queryArgs, bool fetchDetails = true)
            {
                RefreshLocalInfos();
                if (queryArgs.startIndex == 0)
                {
                    RefreshProductUpdateDetails();
                }

                m_ListOperation.onOperationSuccess += op =>
                {
                    var result = m_ListOperation.result;
                    if (result.list.Count > 0)
                    {
                        var placeholderPackages = new List <IPackage>();
                        foreach (var item in result.list)
                        {
                            m_PurchaseInfos[item.productId.ToString()] = item;

                            // create a placeholder before fetching data from the cloud for the first time
                            if (!m_ProductInfos.ContainsKey(item.productId.ToString()))
                            {
                                placeholderPackages.Add(new PlaceholderPackage(item.productId.ToString(), item.displayName, PackageType.AssetStore, PackageTag.None, PackageProgress.Refreshing));
                            }
                        }

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

                        if (fetchDetails)
                        {
                            FetchDetails(result.productIds);
                        }
                    }
                    onProductListFetched?.Invoke(result, fetchDetails);
                };

                onListOperation?.Invoke(m_ListOperation);
                m_ListOperation.Start(queryArgs);
            }
예제 #10
0
 public AssetStorePurchases(PurchasesQueryArgs queryArgs = null)
 {
     this.queryArgs = queryArgs ?? new PurchasesQueryArgs();
 }
예제 #11
0
        public void OnProductListFetched(AssetStorePurchases productList, bool fetchDetailsCalled)
        {
            var isSearchResult = !string.IsNullOrEmpty(productList.searchText);

            if (isSearchResult && productList.searchText != PackageFiltering.instance.currentSearchText)
            {
                return;
            }

            var targetList = isSearchResult ? m_FilteredList.searchList : m_FilteredList.baseList;

            if (productList.startIndex > 0 && (targetList.total != productList.total || (targetList.searchText ?? "") != (productList.searchText ?? "")))
            {
                // if a new page has arrived but the total has changed or the searchText has changed, do a re-fetch
                var queryArgs = new PurchasesQueryArgs
                {
                    startIndex = 0,
                    limit      = productList.startIndex + productList.list.Count,
                    searchText = PackageFiltering.instance.currentSearchText
                };
                AssetStoreClient.instance.ListPurchases(queryArgs, true);
                return;
            }

            var rebuildList = PackageFiltering.instance.currentFilterTab == PackageFilterTab.AssetStore;

            HashSet <long> removed = null;
            List <long>    added   = null;

            if (productList.startIndex == 0)
            {
                if (rebuildList)
                {
                    removed = new HashSet <long>(targetList.productIds);
                    added   = new List <long>();
                    foreach (var id in productList.productIds)
                    {
                        if (removed.Contains(id))
                        {
                            removed.Remove(id);
                        }
                        else
                        {
                            added.Add(id);
                        }
                    }
                }
                // override the result if the new list starts from index 0 (meaning it's a refresh)
                targetList.list  = productList.list;
                targetList.total = productList.total;
                targetList.queryArgs.searchText = productList.searchText;
            }
            else if (productList.startIndex == targetList.list.Count && (targetList.searchText ?? "") == (productList.searchText ?? ""))
            {
                // append the result if it is the next page
                targetList.list.AddRange(productList.list);
                if (rebuildList)
                {
                    added = productList.productIds.ToList();
                }
            }
            else
            {
                // if the content is neither starting from zero or next page, we simply discard it
                return;
            }

            m_MorePackagesToFetch       = m_FilteredList.baseList.total > m_FilteredList.baseList.list.Count;
            m_MoreSearchPackagesToFetch = m_FilteredList.searchList.total > m_FilteredList.searchList.list.Count;

            m_FilteredList.enabled = true;
            if (!fetchDetailsCalled && productList.list.Any())
            {
                AssetStoreClient.instance.FetchDetails(productList.productIds);
            }

            if (rebuildList)
            {
                var addedPackages   = added?.Select(id => PackageDatabase.instance.GetPackage(id.ToString()));
                var removedPackages = removed?.Select(id => PackageDatabase.instance.GetPackage(id.ToString()));
                RebuildList(addedPackages, removedPackages);
            }
        }