Пример #1
0
        public UnityTask <List <CharacterResult> > GetUserCharacters(bool forceUpdate = false)
        {
            if (forceUpdate)
            {
                this.characterCache = null;
            }

            if (this.characterCache != null)
            {
                return(UnityTask <List <CharacterResult> > .Empty(this.characterCache));
            }
            else
            {
                return(UnityTask <List <CharacterResult> > .Run(FetchCharacters()));
            }

            IEnumerator <List <CharacterResult> > FetchCharacters()
            {
                var getCharacters = this.playfabManager.Do <ListUsersCharactersRequest, ListUsersCharactersResult>(new ListUsersCharactersRequest(), PlayFabClientAPI.GetAllUsersCharactersAsync);

                while (getCharacters.IsDone == false)
                {
                    yield return(null);
                }

                this.characterCache = getCharacters.Value.Characters;

                yield return(this.characterCache);
            }
        }
 public UnityTask <T> GetTitleData <T>(string titleDataKey)
     where T : class
 {
     if (this.titleDataObjectCache.TryGetValue(titleDataKey, out object obj))
     {
         return(UnityTask <T> .Empty(obj as T));
     }
     else
     {
         return(UnityTask <T> .Run(FetchTitleDataObject()));
     }
Пример #3
0
        public UnityTask <List <ItemInstance> > GetInventoryItems()
        {
            if (this.usersInventoryCache != null)
            {
                return(UnityTask <List <ItemInstance> > .Empty(this.usersInventoryCache));
            }
            else
            {
                return(UnityTask <List <ItemInstance> > .Run(GetInventoryItemsCoroutine()));
            }

            IEnumerator <List <ItemInstance> > GetInventoryItemsCoroutine()
            {
                // If it's already running, then wait for it to finish
                if (this.getInventoryCoroutineRunning)
                {
                    while (this.getInventoryCoroutineRunning)
                    {
                        yield return(default);
        public UnityTask <string> GetTitleData(string titleDataKey)
        {
            if (this.titleDataCache.TryGetValue(titleDataKey, out string titleDataValue))
            {
                return(UnityTask <string> .Empty(titleDataValue));
            }
            else
            {
                return(UnityTask <string> .Run(FetchTitleData()));
            }

            IEnumerator <string> FetchTitleData()
            {
                if (UnityEngine.Time.realtimeSinceStartup < 10.0)
                {
                    UnityEngine.Debug.LogWarning($"Retrieving Title Data Key {titleDataKey} early in app startup.  Prehaps add this to PlayFabManager to download at startup.");
                }

                yield return(null);
            }
        }
        public UnityTask <List <StoreItem> > GetStore(string storeId, bool forceRefresh = false)
        {
            if (forceRefresh)
            {
                this.cachedStores.Remove(storeId);
            }

            if (this.cachedStores.ContainsKey(storeId))
            {
                return(UnityTask <List <StoreItem> > .Empty(this.cachedStores[storeId]));
            }
            else
            {
                return(UnityTask <List <StoreItem> > .Run(FetchStore()));
            }

            IEnumerator <List <StoreItem> > FetchStore()
            {
                this.getStoreRequest.StoreId = storeId;

                var getStore = this.playfabManager.Do <GetStoreItemsRequest, GetStoreItemsResult>(this.getStoreRequest, PlayFabClientAPI.GetStoreItemsAsync);

                while (getStore.IsDone == false)
                {
                    yield return(null);
                }

                var store = getStore.Value?.Store;

                // Caching off the store in case the user requests it again
                if (store != null)
                {
                    this.cachedStores.Add(storeId, store);
                }

                yield return(store);
            }
        }
        public UnityTask <CatalogItem> GetCatalogItem(string itemId)
        {
            if (this.IsCatalogCached)
            {
                return(UnityTask <CatalogItem> .Empty(this.GetCachedCatalogItem(itemId)));
            }
            else
            {
                return(UnityTask <CatalogItem> .Run(Coroutine()));
            }

            IEnumerator <CatalogItem> Coroutine()
            {
                var getCatalog = this.GetCatalog();

                while (getCatalog.IsDone == false)
                {
                    yield return(null);
                }

                yield return(this.GetCachedCatalogItem(itemId));
            }
        }
        public UnityTask <List <CatalogItem> > GetCatalog()
        {
            if (this.cachedCatalog != null)
            {
                return(UnityTask <List <CatalogItem> > .Empty(this.cachedCatalog));
            }
            else
            {
                return(UnityTask <List <CatalogItem> > .Run(FetchCatalog()));
            }

            IEnumerator <List <CatalogItem> > FetchCatalog()
            {
                var getCatalog = this.playfabManager.Do <GetCatalogItemsRequest, GetCatalogItemsResult>(this.getCatalogRequest, PlayFabClientAPI.GetCatalogItemsAsync);

                while (getCatalog.IsDone == false)
                {
                    yield return(null);
                }

                var catalogItems = getCatalog.Value?.Catalog;

                if (catalogItems != null)
                {
                    this.cachedCatalog = catalogItems;
                    this.catalogItemDictionary.Clear();

                    foreach (var item in this.cachedCatalog)
                    {
                        this.catalogItemDictionary.Add(item.ItemId, item);
                    }
                }

                yield return(catalogItems);
            }
        }