コード例 #1
0
    //指定したレコードの前後のレコード取得
    public void getRankingNeighbors(string name, int gameModeId, Save_ranking_item save_Ranking_Item, CallbackRecordsList callback)
    {
        fetchRank(name, gameModeId, save_Ranking_Item, (int currentRank) =>
        {
            int numSkip = currentRank - 3;
            if (numSkip < 0)
            {
                numSkip = 0;
            }

            List <RankingRecord> rankingRecords = new List <RankingRecord>();
            NCMBQuery <NCMBObject> query        = new NCMBQuery <NCMBObject>(rankingClassName);
            query.WhereEqualTo("gameModeId", gameModeId);
            query.WhereEqualTo("type", (int)save_Ranking_Item);
            query.Skip  = numSkip;
            query.Limit = 5;
            switch (save_Ranking_Item)
            {
            case Save_ranking_item.SAVE_RANKING_HIGH:
                query.OrderByDescending("distance");
                query.AddAscendingOrder("timeSpan");
                break;

            case Save_ranking_item.SAVE_RANKING_LOW:
                query.OrderByAscending("distance");
                query.AddAscendingOrder("timeSpan");
                break;

            default:
                break;
            }
            query.FindAsync((List <NCMBObject> objList, NCMBException e) =>
            {
                if (e == null)
                { //検索成功したら
                    for (int i = 0; i < objList.Count; i++)
                    {
                        string _name                = System.Convert.ToString(objList[i]["name"]);     // 名前を取得
                        float _distance             = System.Convert.ToSingle(objList[i]["distance"]); // スコアを取得
                        float _timeSpan             = System.Convert.ToSingle(objList[i]["timeSpan"]);
                        RankingRecord rankingRecord = new RankingRecord(numSkip + i + 1, _name, _distance, _timeSpan, save_Ranking_Item);
                        rankingRecords.Add(rankingRecord);
                    }
                    callback(rankingRecords);
                }
                else
                {
                    callback(rankingRecords);
                }
            });
        });
        return;
    }
コード例 #2
0
    /// <summary>
    /// データストアからメッセージを取得する
    /// </summary>
    private void FetchDatastore()
    {
        //Scoreフィールドの降順でデータを取得
        query.AddAscendingOrder("createDate");
        query.Limit = 1000;

        //データストアでの検索を行う
        query.FindAsync((List <NCMBObject> objList, NCMBException e) => {
            if (e != null)
            {
                //検索失敗時の処理
            }
            else
            {
                if (dataCount == 0 || dataCount != objList.Count)
                {
                    for (int i = dataCount; i < objList.Count; i++)
                    {
                        // mBaaSから取得
                        string _name      = objList[i]["name"] as string;
                        string _message   = objList[i]["message"] as string;
                        string _photoName = objList[i]["photoName"] as string;

                        // パネルをめくる
                        StartCoroutine(CurlPannel(_name, _message, _photoName));
                    }

                    // データカウント
                    dataCount = objList.Count;
                }
            }
        });
    }
コード例 #3
0
    //ランキング
    //引数levelは online easy normal hard expertのどれか
    public static void getRanking(string level, Text text)
    {
        NCMBQuery <NCMBObject> query = new NCMBQuery <NCMBObject> ("HighScore");

        query.OrderByDescending(level);    //Scoreを降順で並べ替え
        query.AddAscendingOrder("userName");

        query.FindAsync((List <NCMBObject> objList, NCMBException e) => {
            //検索成功したら
            if (e == null)
            {
                Debug.Log(objList.Count);
                for (int i = 0; i < objList.Count && i < 10; i++)
                {
                    if (userName == System.Convert.ToString(objList[i]["userName"]))
                    {
                        text.text += "<b><color=red>";
                    }
                    text.text += (i + 1) + ". " + System.Convert.ToString(objList[i]["userName"]);
                    text.text += " : " + System.Convert.ToString(objList[i][level]) + "\n";
                    if (userName == System.Convert.ToString(objList[i]["userName"]))
                    {
                        text.text += "</color></b>";
                    }
                }
                for (int i = objList.Count; i < 10; i++)
                {
                    text.text += (i + 1) + ". Unkown\n";
                }
            }
            else
            {
                Debug.Log("エラー" + e.ErrorCode + ":" + e.Message);
            }
        });
    }
