가상화폐 상점 아이템 인벤토리ㅣPlayFab




PlayFabManager.Cs 소스입니다



using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using PlayFab;
using PlayFab.ClientModels;
using UnityEngine.UI;

public class PlayFabManager : MonoBehaviour
{
    public InputField EmailInput, PasswordInput, UsernameInput;


    public void Login()
    {
        var request = new LoginWithEmailAddressRequest { Email = EmailInput.text, Password = PasswordInput.text };
        PlayFabClientAPI.LoginWithEmailAddress(request, (result) => print("로그인 성공"), (error) => print("로그인 실패"));
    }

    public void Register()
    {
        var request = new RegisterPlayFabUserRequest { Email = EmailInput.text, Password = PasswordInput.text, Username = UsernameInput.text };
        PlayFabClientAPI.RegisterPlayFabUser(request, (result) => print("회원가입 성공"), (error) => print("회원가입 실패"));
    }


    public void AddMoney()
    {
        var request = new AddUserVirtualCurrencyRequest() { VirtualCurrency = "GD", Amount = 50 };
        PlayFabClientAPI.AddUserVirtualCurrency(request, (result) => print("돈 얻기 성공! 현재 돈 : " + result.Balance), (error) => print("돈 얻기 실패"));
    }

    public void SubtractMoney()
    {
        var request = new SubtractUserVirtualCurrencyRequest() { VirtualCurrency = "GD", Amount = 50 };
        PlayFabClientAPI.SubtractUserVirtualCurrency(request, (result) => print("돈 빼기 성공! 현재 돈 : " + result.Balance), (error) => print("돈 빼기 실패"));
    }


    public void GetInventory()
    {
        PlayFabClientAPI.GetUserInventory(new GetUserInventoryRequest(), (result) =>
        {
            print("현재금액 : " + result.VirtualCurrency["GD"]);
            for (int i = 0; i < result.Inventory.Count; i++)
            {
                var Inven = result.Inventory[i];
                print(Inven.DisplayName + " / " + Inven.UnitCurrency + " / " + Inven.UnitPrice + " / " + Inven.ItemInstanceId + " / " + Inven.RemainingUses);
            }
        },
        (error) => print("인벤토리 불러오기 실패"));
    }

    public void GetCatalogItem()
    {
        PlayFabClientAPI.GetCatalogItems(new GetCatalogItemsRequest() { CatalogVersion = "Main" }, (result) =>
        {
            for (int i = 0; i < result.Catalog.Count; i++)
            {
                var Catalog = result.Catalog[i];
                print(Catalog.ItemId + " / " + Catalog.DisplayName + " / " + Catalog.Description + " / " + 
                    Catalog.VirtualCurrencyPrices["GD"] + " / "+ Catalog.Consumable.UsageCount);
            }
        },
        (error) => print("상점 불러오기 실패"));
    }


    public void PurchaseItem()
    {
        var request = new PurchaseItemRequest() { CatalogVersion = "Main", ItemId = "Apple", VirtualCurrency = "GD", Price = 10};
        PlayFabClientAPI.PurchaseItem(request, (result) => print("아이템 구입 성공"), (error) => print("아이템 구입 실패"));
    }

    public void ConsumeItem()
    {
        var request = new ConsumeItemRequest { ConsumeCount = 1, ItemInstanceId = "58F8901F46E84103" };
        PlayFabClientAPI.ConsumeItem(request, (result) => print("아이템 사용 성공"), (error) => print("아이템 사용 실패"));
    }
}