前提・実現したいこと
FirebaseのRealtimeDataBaseに保存しているデータを取得して
ランキングを作成したいです。
データを取得するメソッドは以下のようになっています
public void getRanking(){ //RealtileDataBaseから現在のランキングを取得 //bossNoのノードからtimeで昇順ソートして最大10件を取る(非同期) reference.Child("ranking").OrderByChild("score").LimitToFirst(10).GetValueAsync().ContinueWith(task =>{ if(task.IsFaulted){ //取得失敗 //Handle the Error Debug.Log("error"); }else if(task.IsCompleted){ //取得成功 DataSnapshot snapshot = task.Result; //結果取得 Debug.Log(snapshot); IEnumerator<DataSnapshot> en = snapshot.Children.GetEnumerator(); //結果リストをenumeratorで処理 int rank = 1; while(en.MoveNext()){ //1件ずつ処理 DataSnapshot data = en.Current; //データ取る string name = (string)data.Child("username").GetValue(true); //名前取る string score = (string)data.Child("score").GetValue(true); //スコアを取る Debug.Log("name:" + name + " score:" + score); /* //Textに反映 GameObject row = rankingSpace.transform.GetChild(rank).gameObject; row.transform.GetChild(0).gameObject.GetComponent<Text>().text = rank.ToString(); //順位 row.transform.GetChild(1).gameObject.GetComponent<Text>().text = score; //スコア row.transform.GetChild(2).gameObject.GetComponent<Text>().text = name; //名前*/ rank++; } } }); }
http://sleepnel.hatenablog.com/entry/2017/01/26/124500
このサイトを参考にしました。
発生している問題・エラーメッセージ
この状態でデバッグするとコンソールに以下のように表示され
2018-10-18 18:26:51.325065+0900 Trampoline[17731:7065346] 5.9.0 - [Firebase/Database][I-RDB034028] Using an unspecified index. Your data will be downloaded and filtered on the client. Consider adding ".indexOn": "score" at /ranking to your security rules for better performance DataSnapshot { key = ranking, value = System.Collections.Generic.Dictionary`2[System.String,System.Object] } FirebaseManager:<getRanking>m__1(Task`1) System.Threading.Tasks.<ContinueWith>c__AnonStorey0:<>m__0(Task) System.Threading.Tasks.<ContinueWith>c__AnonStorey2:<>m__0(Task) System.Threading.Tasks.<ContinueWith>c__AnonStorey1:<>m__0() System.Threading.Tasks.Task:<immediateExecutor>m__1(Action) System.Threading.Tasks.Task`1:RunContinuations() System.Threading.Tasks.Task`1:TrySetResult(T) System.Threading.Tasks.TaskCompletionSource`1:SetResult(T) System.Threading.Tasks.<ContinueWith>c__AnonStorey0:<>m__0(Task) System.Threading.Tasks.<ContinueWith>c__AnonStorey2:<>m__0(Task) System.Threading.Tasks.<ContinueWith>c__AnonStorey1:<>m__0() System.Threading.Tasks.Task:<immediateExecutor>m__1(Action) System.Threading.Tasks.Task`1:RunContinuations() System.Threading.Tasks.Task`1:TrySetResult(T) System.Threading.Tasks.TaskCompletionSource`1:SetResult(T) Firebase.Database.Internal.<GetTask>c__AnonStorey0:<>m__0() Firebase.Database.Internal.Future_InternalDataSnapshot:SWIG_CompletionDispatcher(Int32) Firebase.AppUtil:PollCallbacks() Firebase.Platform.FirebaseHandler:Update() (Filename: /Users/builduser/buildslave/unity/build/Runtime/Export/Debug.bindings.h Line: 43)
ここの部分が表示されません。
Debug.Log("name:" + name + " score:" + score);
score順に並べ替えて、usernameとscoreを取得する方法を教えていただきたいです。
よろしくお願いします。
もしくは、取得したDataSnapshotから"name"と"score"を取得する方法を教えていただきたいです。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。