C# 如何在保存后立即检索objectId
我正在使用Unity和Parse.com进行游戏开发。我试图找出在保存后立即检索objectId的方法。我试过这个:C# 如何在保存后立即检索objectId,c#,multithreading,unity3d,parse-platform,C#,Multithreading,Unity3d,Parse Platform,我正在使用Unity和Parse.com进行游戏开发。我试图找出在保存后立即检索objectId的方法。我试过这个: ParseObject myGame = new ParseObject("Games"); myGame["score"] = 223; myGame["playerName"] = "Michael"; Task saveTask = myGame.SaveAsync().ContinueWith(t => { ParseObject theObject =
ParseObject myGame = new ParseObject("Games");
myGame["score"] = 223;
myGame["playerName"] = "Michael";
Task saveTask = myGame.SaveAsync().ContinueWith(t => {
ParseObject theObject = t.Result;
string newObjectId = theObject.objectId;
});
我在t上得到一个错误。结果是:
Type `System.Threading.Tasks.Task' does not contain a definition for `Result' and no
extension method `Result' of type `System.Threading.Tasks.Task' could be found (are
you missing a using directive or an assembly reference?)
这件事可以这样或那样做吗
感谢您的帮助:-)只需删除带有t.Result的行即可。
使用myGame.objectID获取objectID。我在检索新创建的
objectID
时也遇到问题。经过几个小时(以及大量搜索),我能够获得以下代码:
public static async Task<string> CreateNewGame()
{
string newObjectId = null;
ParseObject myGame = new ParseObject("Games");
myGame["score"] = 223;
myGame["playerName"] = "Michael";
await myGame.SaveAsync().ContinueWith(
t =>
{
newObjectId = myGame.ObjectId;
});
return newObjectId;
}
公共静态异步任务CreateNewGame()
{
字符串newObjectId=null;
ParseObject myGame=新的ParseObject(“游戏”);
myGame[“分数”]=223;
我的游戏[“玩家名称”]=“迈克尔”;
等待myGame.SaveAsync().ContinueWith(
t=>
{
newObjectId=myGame.ObjectId;
});
返回newObjectId;
}
这是因为任务没有Result属性
Ok,所以我无法在保存后立即获取ObjectID,那么?我需要创建一个新的请求吗?尝试删除带有t.Result的行,然后在下一步中使用myGame.objectIDline@Reniuz我收到一个错误-错误CS0246:找不到类型或命名空间名称'Task'。是否缺少using指令或程序集引用?你能帮我一下吗?使用System.Threading.Tasks添加代码>