コード例 #1
0
            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 fetchedInfo = FetchedInfo.ParseFetchedInfo(id.ToString(), productDetail);
                            if (fetchedInfo == null)
                            {
                                package = new AssetStorePackage(id.ToString(), new Error(NativeErrorCode.Unknown, "Error parsing product details."));
                            }
                            else
                            {
                                var oldFetchedInfo = m_FetchedInfos.Get(fetchedInfo.id);
                                if (oldFetchedInfo == null || oldFetchedInfo.versionId != fetchedInfo.versionId || oldFetchedInfo.versionString != fetchedInfo.versionString)
                                {
                                    if (string.IsNullOrEmpty(fetchedInfo.packageName))
                                    {
                                        package = new AssetStorePackage(fetchedInfo, m_LocalInfos.Get(fetchedInfo.id));
                                    }
                                    else
                                    {
                                        UpmClient.instance.FetchForProduct(fetchedInfo.id, fetchedInfo.packageName);
                                    }
                                    m_FetchedInfos[fetchedInfo.id] = fetchedInfo;
                                }
                            }
                        }
                        else
                        {
                            package = new AssetStorePackage(id.ToString(), new Error(NativeErrorCode.Unknown, error));
                        }

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

                        countProduct--;
                        if (countProduct == 0)
                        {
                            onFetchDetailsFinish?.Invoke();
                        }
                    });
                }
            }
コード例 #2
0
            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 });
                }
            }
コード例 #3
0
            private void OnLocalInfoRemoved(LocalInfo localInfo)
            {
                var fetchedInfo = m_FetchedInfos.Get(localInfo.id);

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

                onPackagesChanged?.Invoke(new[] { package });
            }
コード例 #4
0
            private void OnProductPackageFetchError(string productId, Error error)
            {
                var fetchedInfo = m_FetchedInfos.Get(productId);

                if (fetchedInfo != null)
                {
                    var assetStorePackage        = new AssetStorePackage(fetchedInfo);
                    var assetStorePackageVersion = assetStorePackage.versionList.primary as AssetStorePackageVersion;
                    assetStorePackageVersion.SetUpmPackageFetchError(error);
                    onPackagesChanged?.Invoke(new[] { assetStorePackage });
                }
            }
コード例 #5
0
            private void ListInternal(IDictionary <string, AssetStorePackageInfo> localPackages, int offset, int limit)
            {
                onOperationStart?.Invoke();

                AssetStoreRestAPI.instance.GetProductIDList(offset, limit, productList =>
                {
                    if (!productList.isValid)
                    {
                        onOperationFinish?.Invoke();
                        onOperationError?.Invoke(new Error(NativeErrorCode.Unknown, productList.errorMessage));
                        return;
                    }

                    var countProduct = productList.list.Count;
                    if (countProduct == 0 || !ApplicationUtil.instance.isUserLoggedIn)
                    {
                        onOperationFinish?.Invoke();
                        return;
                    }

                    foreach (var product in productList.list)
                    {
                        AssetStoreRestAPI.instance.GetProductDetail(product, productDetail =>
                        {
                            AssetStorePackage package;
                            object error;
                            if (!productDetail.TryGetValue("errorMessage", out error))
                            {
                                AssetStorePackageInfo localPackage;
                                if (localPackages.TryGetValue(product.ToString(), out localPackage))
                                {
                                    productDetail["localPath"] = localPackage.packagePath;
                                }
                                else
                                {
                                    productDetail["localPath"] = string.Empty;
                                }

                                package = new AssetStorePackage(product.ToString(), productDetail);
                                if (m_UpdateDetails.ContainsKey(package.uniqueId))
                                {
                                    package.SetState(m_UpdateDetails[package.uniqueId]);
                                }

                                if (package.state == PackageState.Outdated && !string.IsNullOrEmpty(localPackage.packagePath))
                                {
                                    package.m_FirstVersion.localPath = string.Empty;

                                    try
                                    {
                                        var info              = new AssetStorePackageVersion.SpecificVersionInfo();
                                        var item              = Json.Deserialize(localPackage.jsonInfo) as Dictionary <string, object>;
                                        info.versionId        = item["version_id"] as string;
                                        info.versionString    = item["version"] as string;
                                        info.publishedDate    = item["pubdate"] as string;
                                        info.supportedVersion = item["unity_version"] as string;

                                        var installedVersion       = new AssetStorePackageVersion(product.ToString(), productDetail, info);
                                        installedVersion.localPath = localPackage.packagePath;

                                        package.AddVersion(installedVersion);
                                    }
                                    catch (Exception)
                                    {
                                    }
                                }
                            }
                            else
                            {
                                package = new AssetStorePackage(product.ToString(), new Error(NativeErrorCode.Unknown, error as string));
                            }

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

                            countProduct--;
                            if (countProduct == 0)
                            {
                                onOperationFinish?.Invoke();
                            }
                        });
                    }
                });
            }
コード例 #6
0
            private void FetchDetailsInternal(IEnumerable <long> packageIds, IDictionary <string, AssetStorePackageInfo> localPackages)
            {
                var countProduct = packageIds.Count();

                if (countProduct == 0)
                {
                    return;
                }

                onFetchDetailsStart?.Invoke();

                foreach (var id in packageIds)
                {
                    AssetStoreRestAPI.instance.GetProductDetail(id, productDetail =>
                    {
                        AssetStorePackage package;
                        object error;
                        if (!productDetail.TryGetValue("errorMessage", out error))
                        {
                            AssetStorePackageInfo localPackage;
                            if (localPackages.TryGetValue(id.ToString(), out localPackage))
                            {
                                productDetail["localPath"] = localPackage.packagePath;
                            }
                            else
                            {
                                productDetail["localPath"] = string.Empty;
                            }

                            package = new AssetStorePackage(id.ToString(), productDetail);
                            if (m_UpdateDetails.ContainsKey(package.uniqueId))
                            {
                                package.SetState(m_UpdateDetails[package.uniqueId]);
                            }

                            if (package.state == PackageState.Outdated && !string.IsNullOrEmpty(localPackage.packagePath))
                            {
                                package.m_FetchedVersion.localPath = string.Empty;

                                try
                                {
                                    var info              = new AssetStorePackageVersion.SpecificVersionInfo();
                                    var item              = Json.Deserialize(localPackage.jsonInfo) as Dictionary <string, object>;
                                    info.versionId        = item["version_id"] as string;
                                    info.versionString    = item["version"] as string;
                                    info.publishedDate    = item["pubdate"] as string;
                                    info.supportedVersion = item["unity_version"] as string;

                                    var installedVersion       = new AssetStorePackageVersion(id.ToString(), productDetail, info);
                                    installedVersion.localPath = localPackage.packagePath;

                                    package.AddVersion(installedVersion);
                                }
                                catch (Exception)
                                {
                                }
                            }
                            m_PackageDetailsFetched.Add(id);
                        }
                        else
                        {
                            package = new AssetStorePackage(id.ToString(), new Error(NativeErrorCode.Unknown, error as string));
                        }

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

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