예제 #1
0
        private IEnumerator saveRank(RankingType type, Ranker ranker)
        {
            var className = getClassName(type);
            var ncmbObj   = new NCMBObject(className);

            ncmbObj[@"name"]  = ranker.Name;
            ncmbObj[@"score"] = ranker.Score;

            var key = PlayerPrefsKey.ObjectId[type];

            if (PlayerPrefs.HasKey(key))
            {
                ncmbObj.ObjectId = PlayerPrefs.GetString(key);
            }

            var watcher = new ASyncValue <bool, NCMBException>();

            while (true)
            {
                ncmbObj.SaveAsync(e => {
                    if (e != null)
                    {
                        Debug.LogError(e);
                        watcher.Exception = e;
                        return;
                    }
                    watcher.Value = true;
                    PlayerPrefs.SetString(key, ncmbObj.ObjectId);
                });
                yield return(new WaitUntil(watcher.TakeOrFailure));

                if (!watcher.Failure)
                {
                    break;
                }
                yield return(new WaitForSeconds(3.0f));
            }

            Fetch(type);
        }
예제 #2
0
        public bool Save(RankingType type, Ranker ranker)
        {
            if (string.IsNullOrWhiteSpace(ranker.Name))
            {
                throw new ArgumentException(@"空の名前でランキングに登録する事はできません。");
            }

            if (saveCoroutine != null)
            {
                StopCoroutine(saveCoroutine);
            }

            try {
                saveCoroutine = StartCoroutine(saveRank(type, ranker));
            } catch (Exception e) {
                Debug.LogError(e.Message);
                return(false);
            } finally {
                saveCoroutine = null;
            }

            return(true);
        }