Exemple #1
0
    void OnPurchased(PurchaseItemResult res)
    {
        Debug.Log("ITEM BOUGHT (" + res.Items.Count + ") " + res.Items[0].DisplayName);

        Debug.Log("inventory count " + ClientSessionData.Instance.InventoryItems.Count);
        //updating UI
        labCO.text = ClientSessionData.Instance.currencyCO.ToString();
        labPC.text = ClientSessionData.Instance.currencyPC.ToString();

        //add to inventory
        FMInventoryItem inviItem = ClientSessionData.Instance.InventoryItems.Find(x => x.CatalogID.Equals(res.Items[0].ItemId));

        //if there is already an instance id, we just add 1
        if (inviItem != null && inviItem.IsStackable)
        {
            inviItem.Amount += 1;
            labOwned.text    = inviItem.Amount.ToString();
            Debug.Log("inventory new count (stack)" + ClientSessionData.Instance.InventoryItems.Count);
            return;
        }

        //if the item is new or not stackable, we add it to the inventory
        if (inviItem == null)
        {
            CatalogItem cItem = ClientSessionData.Instance.CatalogItems.Find(x => x.ItemId.Equals(res.Items[0].ItemId));
            FMPlayFabInventory.AddInventoryItem(res.Items[0], ClientSessionData.Instance.InventoryItems, cItem);
            Debug.Log("inventory new count " + ClientSessionData.Instance.InventoryItems.Count);
        }
    }
Exemple #2
0
    /// <summary>
    /// nesting so many callbacks is not that good practice, but for the sake of
    /// keeping it sinchronous, we'll do it just this one time
    /// </summary>
    /// <param name="logResult"></param>
    void OnLoginSuccess(LoginResult logResult)
    {
        List <ItemInstance> inventoryItems = new List <ItemInstance>();

        //get display name
        PlayFabClientAPI.GetAccountInfo(new GetAccountInfoRequest()
        {
            PlayFabId = logResult.PlayFabId
        }, result =>
        {
            ClientSessionData.Instance.PlayfabID = logResult.PlayFabId;
            ClientSessionData.Instance.UserName  = result.AccountInfo.TitleInfo.DisplayName;
            labLoading.text = "... Loading user info ...";
            progress       += 0.20f;
            total          += progress;

            //get currency
            PlayFabClientAPI.GetUserInventory(new GetUserInventoryRequest(), resInventory =>
            {
                //currency
                int CO = 0;
                int PC = 0;
                resInventory.VirtualCurrency.TryGetValue("CO", out CO);
                resInventory.VirtualCurrency.TryGetValue("PC", out PC);
                ClientSessionData.Instance.currencyCO = CO;
                ClientSessionData.Instance.currencyPC = PC;

                //inventory
                inventoryItems  = resInventory.Inventory;
                labLoading.text = "... Loading Inventory ...";
                progress       += 0.20f;
                //total += progress;

                //statistics
                PlayfabUtils.Instance.GetPlayerStatistics(null, statRes =>
                {
                    FMPlayfabUserStatistics.StoreItemsFromJson(statRes);
                    ClientSessionData.Instance.Statistics = FMPlayfabUserStatistics.Items;
                    labLoading.text = "... Loading User Statistics ...";
                    progress       += 0.20f;
                    total          += progress;

                    //get title Data
                    PlayfabUtils.Instance.GetTitleData(new List <string> {
                        "fm_achievements", "fm_rewards"
                    }, titleRes =>
                    {
                        FMPlayfabAchievements.Instance.StoreItemsFromJson(titleRes);
                        FMPlayfabReward.StoreItemsFromJson(titleRes);

                        ClientSessionData.Instance.Achievements = FMPlayfabAchievements.Items;
                        ClientSessionData.Instance.Rewads       = FMPlayfabReward.Items;

                        labLoading.text = "... Loading Title Data ...";
                        progress       += 0.20f;
                        total          += progress;

                        //get catalogItems
                        PlayFabClientAPI.GetCatalogItems(new GetCatalogItemsRequest(), catalogRes =>
                        {
                            ClientSessionData.Instance.CatalogItems = catalogRes.Catalog;

                            //crossing CatalogItem and ItemInstance items
                            FMPlayFabInventory.StoreItemsFromPlayfab(catalogRes.Catalog, inventoryItems);
                            ClientSessionData.Instance.InventoryItems = FMPlayFabInventory.Items;

                            //TODO cross catalog and instance items;
                            labLoading.text = "... Loading Catalog Items ...";
                            progress       += 0.20f;
                            total          += progress;
                        }
                                                         , error => { Debug.Log("error on get catalog info"); });
                        //end catalog
                    }, error => { Debug.Log("error on get title info"); });
                    //end get title
                }, error => { Debug.Log("error on getting statistics"); });
                //end get Statistics
            }
                                              , error => { Debug.Log("error on get currency info"); });
            //end get currency
        }, error => { Debug.Log("error on get account info"); });
        //end get account info
    }