GameSparks的连接与应用(Unity)--(6)添加成就
添加一个成就
首先你需要有一个货币,如果没有请看
GameSparks的连接与应用(Unity)--(5)添加货币
添加一个事件
填入代码
var player = Spark.getPlayer();//获得当前玩家
player.addAchievement("Cloud_Achievement");//使玩家获得"Cloud_Achievement"成就
查询货币
需要先登陆,参见
GameSparks的连接与应用(Unity)--(2)玩家登陆
执行获得成就(如果前面设置了成就不重复则只能获得一次成就)
再次查询
unity端添加获得成就(需要先登录)
new GameSparks.Api.Requests.LogEventRequest()
.SetEventKey("Award_Achievement")//与Short Code相对应
.Send((response) =>
{
if (!response.HasErrors)
{
Debug.Log("Achivement Awarded Scucessfully...");
}
else
{
Debug.Log("Error Awarding Achivement...");
Debug.Log(response.HasErrors);
}
});
unity端获得账户所有信息
/*可以获得账户的所有细节信息*/
Debug.Log("Fetching Account Details...");
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
List<string> achievementsList = response.Achievements; // we can get a list of achievements earned
// we can grab all the currency-types into a list //
List<int> currencyList = new List<int>()
{
int.Parse(response.Currency1.ToString()),
int.Parse(response.Currency2.ToString()),
int.Parse(response.Currency3.ToString()),
int.Parse(response.Currency4.ToString()),
int.Parse(response.Currency5.ToString()),
int.Parse(response.Currency6.ToString()),
};
Debug.Log ("Display Name: " + playerName);
Debug.Log("CURRENCY_A: " + response.Currencies.GetLong("CURRENCY_A"));//获得货币CURRENCY_A的数量
Debug.Log ("Currency1: " + currencyList[0]);
Debug.Log ("Currency2: " + currencyList[1]);
Debug.Log ("Currency3: " + currencyList[2]);
Debug.Log ("Currency4: " + currencyList[3]);
Debug.Log ("Currency5: " + currencyList[4]);
Debug.Log ("Currency6: " + currencyList[5]);
}
else
{
Debug.Log("Error Retrieving Account Details...");
}
});