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); }
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); } }
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); }
public void List(int offset, int limit, string searchText = "", bool fetchDetails = true) { m_ListOperation.Start(); onListOperation?.Invoke(m_ListOperation); if (!ApplicationUtil.instance.isUserLoggedIn) { m_ListOperation.TriggerOperationError(new Error(NativeErrorCode.Unknown, L10n.Tr("User not logged in"))); return; } RefreshLocalInfos(); if (offset == 0) { RefreshProductUpdateDetails(); } AssetStoreRestAPI.instance.GetProductIDList(offset, limit, searchText, productList => { if (!productList.isValid) { m_ListOperation.TriggerOperationError(new Error(NativeErrorCode.Unknown, productList.errorMessage)); return; } if (!ApplicationUtil.instance.isUserLoggedIn) { m_ListOperation.TriggerOperationError(new Error(NativeErrorCode.Unknown, L10n.Tr("User not logged in"))); return; } onProductListFetched?.Invoke(productList, fetchDetails); if (productList.list.Count == 0) { m_ListOperation.TriggeronOperationSuccess(); return; } var placeholderPackages = new List <IPackage>(); foreach (var productId in productList.list) { // create a placeholder before fetching data from the cloud for the first time if (!m_FetchedInfos.ContainsKey(productId.ToString())) { placeholderPackages.Add(new PlaceholderPackage(productId.ToString(), PackageType.AssetStore, PackageTag.None, PackageProgress.Refreshing)); } } if (placeholderPackages.Any()) { onPackagesChanged?.Invoke(placeholderPackages); } m_ListOperation.TriggeronOperationSuccess(); if (fetchDetails) { FetchDetails(productList.list); } }); }