Example #1
0
 public Client(Gs2.Unity.Util.Profile profile)
 {
     _profile = profile;
     _client  = new Gs2InventoryWebSocketClient(profile.Gs2Session);
     if (profile.checkRevokeCertificate)
     {
         _restClient = new Gs2InventoryRestClient(profile.Gs2RestSession);
     }
     else
     {
         _restClient = new Gs2InventoryRestClient(profile.Gs2RestSession, new DisabledCertificateHandler());
     }
 }
Example #2
0
        public static IEnumerator Acquire(
            GameSession session,
            string identifierAcquireItemClientId,
            string identifierAcquireItemClientSecret,
            string inventoryNamespaceName,
            string inventoryModelName,
            string itemModelName,
            int value,
            AcquireEvent onAcquire,
            ErrorEvent onError
            )
        {
            // このコードは実際にアプリケーションで使用するべきではありません。
            // アプリ内から課金通貨の残高を加算できるようにすることは、事業に多大な悪い影響を及ぼす可能性があります。
            var restSession = new Gs2RestSession(
                new BasicGs2Credential(
                    identifierAcquireItemClientId,
                    identifierAcquireItemClientSecret
                    )
                );
            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 Gs2InventoryRestClient(
                restSession
                );

            yield return(restClient.AcquireItemSetByUserId(
                             new AcquireItemSetByUserIdRequest()
                             .WithNamespaceName(inventoryNamespaceName)
                             .WithUserId(session.AccessToken.userId)
                             .WithInventoryName(inventoryModelName)
                             .WithItemName(itemModelName)
                             .WithAcquireCount(value),
                             r =>
            {
                if (r.Error != null)
                {
                    onError.Invoke(r.Error);
                    error = true;
                }
                else
                {
                    onAcquire.Invoke(
                        new EzInventory(r.Result.inventory),
                        r.Result.items.Select(item => new EzItemSet(item)).ToList(),
                        value
                        );
                }
            }
                             ));

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