LoginSignup
4
0

More than 3 years have passed since last update.

【playfab】クライアントAPIで手持ちのアイテム情報を全部精査

Last updated at Posted at 2019-10-13

playfab、クラウドスクリプトの方ばっかりいじってたらクライアントAPIの方で少し躓く。
自分の手持ちアイテムとその情報を全て精査する方法で少し詰まったので記載。

プレイヤーの手持ちのアイテムを取得する方法として、PlayFabClientAPI.GetUserInventoryを呼ぶ。その結果が「result」と名前にしたとして…

  • 型はGetUserInventoryResultとなるので他のと間違わないように注意
  • 「result.Inventory」でインベントリ全体の情報
  • Inventoryの中のものは「ItemInstance型」として取得

あとは個々にパラメータを取れた。


    public void getInventoryAll()
    {
        PlayFabClientAPI.GetUserInventory(new GetUserInventoryRequest(), result =>
        {
            foreach(ItemInstance item in result.Inventory)
            {
                Debug.Log(item.ItemId);
                Debug.Log(item.DisplayName);
                Debug.Log(item.CustomData["skillLv"]);  //skillLvというカスタムデータを取得する場合
            }
        }, error => Debug.Log(error.GenerateErrorReport()));
    }


GetUserInventoryResultはこちらに情報が。ItemInstance型配列ってのも書いてましたね。。。
https://docs.microsoft.com/en-us/rest/api/playfab/client/player-item-management/getuserinventory?view=playfab-rest#getuserinventoryresult

解決のきっかけになった質問。てかplayfabじゃなくてunityコミュニティにあった。
https://answers.unity.com/questions/994665/accessing-instances-in-object-array-playfab.html

4
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
0