【发布时间】:2015-11-25 00:08:08
【问题描述】:
我正在尝试使用
UpdateUserData
向用户添加/更新键值对,但出现此错误:
Assets/PlayFabManager.cs(73,36):错误 CS0246:类型或命名空间 找不到名称“字典”。你错过了一个使用 指令还是程序集引用?
我尝试在谷歌上关注其他解决方案,但我无法让它们工作。我们怎样才能让它发挥作用?
我的代码:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using PlayFab;
using PlayFab.ClientModels;
public class PlayFabManager : MonoBehaviour {
public string PlayFabId;
void Login(string titleId)
{
LoginWithCustomIDRequest request = new LoginWithCustomIDRequest()
{
TitleId = titleId,
CreateAccount = true,
CustomId = SystemInfo.deviceUniqueIdentifier
};
PlayFabClientAPI.LoginWithCustomID(request, (result) => {
PlayFabId = result.PlayFabId;
Debug.Log("Got PlayFabID: " + PlayFabId);
if(result.NewlyCreated)
{
Debug.Log("(new account)");
}
else
{
Debug.Log("(existing account)");
SetUserData();
GetUserData();
}
},
(error) => {
Debug.Log("Error logging in player with custom ID:");
Debug.Log(error.ErrorMessage);
});
}
void GetUserData()
{
GetUserDataRequest request = new GetUserDataRequest()
{
PlayFabId = PlayFabId,
Keys = null
};
PlayFabClientAPI.GetUserData(request,(result) => {
Debug.Log("Got user data:");
if ((result.Data == null) || (result.Data.Count == 0))
{
Debug.Log("No user data available");
}
else
{
Debug.Log (result.Data["age"].Value);
foreach (var item in result.Data)
{
Debug.Log(" " + item.Key + " == " + item.Value.Value);
}
}
}, (error) => {
Debug.Log("Got error retrieving user data:");
Debug.Log(error.ErrorMessage);
});
}
void SetUserData()
{
UpdateUserDataRequest request = new UpdateUserDataRequest()
{
Data = new Dictionary(){
{"Ancestor", "Arthur"},
{"Successor", "Fred"}
}
};
PlayFabClientAPI.UpdateUserData(request, (result) =>
{
Debug.Log("Successfully updated user data");
}, (error) =>
{
Debug.Log("Got error setting user data Ancestor to Arthur");
Debug.Log(error.ErrorDetails);
});
}
void Awake(){
PlayFabSettings.TitleId = "HIDDEN"; //your title id goes here.
}
// Use this for initialization
void Start () {
Login ("HIDDEN");
}
// Update is called once per frame
void Update () {
}
}
谢谢!
【问题讨论】:
标签: c# dictionary unity3d