GameSparks的连接与应用(Unity)--(7)添加虚拟货物
添加一个虚拟货物
没显示参数的都为默认
首先你需要有货币
在GameSparks上购买虚拟货物
成功后返回信息
在GameSparks上消耗虚拟货物
在Unity上查询虚拟货物
new GameSparks.Api.Requests.AccountDetailsRequest().Send((response) =>
{
if (!response.HasErrors)
{
Debug.Log("Account Details Found...");
string playerName = response.DisplayName; // we can get the display name
int cashAvailable = (int)response.Currency1;
int goldCoinsAvailable = (int)response.VirtualGoods.GetNumber("GOLD_COIN");
Debug.Log("Display Name: " + playerName);
Debug.Log("VirtualGoods -- GOLD_COIN: " + goldCoinsAvailable.ToString());
}
else
{
Debug.Log("Error Retrieving Account Details...");
}
});
在Unity上购买虚拟货物
new GameSparks.Api.Requests.BuyVirtualGoodsRequest()
.SetCurrencyShortCode("CURRENCY_A")//货币名称
//.SetCurrencyType(1)//此句和上一行的SetCurrencyShortCode不能同时存在,有一个就行
.SetQuantity(1)//购买数量
.SetShortCode("GOLD_COIN")//虚拟货物名称
.Send((response) =>
{
if (!response.HasErrors)
{
Debug.Log("Virtual Goods Bought Successfully...");
}
else
{
Debug.Log("Error Buying Virtual Goods...");
}
});
在Unity上消耗虚拟货物
new GameSparks.Api.Requests.ConsumeVirtualGoodRequest()
.SetQuantity(1)//消耗数量
.SetShortCode("GOLD_COIN")//虚拟货物名称
.Send((response) =>
{
if (!response.HasErrors)
{
Debug.Log("Virtual Goods Consumed Successfully...");
}
else
{
Debug.Log("Error Consuming Virtual Goods...");
}
});
相关GameSparks端代码
Spark.getPlayer().credit1(20); //给"currency1"的数量增加20
Spark.getPlayer().credit("CURRENCY_A", 20, "");//给货币"CURRENCY_A"的数量增加20