unity初心者です。
ニフティmobile backendを利用して全国ランキングを実装したいと考えています。
C#
1//HighScore.cs 2using System.Collections; 3using System.Collections.Generic; 4using NCMB; 5 6 7namespace NCMB 8{ 9 public class HighScore 10 { 11 public int score { get; set; } 12 public string name { get; private set; } 13 14 // コンストラクタ ----------------------------------- 15 public HighScore(int _score, string _name) 16 { 17 score = _score; 18 name = _name; 19 } 20 21 // ランキングで表示するために文字列を整形 ----------- 22 public string print() 23 { 24 return name + ' ' + score; 25 } 26 27 // サーバーにハイスコアを保存 ------------------------- 28 public void save() 29 { 30 // データストアの「HighScore」クラスから、Nameをキーにして検索 31 NCMBQuery<NCMBObject> query = new NCMBQuery<NCMBObject>("HighScore"); 32 query.WhereEqualTo("Name", name); 33 query.FindAsync((List<NCMBObject> objList, NCMBException e) => { 34 35 //検索成功したら 36 if (e == null) 37 { 38 objList[0]["Score"] = score; 39 objList[0].SaveAsync(); 40 } 41 }); 42 } 43 44 // サーバーからハイスコアを取得 ----------------- 45 public void fetch() 46 { 47 48 // データストアの「HighScore」クラスから、Nameをキーにして検索 49 NCMBQuery<NCMBObject> query = new NCMBQuery<NCMBObject>("HighScore"); 50 query.WhereEqualTo("Name", name); 51 query.FindAsync((List<NCMBObject> objList, NCMBException e) => { 52 53 //検索成功したら 54 if (e == null) 55 { 56 // ハイスコアが未登録だったら 57 if (objList.Count == 0) 58 { 59 NCMBObject obj = new NCMBObject("HighScore"); 60 obj["Name"] = name; 61 obj["Score"] = 0; 62 obj.SaveAsync(); 63 score = 0; 64 } 65 // ハイスコアが登録済みだったら 66 else 67 { 68 score = System.Convert.ToInt32(objList[0]["Score"]); 69 } 70 } 71 }); 72 } 73 74 } 75}
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。