Example #1
0
        public IEnumerator Refresh()
        {
            void RefreshStatuesAction(
                EzExperienceModel experienceModelTemp,
                List <EzStatus> statuses
                )
            {
                if (experienceModelTemp.Name != _experienceModel.Name)
                {
                    return;
                }

                _experienceModel = experienceModelTemp;
                _statuses        = statuses.ToDictionary(status => status.PropertyId);

                _onGetStatuses.RemoveListener(RefreshStatuesAction);
            }

            _onGetStatuses.AddListener(RefreshStatuesAction);

            yield return(ExperienceController.GetStatuses(
                             _client,
                             _session,
                             _experienceNamespaceName,
                             _experienceModel,
                             _onGetStatuses,
                             _onError
                             ));
        }
Example #2
0
        public IEnumerator Run(
            Client client,
            GameSession session,
            Func <IEnumerator, Coroutine> startCoroutine,
            string experienceNamespaceName,
            string experienceModelName,
            GetExperienceModelEvent onGetExperienceModel,
            GetStatusesEvent onGetStatuses,
            IncreaseExperienceEvent onIncreaseExperience,
            ErrorEvent onError
            )
        {
            if (_watching)
            {
                throw new InvalidOperationException("already started");
            }

            _watching = true;

            _client                  = client;
            _session                 = session;
            _startCoroutine          = startCoroutine;
            _experienceNamespaceName = experienceNamespaceName;
            _experienceModelName     = experienceModelName;
            _onGetExperienceModel    = onGetExperienceModel;
            _onGetStatuses           = onGetStatuses;
            _onIncreaseExperience    = onIncreaseExperience;
            _onError                 = onError;

            void GetExperienceModelAction(
                string experienceModelNameTemp,
                EzExperienceModel experienceModel
                )
            {
                if (_experienceModelName != experienceModelNameTemp)
                {
                    return;
                }

                _experienceModel = experienceModel;

                _onGetExperienceModel.RemoveListener(GetExperienceModelAction);
            }

            _onGetExperienceModel.AddListener(GetExperienceModelAction);

            yield return(ExperienceController.GetExperienceModel(
                             _client,
                             _experienceNamespaceName,
                             _experienceModelName,
                             _onGetExperienceModel,
                             _onError
                             ));

            _onIncreaseExperience.AddListener(OnIncreaseExperience);

            yield return(Refresh());
        }
Example #3
0
 public EzGetExperienceModelResult(
     GetExperienceModelResult result
     )
 {
     if (result.item != null)
     {
         Item = new EzExperienceModel(result.item);
     }
 }
Example #4
0
        public void OnIncreaseExperience(
            EzExperienceModel experienceModel,
            EzStatus status,
            int value
            )
        {
            if (_experienceModelName != experienceModel.Name)
            {
                return;
            }

            _startCoroutine(Refresh());
        }
Example #5
0
        public static IEnumerator GetStatuses(
            Client client,
            GameSession session,
            string experienceNamespaceName,
            EzExperienceModel experienceModel,
            GetStatusesEvent onGetStatuses,
            ErrorEvent onError
            )
        {
            var    statuses  = new List <EzStatus>();
            string pageToken = null;

            while (true)
            {
                AsyncResult <EzListStatusesResult> result = null;
                yield return(client.Experience.ListStatuses(
                                 r =>
                {
                    result = r;
                },
                                 session,
                                 experienceNamespaceName,
                                 experienceModel.Name,
                                 pageToken
                                 ));

                if (result.Error != null)
                {
                    onError.Invoke(
                        result.Error
                        );
                    yield break;
                }

                statuses.AddRange(result.Result.Items);

                if (result.Result.NextPageToken == null)
                {
                    break;
                }

                pageToken = result.Result.NextPageToken;
            }

            onGetStatuses.Invoke(experienceModel, statuses);
        }
Example #6
0
        public static IEnumerator IncreaseExperience(
            GameSession session,
            string identifierIncreaseExperienceClientId,
            string identifierIncreaseExperienceClientSecret,
            string experienceNamespaceName,
            EzExperienceModel experienceModel,
            string propertyId,
            int value,
            IncreaseExperienceEvent onIncreaseExperience,
            ErrorEvent onError
            )
        {
            // このコードは実際にアプリケーションで使用するべきではありません。
            // アプリ内から課金通貨の残高を加算できるようにすることは、事業に多大な悪い影響を及ぼす可能性があります。
            var restSession = new Gs2RestSession(
                new BasicGs2Credential(
                    identifierIncreaseExperienceClientId,
                    identifierIncreaseExperienceClientSecret
                    )
                );
            var error = false;

            yield return(restSession.Open(
                             r =>
            {
                if (r.Error != null)
                {
                    onError.Invoke(r.Error);
                    error = true;
                }
            }
                             ));

            if (error)
            {
                yield return(restSession.Close(() => { }));

                yield break;
            }

            var restClient = new Gs2ExperienceRestClient(
                restSession
                );

            yield return(restClient.AddExperienceByUserId(
                             new AddExperienceByUserIdRequest()
                             .WithNamespaceName(experienceNamespaceName)
                             .WithUserId(session.AccessToken.userId)
                             .WithExperienceName(experienceModel.Name)
                             .WithPropertyId(propertyId)
                             .WithExperienceValue(value),
                             r =>
            {
                if (r.Error != null)
                {
                    onError.Invoke(r.Error);
                    error = true;
                }
                else
                {
                    onIncreaseExperience.Invoke(
                        experienceModel,
                        new EzStatus(r.Result.item),
                        value
                        );
                }
            }
                             ));

            yield return(restSession.Close(() => { }));
        }