예제 #1
0
        private void parseItems(string id, GetCatalogItemsResult result, Action <CatalogModel> successHandler)
        {
            IJsonParser  jsonParser   = new PlayFabClientJsonParser();
            CatalogModel catalogModel = new CatalogModel(id);

            for (int i = 0; i < result.Catalog.Count; i++)
            {
                CatalogItem catalogItem = result.Catalog[i];
                catalogModel.AddItemWithStackCount(
                    PlayFabItemFactory.GetItemModelFromCatalogItem(
                        catalogItem.ItemId,
                        catalogItem.ItemClass,
                        catalogItem.DisplayName,
                        catalogItem.Description,
                        catalogItem.CustomData,
                        jsonParser));
            }
            successHandler(catalogModel);
        }
예제 #2
0
        protected override void getCatalog(string catalogID, Action <CatalogModel> onSuccessHandler, Action onFailureHandler)
        {
            GetCatalogItemsRequest request = new GetCatalogItemsRequest();

            request.CatalogVersion = catalogID;

            IJsonParser jsonParser = new PlayFabServerJsonParser();

            PlayFabServerAPI.GetCatalogItemsAsync(request).ContinueWith(t => {
                if (t.Result.Error != null)
                {
                    Log.Error("PlayFabCatalogService error getting catalog: " + t.Result.Error.ErrorMessage);
                    onFailureHandler();
                }
                else
                {
                    CatalogModel catalogModel = new CatalogModel(catalogID);
                    for (int i = 0; i < t.Result.Result.Catalog.Count; i++)
                    {
                        try {
                            CatalogItem catalogItem = t.Result.Result.Catalog[i];
                            ItemModel itemModel     = PlayFabItemFactory.GetItemModelFromCatalogItem(
                                catalogItem.ItemId,
                                catalogItem.ItemClass,
                                catalogItem.DisplayName,
                                catalogItem.Description,
                                catalogItem.CustomData,
                                jsonParser);
                            catalogModel.AddItemWithStackCount(itemModel);
                        } catch (Exception) {
                            Log.Warning("PlayFabCatalogService couldn't parse item with ID: " +
                                        t.Result.Result.Catalog[i].ItemId);
                            continue;
                        }
                    }
                    onSuccessHandler(catalogModel);
                }
            });
        }