public IEnumerator FileDeleteTest() { byte[] data = System.Text.Encoding.UTF8.GetBytes("delete test"); NCMBFile file = new NCMBFile("delete.txt", data); file.SaveAsync((NCMBException error) => { Assert.Null(error); NCMBTestSettings.CallbackFlag = true; }); yield return(NCMBTestSettings.AwaitAsync()); NCMBTestSettings.CallbackFlag = false; Assert.NotNull(file.CreateDate); file.DeleteAsync((NCMBException error) => { Assert.Null(error); NCMBTestSettings.CallbackFlag = true; }); yield return(NCMBTestSettings.AwaitAsync()); NCMBTestSettings.CallbackFlag = false; NCMBQuery <NCMBFile> query = NCMBFile.GetQuery(); query.WhereEqualTo("fileName", "delete.txt"); query.FindAsync((List <NCMBFile> objList, NCMBException error) => { Assert.Null(error); Assert.AreEqual(0, objList.Count); NCMBTestSettings.CallbackFlag = true; }); yield return(NCMBTestSettings.AwaitAsync()); Assert.True(NCMBTestSettings.CallbackFlag); }
public IEnumerator FileACLTest() { byte[] data = System.Text.Encoding.UTF8.GetBytes("acl test"); NCMBACL acl = new NCMBACL(); acl.PublicReadAccess = true; NCMBFile file = new NCMBFile("ACL.txt", data, acl); file.SaveAsync((NCMBException error) => { NCMBTestSettings.CallbackFlag = true; }); yield return(NCMBTestSettings.AwaitAsync()); NCMBTestSettings.CallbackFlag = false; NCMBQuery <NCMBFile> query = NCMBFile.GetQuery(); query.WhereEqualTo("fileName", "ACL.txt"); query.FindAsync((List <NCMBFile> objList, NCMBException error) => { Assert.Null(error); NCMBFile getFile = objList [0]; Assert.True(getFile.ACL.PublicReadAccess); Assert.False(getFile.ACL.PublicWriteAccess); NCMBTestSettings.CallbackFlag = true; }); yield return(NCMBTestSettings.AwaitAsync()); Assert.True(NCMBTestSettings.CallbackFlag); }
// サーバーからハイスコアを取得 ----------------- public void Fetch() { // データストアの「HighScore」クラスから、Nameをキーにして検索 NCMBQuery <NCMBObject> query = new NCMBQuery <NCMBObject> ("HighScore"); query.WhereEqualTo("Name", name); query.FindAsync((List <NCMBObject> objList, NCMBException e) => { //検索成功したら if (e == null) { // ハイスコアが未登録だったら if (objList.Count == 0) { NCMBObject obj = new NCMBObject("HighScore"); obj ["Name"] = name; obj ["Score"] = 0; obj.SaveAsync(); highscore = 0; } // ハイスコアが登録済みだったら else { highscore = System.Convert.ToInt32(objList [0] ["Score"]); } } }); }
public IEnumerator SetRecentClearTextFromClearResult() { NCMBQuery <NCMBObject> query = new NCMBQuery <NCMBObject>(SceneManager.GetActiveScene().name); List <NCMBObject> result = null; NCMBException error = null; query.OrderByDescending("createDate"); query.Limit = 9; query.FindAsync((List <NCMBObject> _result, NCMBException _error) => { result = _result; error = _error; }); //resultもしくはerrorが入るまで待機 yield return(new WaitWhile(() => result == null && error == null)); //後続処理 if (error == null) { this.SetRecentClearTextFromClearResult(result); } else { Debug.Log(error); } }
void NameSet() { NCMBQuery <NCMBObject> query = new NCMBQuery <NCMBObject>("OnlineRanking"); query.WhereEqualTo("objectId", PlayerPrefs.GetString("ID")); query.FindAsync((List <NCMBObject> objectlist, NCMBException e) => { if (e != null) { Debug.Log("Miss"); connecttext.text = "接続に失敗しました"; connectmessage = true; connectmessagetimer = 0; } else { Debug.Log("ObjectID=" + objectlist[0].ObjectId); PlayerPrefs.SetString("Name", nameinput.text); objectlist[0]["UserName"] = PlayerPrefs.GetString("Name"); objectlist[0].SaveAsync(); connecttext.text = ""; namepanel.SetActive(false); } }); }
// サーバーからハイスコアを取得する public void fetch() { Debug.Log ("fetch name " + name); // データストアの「HighScore」から,Nameをキーにして検索する NCMBQuery<NCMBObject> query = new NCMBQuery<NCMBObject> ("HighScore"); query.WhereEqualTo ("Name", name); query.FindAsync ((List<NCMBObject> objList ,NCMBException e) => { //検索が成功した場合 if (e == null) { // ハイスコアが未登録だった場合 if (objList.Count == 0) { NCMBObject obj = new NCMBObject ("HighScore"); obj ["Name"] = name; obj ["Score"] = 0; obj.SaveAsync (); //score = 0; Debug.Log ("取得1"); } // ハイスコアが登録済みだった場合 else { score = System.Convert.ToInt32 (objList [0] ["Score"]); Debug.Log ("取得2"); } } }); }
// ランキングをサーバーから取得し適用 public void GetRanking() { Loading(); NCMBQuery <NCMBObject> query = new NCMBQuery <NCMBObject> ("Ranking"); query.OrderByAscending("Time"); query.Limit = 30; query.FindAsync((List <NCMBObject> objList, NCMBException e) => { if (e != null) { ShowToast("エラーが発生しました。"); } else { // ランカーの内容を適用していく Transform rankerParent = GameObject.Find("UI/Ranking/Panel/LeaderBoard/Viewport/Content").transform; int r = 0; foreach (NCMBObject obj in objList) { r++; float s = (float)System.Convert.ToDouble(obj["Time"]); string n = System.Convert.ToString(obj["Name"]); GameObject ranker = Instantiate(rankerPrefab, rankerParent); ranker.transform.GetChild(0).GetComponent <Text> ().text = r.ToString(); ranker.transform.GetChild(1).GetComponent <Text> ().text = n; ranker.transform.GetChild(2).GetComponent <Text> ().text = s.ToString(); } } LoadEnd(); }); }
// サーバーからトップ10を取得 public void FetchTopRankers() { // データストアのHiScoreクラスから検索 NCMBQuery <NCMBObject> query = new NCMBQuery <NCMBObject>("HiScore"); query.OrderByDescending("score"); query.Limit = 10; query.FindAsync((List <NCMBObject> objList, NCMBException e) => { if (e != null) { //検索失敗時の処理 } else { //検索成功時の処理 List <LeaderBoardSet> list = new List <LeaderBoardSet>(); // 取得したレコードをリーダーボードクラスとして保存 foreach (NCMBObject obj in objList) { int s = System.Convert.ToInt32(obj["score"]); string n = System.Convert.ToString(obj["name"]); list.Add(new LeaderBoardSet(n, s)); } m_TopRankers = list; ShowLeaderBoard(); } }); }
public void FetchTopRankingData() { NCMBQuery <NCMBObject> query = new NCMBQuery <NCMBObject> ("HighScore"); //ここでqueryに色々条件を与える query.OrderByDescending("score"); query.Limit = 5; query.FindAsync((List <NCMBObject> objList, NCMBException e) => { if (e != null) { //検索失敗時の処理 } else { //検索成功時の処理 // 取得したレコードをHighScoreクラスとして保存 foreach (var obj in objList) { int s = System.Convert.ToInt32(obj ["score"]); string n = System.Convert.ToString(obj ["name"]); HighScore highScore = new HighScore(); highScore.name = n; highScore.score = s; // Debug.Log("score"+s,"name"+n); highScoreList.Add(highScore); } } }); }
void Start() { if (instance == null) { instance = this; } DontDestroyOnLoad(this); volumeClass = new NCMBObject("VolumeClass"); NCMBQuery <NCMBObject> query = new NCMBQuery <NCMBObject>("VolumeClass"); query.FindAsync((List <NCMBObject> objList, NCMBException e) => { if (e == null) { if (objList.Count != 0) { volumeClass.ObjectId = objList[0].ObjectId; } } else { print("Error:" + e); } volumeClass["s"] = 0; volumeClass["a"] = 0; volumeClass.SaveAsync(); }); }
public IEnumerator SetHighRankingTextFromFailedResult() { NCMBQuery <NCMBObject> query = new NCMBQuery <NCMBObject>(SceneManager.GetActiveScene().name); List <NCMBObject> result = null; NCMBException error = null; if (TimeManager.Instance.CountTimeType == E_CountTimeType.CountUp) { query.OrderByAscending("ClearTime"); //昇順 } else { query.OrderByDescending("ClearTime"); //降順 } query.Limit = 10; query.FindAsync((List <NCMBObject> _result, NCMBException _error) => { result = _result; error = _error; }); //resultもしくはerrorが入るまで待機 yield return(new WaitWhile(() => result == null && error == null)); //後続処理 if (error == null) { this.SetHighRankingTextFromFailedResult(result); } }
private void FetchScoreList(int higherThan) { //여러 개의 NCMBObject를 취득하는 쿼리를 작성 NCMBQuery <NCMBObject> query = new NCMBQuery <NCMBObject>("PlayerData"); //조건 설정 query.WhereGreaterThan("Score", higherThan); query.FindAsync((List <NCMBObject> objList, NCMBException e) => { if (e != null) { //오류 시 처리 } else { //성공 시 처리 foreach (NCMBObject obj in objList) { Debug.Log( "PlayerName:" + obj["PlayerName"] + ", Score:" + obj["Score"] + ", Coin:" + obj["Coin"] ); } } }); }
public void Yes() { NCMBUser.CurrentUser["BorrowUmbrellaID"] = id; NCMBUser.CurrentUser.SaveAsync(); NCMBQuery <NCMBObject> query = new NCMBQuery <NCMBObject>("Umbrella"); query.WhereEqualTo("objectId", id); query.FindAsync((List <NCMBObject> objList, NCMBException e) => { if (e != null) { //検索失敗時の処理 } else { // foreach (NCMBObject obj in objList) { obj["IsBorrow"] = true; obj["BorrowID"] = NCMBUser.CurrentUser.ObjectId; obj.SaveAsync(); Debug.Log("成功"); mode = Mode.OK; canvas[1].SetActive(false); canvas[2].SetActive(true); } } }); }
/// <summary> /// 存在するユーザー名から記録更新 /// </summary> /// <param name="userName">ユーザー名</param> /// <param name="score">スコア</param> public void FetchRanking(string userName, int score) { NCMBQuery <NCMBObject> query = new NCMBQuery <NCMBObject>("ScoreRanking"); query.WhereEqualTo("Name", userName); query.FindAsync((List <NCMBObject> objList, NCMBException e) => { if (e != null)//検索失敗時の処理 { Debug.LogError(userName + "という名前は存在しません。" + e.ErrorMessage); } else { if (objList.Count == 1)//ユーザー名が一つだけの時 { int cloudScore = System.Convert.ToInt32(objList[0]["Score"]); if (cloudScore < score) { objList[0]["Score"] = score; objList[0].SaveAsync(); } } else if (objList.Count <= 0)//ユーザー名が存在しない時 { objList[0]["Name"] = userName; objList[0]["Score"] = score; objList[0].SaveAsync(); } } }); }
public void UpdatePvPWeekly(string userId, string userName, int todayNCMB, int kuniLv, int soudaisyo, int jinkeiHeiryoku) { NCMBQuery <NCMBObject> query = new NCMBQuery <NCMBObject>("pvpTmp"); query.WhereEqualTo("userId", userId); query.WhereGreaterThanOrEqualTo("endDate", todayNCMB); query.OrderByDescending("endDate"); query.FindAsync((List <NCMBObject> objList, NCMBException e) => { if (e == null) { if (objList.Count != 0) { objList[0]["userName"] = userName; objList[0]["kuniLv"] = kuniLv; if (soudaisyo != 0) { objList[0]["soudaisyo"] = soudaisyo; } objList[0]["jinkeiHeiryoku"] = jinkeiHeiryoku; objList[0].SaveAsync(); } } }); }
public void GetEnemyBusyoStatus(string userId, int PvPId) { NCMBQuery <NCMBObject> query = new NCMBQuery <NCMBObject>("pvpJinkei"); query.WhereNotEqualTo("userId", userId); query.FindAsync((List <NCMBObject> objList, NCMBException e) => { if (e != null) { Debug.Log("Ther is no user : exception"); } else { for (int i = 0; i < 25; i++) { int id = i + 1; string mapId = "map" + id.ToString(); int busyoId = System.Convert.ToInt32(objList[i][mapId]); if (PvPId == 1) { PvP1BusyoList.Add(busyoId); } else if (PvPId == 2) { PvP2BusyoList.Add(busyoId); } else if (PvPId == 3) { PvP3BusyoList.Add(busyoId); } } } }); }
/* Weekly Pt Start*/ public void GetTop10Pt(int todayNCMB) { NCMBQuery <NCMBObject> query = new NCMBQuery <NCMBObject>("pvpTmp"); query.WhereGreaterThanOrEqualTo("endDate", todayNCMB); query.OrderByDescending("totalPt"); query.AddDescendingOrder("totalWinNo"); query.Limit = 10; query.FindAsync((List <NCMBObject> objList, NCMBException e) => { if (e != null) { } else { foreach (NCMBObject obj in objList) { //PvP Detail string userId = System.Convert.ToString(obj["userId"]); Top10PtWeeklyWinList.Add(System.Convert.ToInt32(obj["totalWinNo"])); int atkNo = System.Convert.ToInt32(obj["atkNo"]); int dfcNo = System.Convert.ToInt32(obj["dfcNo"]); Top10PtWeeklyBattleList.Add(atkNo + dfcNo); Top10PtWeeklyQtyList.Add(System.Convert.ToInt32(obj["totalPt"])); Top10PtWeeklyUserIdList.Add(userId); Top10PtWeeklyNameList.Add(System.Convert.ToString(obj["userName"])); Top10PtWeeklyRankList.Add(System.Convert.ToInt32(obj["kuniLv"])); Top10PtWeeklyBusyoList.Add(System.Convert.ToInt32(obj["soudaisyo"])); Top10PtWeeklyHeiList.Add(System.Convert.ToInt32(obj["jinkeiHeiryoku"])); } } }); }
public void getLevelRanking() { NCMBQuery <NCMBObject> query = new NCMBQuery <NCMBObject>("LevelRanking"); query.OrderByDescending("level"); // スコアを降順に並び替える query.Limit = 100; // 上位10件のみ取得 query.FindAsync((List <NCMBObject> objList, NCMBException e) => { if (e == null) { //検索成功したら List <string> nameList = new List <string>(); // 名前のリスト List <int> sankakuList = new List <int>(); // 使用三角のリスト List <int> scoreList = new List <int>(); // スコアのリスト for (int i = 0; i < objList.Count; i++) { string s = System.Convert.ToString(objList[i]["playername"]); // 名前を取得 int t = System.Convert.ToInt32(objList[i]["sankaku"]); // スコアを取得 int n = System.Convert.ToInt32(objList[i]["level"]); // スコアを取得 nameList.Add(s); // リストに突っ込む scoreList.Add(t); scoreList.Add(n); addrank(i + 1, s, t, n); } } }); ////ここから表示 }
private void Start() { query = new NCMBQuery <NCMBObject>("Ranking"); query.OrderByDescending("score"); query.Limit = RankingPacket.RankingCount; query.FindAsync((List <NCMBObject> objList, NCMBException e) => { Packet = new RankingPacket(); for (int i = 0; i < RankingPacket.RankingCount; i++) { Packet.Ranks[i] = 0; Packet.Scores[i] = 0; } if (e != null) { ResultManager.Instance.SetRanking(Packet); } else { int rank = 0; foreach (var obj in objList) { rank++; int score = System.Convert.ToInt32(obj["score"]); Packet.Ranks[rank - 1] = rank; Packet.Scores[rank - 1] = score; } //ResultManager.Instance.SetRanking(Packet); } }); }
void LoadFile() { NCMBQuery <NCMBObject> query = new NCMBQuery <NCMBObject>("SummerTask"); query.OrderByDescending("Score"); query.Limit = 10; // 上位10件のみ取得 query.FindAsync((List <NCMBObject> objList, NCMBException e) => { if (e == null) { //検索成功したら nameList = new List <string>(); // 名前のリスト scoreList = new List <int>(); // スコアのリスト GameObject tmpObj; Text tmpText; for (int i = 0; i < objList.Count; i++) { string s = System.Convert.ToString(objList[i]["Name"]); // 名前を取得 int n = System.Convert.ToInt32(objList[i]["Score"]); // スコアを取得 nameList.Add(s); // リストに突っ込む scoreList.Add(n); tmpObj = GameObject.Find("No" + (i + 1)); // ランキング表示用のオブジェクト取得 // テキストに代入 tmpText = tmpObj.GetComponent <Text>(); tmpText.text = "No." + (i + 1) + " " + s + " " + n; } } }); }
/// <summary> /// ランキングボード用取得関数 /// </summary> public void FetchTopRankers() { // データストアの「ScoreRanking」クラスから検索 NCMBQuery <NCMBObject> query = new NCMBQuery <NCMBObject>("ScoreRanking"); query.OrderByDescending("Score"); query.Limit = 5; query.FindAsync((List <NCMBObject> objList, NCMBException e) => { if (e != null) { //検索失敗時の処理 Debug.LogError("ランキング取得失敗しました。" + e.ErrorMessage); } else { //検索成功時の処理 List <ScoreRanking> list = new List <ScoreRanking>(); // 取得したレコードをScoreRankingクラスとして保存 foreach (NCMBObject obj in objList) { string n = System.Convert.ToString(obj["Name"]); int s = System.Convert.ToInt32(obj["Score"]); list.Add(new ScoreRanking(n, s)); } rankingList = list; } }); }
// サーバーからハイスコアを取得 ----------------- public void fetch() { // データストアの「HighScore」クラスから、Nameをキーにして検索 NCMBQuery<NCMBObject> query = new NCMBQuery<NCMBObject> ("HighScore"); query.WhereEqualTo ("Name", name); query.FindAsync ((List<NCMBObject> objList ,NCMBException e) => { //検索成功したら if (e == null) { // ハイスコアが未登録だったら if( objList.Count == 0 ) { NCMBObject obj = new NCMBObject("HighScore"); obj["Name"] = name; obj["Score"] = 0; obj.SaveAsync(); score = 0; } // ハイスコアが登録済みだったら else { score = System.Convert.ToInt32( objList[0]["Score"] ); } } }); }
// ランキングデータ読み込み public void DBRankingLoad() { NCMBQuery <NCMBObject> query = new NCMBQuery <NCMBObject>(Define.DATASTORENAME); // Scoreの値で降順にソート query.OrderByDescending("Score"); // 取得数の設定 query.Limit = Define.DRAWLIST_MAX; query.FindAsync((List <NCMBObject> objList, NCMBException e) => { if (e != null) { // 検索失敗時の処理 IsRankingDataValid = false; } else { rankingDataList.Clear(); foreach (NCMBObject obj in objList) { rankingDataList.Add(new RankingData( name: obj["Name"] as string, time: obj["Time"] as string, score: Convert.ToInt32(obj["Score"]) )); } IsRankingDataValid = true; } }); }
// ランキングをサーバーから取得する public void GetRanking() { // いったん初期化 Init(); // 取得 NCMBQuery <NCMBObject> query = new NCMBQuery <NCMBObject>("Ranking"); query.OrderByDescending("Level"); query.Limit = 30; query.FindAsync((List <NCMBObject> objList, NCMBException e) => { if (e != null) { Message("エラーが発生しました。"); } else { // ランカーオブジェクトを生成し、値を設定 int r = 0; foreach (NCMBObject obj in objList) { r++; int l = System.Convert.ToInt32(obj["Level"]); string n = System.Convert.ToString(obj["Name"]); GameObject ranker = Instantiate(rankerPrefab, rankerBoard); ranker.GetComponent <Ranker>().Set(r, n, l); } } }); }
//NCMBからストア公開中の最新Verを取得。RemoteSettingsに移行したため現在は未使用 public void GetAppLatestVer(CallbackStr callback) { string latestVer = ""; #if UNITY_IOS var os = "iOS"; #elif UNITY_ANDROID var os = "Android"; #endif NCMBQuery <NCMBObject> query = new NCMBQuery <NCMBObject>(appLatestVerClassName); query.WhereEqualTo("os", os); // OS名で絞る query.FindAsync((List <NCMBObject> objList, NCMBException e) => { if (e == null) { //検索成功したら if (objList.Count > 0) { // 1個以上あれば latestVer = System.Convert.ToString(objList[0]["version"]); } else { latestVer = "Not Exist."; } } callback(latestVer); }); return; }
/// <summary> /// サーバーからTOP5までのスコアを取得 /// </summary> public void FetchRankerScores() { AsyncState = ASYNC_DOING; NCMBQuery <NCMBObject> query = new NCMBQuery <NCMBObject>(CLASS_NAME); query.OrderByDescending(KEY_SCORE); query.Limit = 5; query.FindAsync((List <NCMBObject> records, NCMBException e) => { if (e == null) { int count = records.Count; mRankerScoreArray = new int[count]; for (int i = 0; i < count; i++) { mRankerScoreArray[i] = System.Convert.ToInt32(records[i][KEY_SCORE]); } } else { Debug.LogError(e); // エラーが出た場合はデフォルトのスコアを設定してしまう mRankerScoreArray = new int[5]; mRankerScoreArray[0] = 3000; mRankerScoreArray[1] = 2000; mRankerScoreArray[2] = 1500; mRankerScoreArray[3] = 1000; mRankerScoreArray[4] = 500; HasAsyncError = true; } AsyncState = ASYNC_DONE; }); }
//新規ユーザー登録 public void SaveNewUser(string name, CallbackBool callback) { isNameExist = false; NCMBQuery <NCMBObject> query = new NCMBQuery <NCMBObject>(usersClassName); query.WhereEqualTo("name", name); // 古い名前でデータを絞る query.FindAsync((List <NCMBObject> objList, NCMBException e) => { if (e == null) { //検索成功したら if (objList.Count > 0) { // 1個以上あれば isNameExist = true; } else { NCMBObject obj = new NCMBObject(usersClassName); obj["name"] = name; // 新しい名前にする obj.SaveAsync((NCMBException e2) => { if (e2 == null) { GameMaster.gameMaster.Save(); } }); } } callback(isNameExist); }); return; }
public void LoadOneImage(int index, Image go) { NCMBQuery <NCMBFile> query = NCMBFile.GetQuery(); query.Skip = index; query.Limit = 1; query.OrderByDescending("createDate"); query.FindAsync((List <NCMBFile> objList, NCMBException error) => { if (error != null) { // 検索失敗 } else { // 検索成功 foreach (NCMBFile file in objList) { file.FetchAsync((byte[] fileData, NCMBException e) => { if (e != null) { // 取得失敗 } else { // 取得成功 SaveBytes(fileData, go); } }); } } }); }
// サーバーからハイスコアを取得 ----------------- // key :online easy nomal hard expertとかを入力 public static void getData() { // int score = 0; // データストアの「HighScore」クラスから、Nameをキーにして検索 NCMBQuery <NCMBObject> query = new NCMBQuery <NCMBObject>("HighScore"); query.WhereEqualTo("userName", getUserName()); query.FindAsync((List <NCMBObject> objList, NCMBException e) => { //検索成功したら if (e == null) { // ハイスコアが未登録だったら if (objList.Count == 0) { saveData(); } // ハイスコアが登録済みだったら else { PlayerInformation.highScore[0] = System.Convert.ToInt32(objList[0]["online"]); PlayerInformation.highScore[1] = System.Convert.ToInt32(objList[0]["easy"]); PlayerInformation.highScore[2] = System.Convert.ToInt32(objList[0]["normal"]); PlayerInformation.highScore[3] = System.Convert.ToInt32(objList[0]["hard"]); PlayerInformation.highScore[4] = System.Convert.ToInt32(objList[0]["expert"]); // score = System.Convert.ToInt32(objList[0][key]); // Debug.Log(key+"今までのハイスコア:"+score); } } // HighScore = score; }); }
private void Update() { NCMBObject volumeClass = new NCMBObject("VolumeClass"); NCMBQuery <NCMBObject> query = new NCMBQuery <NCMBObject>("VolumeClass"); query.FindAsync((List <NCMBObject> objList, NCMBException e) => { if (e == null) { double s = System.Convert.ToDouble((objList[0])["s"]); double a = System.Convert.ToDouble((objList[0])["a"]); sText.text = (objList[0])["s"].ToString(); aText.text = (objList[0])["a"].ToString(); for (int i = 0; i < 3; i++) { float sScale = (float)s * 100; float aScale = (float)a * 100; S_Fire[i].gameObject.transform.localScale = new Vector3(sScale, sScale, sScale); A_Fire[i].gameObject.transform.localScale = new Vector3(aScale, aScale, aScale); } } else { print("Error:" + e); } }); }
public void FetchFriendDataFromNCMB(UnityAction <List <FriendData> > callback) { NCMBQuery <NCMBObject> query = new NCMBQuery <NCMBObject>("FriendData"); query.OrderByDescending("createDate"); query.Limit = 20; query.FindAsync((List <NCMBObject> childObjList, NCMBException error) => { if (error != null) { //エラー処理 } else { //成功時の処理 List <FriendData> friendDataList = new List <FriendData>(); foreach (NCMBObject obj in childObjList) { string name = (string)obj["Name"]; string message = (string)obj["Message"]; ArrayList doubleArrayPosition = (ArrayList)obj["Position"]; Vector3 position = doubleArrayPosition.ToVector3(); friendDataList.Add(new FriendData(name, message, position)); } callback(friendDataList); } }); }
// サーバーからトップ5を取得 --------------- public void fetchTopRankers() { // データストアの「HighScore」クラスから検索 NCMBQuery<NCMBObject> query = new NCMBQuery<NCMBObject> ("HighScore"); query.OrderByDescending ("Score"); query.Limit = 5; query.FindAsync ((List<NCMBObject> objList ,NCMBException e) => { if (e != null) { //検索失敗時の処理 } else { //検索成功時の処理 List<NCMB.HighScore> list = new List<NCMB.HighScore>(); // 取得したレコードをHighScoreクラスとして保存 foreach (NCMBObject obj in objList) { int s = System.Convert.ToInt32(obj["Score"]); string n = System.Convert.ToString(obj["Name"]); string u = System.Convert.ToString(obj["Uuid"]); list.Add( new HighScore( s, n, u) ); } topRankers = list; } }); }
// サーバーからrankの前後2件を取得 --------------- public void fetchNeighbors() { neighbors = new List<NCMB.HighScore>(); // スキップする数を決める(ただし自分が1位か2位のときは調整する) int numSkip = currentRank - 3; if(numSkip < 0) numSkip = 0; // データストアの「HighScore」クラスから検索 NCMBQuery<NCMBObject> query = new NCMBQuery<NCMBObject> ("HighScore"); query.OrderByDescending ("Score"); query.Skip = numSkip; query.Limit = 5; query.FindAsync ((List<NCMBObject> objList ,NCMBException e) => { if (e != null) { //検索失敗時の処理 } else { //検索成功時の処理 List<NCMB.HighScore> list = new List<NCMB.HighScore>(); // 取得したレコードをHighScoreクラスとして保存 foreach (NCMBObject obj in objList) { int s = System.Convert.ToInt32(obj["Score"]); string n = System.Convert.ToString(obj["Name"]); string u = System.Convert.ToString(obj["Uuid"]); list.Add( new HighScore( s, n, u ) ); } neighbors = list; } }); }
public void GunzeiDelete(string userId) { NCMBQuery <NCMBObject> query = new NCMBQuery <NCMBObject>("deleteGunzei"); query.WhereEqualTo("userId", userId); query.FindAsync((List <NCMBObject> objList, NCMBException e) => { if (e == null) { if (objList.Count != 0) //delete { string objectId = objList[0].ObjectId; NCMBObject deleteQuery = new NCMBObject("deleteGunzei"); deleteQuery.ObjectId = objectId; deleteQuery.DeleteAsync(); HPCounter deleteGunzeiScript = new HPCounter(); for (int i = 1; i < 66; i++) { PlayerPrefs.DeleteKey("keyHistory"); PlayerPrefs.Flush(); deleteGunzeiScript.deleteEnemyGunzeiData(i); } } } }); }
// サーバーにハイスコアを保持. public void save() { // データストアの「HighScore」クラスから、Nameをキーいして検索. NCMBQuery<NCMBObject> query = new NCMBQuery<NCMBObject>("HighScore"); query.WhereEqualTo ("Name", name); query.FindAsync ((List<NCMBObject> objList, NCMBException e) => { // 検索に成功したら. if (e == null) { objList[0]["Score"] = score; objList[0].SaveAsync(); } }); }
public void Login() { NCMBQuery<NCMBObject> query = new NCMBQuery<NCMBObject> ("TestClass"); query.WhereEqualTo ("message", "Hello, Tarou!"); query.FindAsync ((List<NCMBObject> objectList,NCMBException e) => { if (objectList.Count != 0) { NCMBObject obj = objectList [0]; Debug.Log ("message : " + obj ["message"]); } else { NCMBObject testClass = new NCMBObject ("TestClass"); testClass ["message"] = "Hello, NCMB!"; testClass.SaveAsync (); } }); }
/// <summary> /// ランキングの取得. /// </summary> void HighScoreGetter() { NCMBQuery<NCMBObject> query = new NCMBQuery<NCMBObject> ("HighScore"); // Scoreフィールドの降順でデータを取得. query.OrderByDescending("Score"); // 検索件数を設定. query.Limit = listLimit; // データストアで検索を行う. query.FindAsync (( List<NCMBObject> objList, NCMBException e) => { if ( e != null) { // 検索失敗時の処理. } else { // 検索成功時の処理. } }); }
void OnGUI() { //getMessage from server NCMBQuery<NCMBObject> query = new NCMBQuery<NCMBObject> ("Message"); query.WhereEqualTo ("placeid", "1"); query.FindAsync ((List<NCMBObject> objectList,NCMBException e) => { if (objectList.Count != 0) { NCMBObject obj = objectList [0]; string message = (string) obj["msg"]; GUI.Label(new Rect(0,0,Screen.width,Screen.height), message); //Save log NCMBObject testClass = new NCMBObject ("ShowLog"); testClass ["message"] = "Unitychan is showed"; testClass.SaveAsync (); } else { } }); }
// Use this for initialization void Start() { NCMBQuery<NCMBObject> query = new NCMBQuery<NCMBObject> ("Score"); query.OrderByDescending ("score"); query.Limit = 1; query.FindAsync ((List<NCMBObject> objList,NCMBException e)=>{ if(e !=null){ //検索失敗時の処理 }else{ //検索成功時の処理 //取得したレコードをscoreクラスとして保存 if(objList.Count > 0){ Debug.Log("GhostData"); readyGhost = true; foreach(NCMBObject obj in objList){ posObj = obj; } } } }); }
// Use this for initialization void Start() { NCMBQuery<NCMBObject> query = new NCMBQuery<NCMBObject>("TestClass"); query.WhereEqualTo("message", "Hello, Tarou!"); query.FindAsync((List<NCMBObject> objectList, NCMBException e) => { if (objectList.Count != 0) { NCMBObject obj = objectList[0]; Debug.Log("message : " + obj["message"]); } else { NCMBObject testClass = new NCMBObject("TestClass"); testClass["message"] = "Hello, NCMB!"; testClass.SaveAsync(); scoretext = Score.GetComponent<GUIText>(); print("scoretext: " + scoretext); //scoretext.text = testClass["message"].ToString(); } }); }
// サーバーからコメントをランダムに取得 ----------------- public void fetchRandomly(int currentWave) { // データストアの「Comment」クラスから、Waveをキーにして検索 NCMBQuery<NCMBObject> query = new NCMBQuery<NCMBObject> ("Comment"); query.WhereEqualTo ("Wave", currentWave); query.FindAsync ((List<NCMBObject> commentList, NCMBException e) => { if (e != null) { //取得失敗時の処理 } else { //取得成功時の処理 if ( commentList.Count != 0 ) { //取得したコメントの数を上限として、乱数を生成 System.Random random = new System.Random(); int i = random.Next(commentList.Count); //ランダムに選んだコメントを保持する wave = System.Convert.ToInt32 ( commentList[i]["Wave"] ); text = System.Convert.ToString( commentList[i]["Text"] ); player = System.Convert.ToString( commentList[i]["Player"] ); } } }); }
// サーバーからトップ5を取得 --------------- public void fetchTopRankers() { // データストアの「Time」クラスから検索 NCMBQuery<NCMBObject> query = new NCMBQuery<NCMBObject> ("Time"); query.OrderByAscending ("time"); query.Limit = 5; query.FindAsync ((List<NCMBObject> objList ,NCMBException e) => { if (e != null) { //検索失敗時の処理 } else { //検索成功時の処理 List<NCMB.Rankers> list = new List<NCMB.Rankers>(); // 取得したレコードをtimeクラスとして保存 foreach (NCMBObject obj in objList) { string t = System.Convert.ToString(obj["time"]); list.Add( new Rankers(t) ); } topRankers = list; } }); }
// ハイスコアを更新して保存 ------------------------- public void updateScore() { #if False NCMBObject obj = new NCMBObject("HighScore"); obj["Uuid"] = uuid; obj["Name"] = name; obj["Score"] = score; obj.SaveAsync(); #else // データストアの「HighScore」クラスから、Uuidをキーにして検索 NCMBQuery<NCMBObject> query = new NCMBQuery<NCMBObject> ("HighScore"); query.WhereEqualTo ("Uuid", uuid); query.FindAsync ((List<NCMBObject> objList ,NCMBException e) => { //検索成功したら if (e == null) { objList[0]["Score"] = score; objList[0]["Uuid"] = uuid; objList[0]["Name"] = name; objList[0].SaveAsync(); } }); #endif }
// サーバーにハイスコアを保存する public void testSave() { Debug.Log ("testHighScore内スコア " + score + name); // データストアの「HighScore」クラスから,Nameをキーにして検索する NCMBQuery<NCMBObject> query = new NCMBQuery<NCMBObject> ("HighScore"); query.WhereEqualTo ("Name", name); query.FindAsync ((List<NCMBObject> objList ,NCMBException e) => { //検索が成功した場合 if (e == null) { objList [0] ["Score"] = score; // Score.scoreで誤魔化す? objList [0].SaveAsync (); Debug.Log ("testHighScore内スコア保存メソッド発動 " + score); }else{ Debug.Log("NEETなう"); } }); }