0
Save Dataからコードをコピーしました。このようなものですTransactionResult.Successは自分のmutableData(Firebase)を更新しません
:
void addScoreToLeaders(string name, int score ,string
key,Dictionary<string,object> childUpdates){
reference.Child ("leaders").KeepSynced (true);
reference.Child ("leaders").RunTransaction(mutableData =>{
List<Dictionary<string,object>> leaders = mutableData.Value as
List<Dictionary<string,object>>;
if(leaders == null){
leaders = new List<Dictionary<string,object>>();
} else if(mutableData.ChildrenCount >= MAX_SCORE){
int minScore = int.MaxValue;
Dictionary<string,object> minValue = null;
foreach(var child in leaders){
if(!(child is Dictionary<string,object>)) continue;
int childScore = (int)((Dictionary<string,object>)child)
["score"];
if(childScore < minScore){
minScore = childScore;
minValue = child;
}
}
if(minScore > score){
return TransactionResult.Abort();
}
leaders.Remove (minValue);
}
//Add the new high score
Dictionary<string ,object> newScoreMap = new
Dictionary<string,object>();
LeaderBoardEntry entry = new LeaderBoardEntry (name, score);
newScoreMap = entry.ToDictionary();
leaders.Add (newScoreMap);
mutableData.Value = leaders;
return TransactionResult.Success (mutableData);
});
}
いいが、二つのことがあります正しく起こりません:
TransactionResult.Success(mutableDataは)場所
に新しいデータを保存しません
私はメソッドを呼び出すたびにmutableDataを返します。