用Firebase数据库处理事务和数组。

问题描述 投票:0回答:1

我正在使用以下方法保存排行榜数据 保存数据

我正在寻找一种方法来删除Firebase事务的数组编号,并将其替换为 userId 让我能够更新用户信息.代码。

 private TransactionResult AddScoreTransaction(MutableData mutableData)
    {
        playerNewGlobalScore = false;
        List<object> leaders = mutableData.Value as List<object>;
        if (leaders == null)
        {
            leaders = new List<object>();
        }
        else if (mutableData.ChildrenCount >= LeaderBoardManager.Instance.MaxScoreRows)
        {
            // If the current list of scores is greater or equal to our maximum allowed number,
            // we see if the new score should be added and remove the lowest existing score.
            long minScore = long.MaxValue;
            object minVal = null;

            foreach (var child in leaders)
            {
                if (!(child is Dictionary<string, object>))
                    continue;
                long childScore = (long)((Dictionary<string, object>)child)["score"];
                if (childScore < minScore)
                {
                    minScore = childScore;
                    minVal = child;
                }
            }
            // If the new score is lower than the current minimum, we abort.
            if (minScore > Score)
            {
                return TransactionResult.Abort();
            }
            // Otherwise, we remove the current lowest to be replaced with the new score.

            leaders.Remove(minVal);
        }

        // Now we add the new score as a new entry that contains the email address and score.
        Dictionary<string, object> newScoreMap = new Dictionary<string, object>();

        newScoreMap["name"] = Name;
        newScoreMap["country"] = Country;
        newScoreMap["photoUrl"] = PhotoUrl;
        newScoreMap["level"] = Level;
        newScoreMap["userId"] = UserId;
        newScoreMap["score"] = Score;

        leaders.Add(newScoreMap);

        // You must set the Value to indicate data at that location has changed.
        mutableData.Value = leaders;

        playerNewGlobalScore = true;
        return TransactionResult.Success(mutableData);
    }

实时数据库的例子:enter image description here

c# firebase unity3d firebase-realtime-database
1个回答
0
投票

https:/cloud.google.comsupport#support-plansFirebase不支持C#,他们对此很满意(见图) https:/stackshare.iostackupsfirebase-vs-pusher-vs-signalr。),firestore就有。他们建议你去。https:/groups.google.comforum#!forumfirebase-talk。 然而 https:/github.comstep-up-labsfirebase-database-dotnet。 从 Step Up Labs, Inc. (使用NuGet Firebase)对于所有你想通过REST API做的事情都很有用。https:/firebase.google.comdocsreferencerestdatabase。 在文档的底层是"有条件的请求,相当于SDK的REST 交易业务,根据某个条件更新数据。请查看工作流程的概述,并了解更多关于保存数据中REST的条件请求的信息。",可以在 https:/firebase.google.comdocsdatabaserestsave-data#section-conditional-requests。 希望对大家有所帮助。

© www.soinside.com 2019 - 2024. All rights reserved.