コード例 #4
0
ファイル: RecordManager.cs プロジェクト: aimy-07/UniFight
    public void GetRanking()
    {
        nowLoading.SetActive(true);
        failedLoading.SetActive(false);
        refreshButton.interactable = false;
        NCMBQuery <NCMBObject> query = new NCMBQuery <NCMBObject> ("DataBase");

        query.OrderByDescending("winCount");                    // 勝った回数を降順(多い順)に並び替える
        query.AddAscendingOrder("loseCount");                   //さらに負けた回数を昇順(少ない順)で並べ替え
        query.Limit = 10;                                       // 上位10件のみ取得
        query.FindAsync((List <NCMBObject> objList, NCMBException e) => {
            if (e == null)                                      //検索成功したら
            {
                List <string> idList     = new List <string>(); // idのリスト
                List <string> nameList   = new List <string>(); // 名前のリスト
                List <int> winCountList  = new List <int>();    // 勝った回数のリスト
                List <int> loseCountList = new List <int>();    // 負けた回数のリスト
                for (int i = 0; i < objList.Count; i++)
                {
                    string _id = System.Convert.ToString(objList[i]["id"]);       // idを取得
                    string n   = System.Convert.ToString(objList[i]["name"]);     // 名前を取得
                    int w      = System.Convert.ToInt32(objList[i]["winCount"]);  // 勝った回数を取得
                    int l      = System.Convert.ToInt32(objList[i]["loseCount"]); //  負けた回数を取得
                    idList.Add(_id);
                    nameList.Add(n);                                              // リストに突っ込む
                    winCountList.Add(w);
                    loseCountList.Add(l);
                }
                int rank = 1;
                for (int i = 0; i < rankItems.Length; i++)
                {
                    if (i < nameList.Count)
                    {
                        if (idList[i] == id)
                        {
                            rankItems[i].GetComponent <Image>().sprite = rankItemSprites[1];
                        }
                        else
                        {
                            rankItems[i].GetComponent <Image>().sprite = rankItemSprites[0];
                        }
                        rankItems[i].GetComponent <Image>().color = Color.white;
                        rankItems[i].transform.Find("RankText").gameObject.GetComponent <Text>().text  = rank + "位";
                        rankItems[i].transform.Find("NameText").gameObject.GetComponent <Text>().text  = nameList[i];
                        rankItems[i].transform.Find("CountText").gameObject.GetComponent <Text>().text = winCountList[i] + "勝 / " + loseCountList[i] + "敗";
                        if (i < nameList.Count - 1 && winCountList[i + 1] == winCountList[i] && loseCountList[i + 1] == loseCountList[i])
                        {
                            // 次が同率順位のスコア
                        }
                        else
                        {
                            rank++;
                        }
                    }
                    else
                    {
                        // rankItems[i].SetActive(false);
                        rankItems[i].GetComponent <Image>().sprite = rankItemSprites[0];
                        rankItems[i].GetComponent <Image>().color  = new Color(0.7f, 0.7f, 0.7f);
                        rankItems[i].transform.Find("RankText").gameObject.GetComponent <Text>().text  = rank + "位";
                        rankItems[i].transform.Find("NameText").gameObject.GetComponent <Text>().text  = "No Data";
                        rankItems[i].transform.Find("CountText").gameObject.GetComponent <Text>().text = "--勝 / --敗";
                        rank++;
                    }
                }
                nowLoading.SetActive(false);
                refreshButton.interactable = true;
                AudioSourceManager.PlaySE(6);
            }
            else      //ネットワークに接続していないなどでデータが取れなかった時
            {
                nowLoading.SetActive(false);
                failedLoading.SetActive(true);
                refreshButton.interactable = true;
                AudioSourceManager.PlaySE(4);
            }
        });
    }