分析&;Unity 3D:更新现有行
本文关键字:更新 3D amp Unity 分析 | 更新日期: 2023-09-27 18:19:28
使用Unity开发者指南中的示例代码|解析@https://www.parse.com/docs/unity_guide#objects-更新
// Create the object.
var gameScore = new ParseObject("GameScore")
{
{ "score", 1337 },
{ "playerName", "Sean Plott" },
{ "cheatMode", false },
{ "skills", new List<string> { "pwnage", "flying" } },
};
gameScore.SaveAsync().ContinueWith(t =>
{
// Now let's update it with some new data. In this case, only cheatMode
// and score will get sent to the cloud. playerName hasn't changed.
gameScore["cheatMode"] = true;
它只是添加了一个新行,并保持原来的行不变
我想我认为Parse会做一些"类似SQL"的事情,比如UPDATE,其中primaryKey=123。
在搜索答案时,我发现了这个代码@https://parse.com/questions/updating-a-field-without-retrieving-the-object-first,但在C#中没有示例。所有将其移植到C#的尝试都会导致多个语法错误。
UnityScript:
// Create a pointer to an object of class Point with id dlkj83d
var Point = Parse.Object.extend("Point");
var point = new Point();
point.id = "dlkj83d";
// Set a new value on quantity
point.set("quantity", 6);
// Save
point.save(null, {
success: function(point) {
// Saved successfully.
},
error: function(point, error) {
// The save failed.
// error is a Parse.Error with an error code and description.
}
});
Parse是否有某种方法可以使用C#更新已经存在的行?文档中的内容在哪里?他们自己的榜样怎么会这么没用?
与我的问题相关的一篇帖子说"检索对象,然后用更改将其写回",我根本不知道如何执行所述目标(尤其是在Parse Documentation的示例代码出现史诗般的失败之后)
以下是我已经能够弄清楚并工作的内容:
var query = new ParseQuery<ParseObject>("Tokens")
.WhereEqualTo ("objectId", "XC18riofu9");
query.FindAsync().ContinueWith(t =>
{
var tokens = t.Result;
IEnumerator<ParseObject> enumerator = tokens.GetEnumerator();
enumerator.MoveNext();
var token = enumerator.Current;
token["power"] = 20;
return token.SaveAsync();
}).Unwrap().ContinueWith(t =>
{
// Everything is done!
//Debug.Log("Token has been updated!");
});
第一部分检索具有所述objectId的对象,第二部分设置对象中的字段。第三部分报告操作一切顺利。
这是一个猴子看,猴子做的理解,在这一点上,我不理解代码中的细节。
可以通过创建一个名为"Tokens"的类来测试代码。在该类中创建一个tokenName字段和一个power字段。以火、水、泥为记号划几排。将.WhereEqualTo子句中的objectId替换为有效的objectId或您喜欢的任何其他搜索参数。执行代码并观察分析数据浏览器中的更改。
为了获得额外的学分,创建实现Parse文档的Chaining Tasks Together部分的示例代码所需的类。
https://www.parse.com/docs/unity_guide#tasks-链接