示例#1
0
 /// <summary>
 /// レコードの登録
 /// コールバックはメインスレッドで実行される
 /// </summary>
 /// <param name="entry">登録するレコード</param>
 /// <param name="onComplete">成功時処理</param>
 /// <param name="onError">失敗時処理</param>
 public void AddEntry(RankingEntry entry, Action onComplete, Action <AggregateException> onError)
 {
     service.AddEntryAsync(entry).ContinueWith(task =>
     {
         if (task.IsFaulted)
         {
             onError?.Invoke(task.Exception);
         }
         else
         {
             onComplete?.Invoke();
         }
     }, TaskScheduler.FromCurrentSynchronizationContext());
 }
        /// <summary>
        /// Functions addEntryを実行する
        /// require: 認証済み
        /// </summary>
        /// <param name="entry"></param>
        /// <returns></returns>
        public async Task <object> AddEntryAsync(RankingEntry entry)
        {
            object data = new Dictionary <object, object>
            {
                { "name", entry.Name },
                { "score", entry.Score },
            };

            return(await functions.GetHttpsCallable("addEntry").CallAsync(data)
                   .ContinueWith(task =>
            {
                return task.Result.Data;
            }));
        }
        /// <summary>
        /// Functions getTopEntriesを実行する
        /// require: 認証済み
        /// </summary>
        /// <param name="entry"></param>
        /// <returns></returns>
        public async Task <IEnumerable <RankingEntry> > GetTopEntriesAsync(int count)
        {
            object data = new Dictionary <object, object>
            {
                { "count", count },
            };

            return(await functions.GetHttpsCallable("getTopEntries").CallAsync(data)
                   .ContinueWith(task =>
            {
                var result = (Dictionary <object, object>)task.Result.Data;
                return ((List <object>)result["entries"])
                .Select(e => RankingEntry.CreateFromEntryObject(e));
            }));
        }
 /// <summary>
 /// UI要素を設定する
 /// </summary>
 /// <param name="number">順位</param>
 /// <param name="entry">レコード情報</param>
 private void SetRankingEntry(int number, RankingEntry entry)
 {
     numberText.text = number.ToString();
     nameText.text   = entry.Name;
     scoreText.text  = entry.Score.ToString();
 }
        /// <summary>
        /// レコードのGameObjectを生成する
        /// </summary>
        /// <param name="prefab">コピー元オブジェクト</param>
        /// <param name="number">順位</param>
        /// <param name="entry">レコード情報</param>
        /// <returns></returns>
        public static RankingEntryPanel CreateRankingEntryPanel(RankingEntryPanel prefab, int number, RankingEntry entry)
        {
            RankingEntryPanel panel = Instantiate(prefab);

            panel.SetRankingEntry(number, entry);

            return(panel);
        }