예제 #1
0
        private void UnityPurchasingInit()
        {
            LogUtils.Log("UnityPurchasingInit begin");
            var gp = _configurationBuilder.Configure <IGooglePlayConfiguration>();

            gp.SetPublicKey(Settings.instance.androidPublicKey);
            UnityPurchasing.Initialize(_compoundStoreListener, _configurationBuilder);
            LogUtils.Log("UnityPurchasingInit end");
        }
예제 #2
0
파일: Client.cs 프로젝트: zendorx/testapp
        private IEnumerator C_Post(string command, JsonObject args, Action <JsonObject> completed, Action <string> error)
        {
            if (command != "sdk.login")
            {
                if (Controller.instance.nowLogging)
                {
                    while (!Controller.instance.isLogged)
                    {
                        yield return(0);
                    }
                }
                else
                {
                    while (!Controller.instance.isLogged)
                    {
                        var wait = true;

                        Controller.instance.Login(loginData => { wait = false; }, errorMessage => { wait = false; });

                        while (wait)
                        {
                            yield return(0);
                        }
                    }
                }
            }

            LogUtils.Log("!!!SEND " + command + " " + GoWMiniJSON.Serialize(args));
            var argsBytes = Encoding.UTF8.GetBytes(GoWMiniJSON.Serialize(args));
            var headers   = new Dictionary <string, string>
            {
                { "Content-Type", "application/json" },
                { "Content-Length", argsBytes.Length.ToString() }
            };

            var www = new WWW(Settings.serverUrl + "/" + command, argsBytes, headers);

            yield return(www);

            if (!string.IsNullOrEmpty(www.error))
            {
                var fullError = string.Format("Server: {0} \r\nCommand: {1} \r\nArguments : {2} \r\nError: {3}\r\n", Settings.serverUrl, command, GoWMiniJSON.Serialize(args), www.error);
                Debug.LogError(fullError);
                if (error != null)
                {
                    error(www.error);
                }
            }
            else if (completed != null)
            {
                LogUtils.Log("RESPONSE:" + www.text);
                var obj = (JsonObject)GoWMiniJSON.Deserialize(www.text);
                completed(obj);
            }
        }
예제 #3
0
        private IEnumerator C_Login(System.Action <JsonObject> callback, System.Action <string> onError)
        {
            while (nowLogging)
            {
                yield return(0);
            }

            isLogged   = false;
            nowLogging = true;
            GetPlayerId((playerId) =>
            {
                LogUtils.Log("Get player ID:" + playerId);
                _client.Login(Settings.instance.gameKey,
                              playerId,
                              _device.timezone,
                              _device.platform,
                              Application.version,
                              (obj) =>
                {
                    LogUtils.Log("Logged in");
                    nowLogging        = false;
                    isLogged          = true;
                    _applicationQuit += () =>
                    {
                        _client.Logout(Settings.instance.gameKey, playerId, (long)Time.unscaledTime);
                    };

                    if (Settings.instance.autoSubscribeToNotifications)
                    {
                        _device.GetDeviceToken();
                    }

                    _device.RequestNotifications();

                    InitSegments(obj.GetSequence <string>("segments"));

                    InitSpecialOffers(obj.GetSequence <JsonObject>("specialOffers"));

                    if (callback != null)
                    {
                        callback(obj);
                    }
                },
                              error =>
                {
                    nowLogging = false;
                    if (onError != null)
                    {
                        onError(error);
                    }
                });
            });
        }
예제 #4
0
 public void Buy(SpecialOffers.Replacement replacement)
 {
     if (_store == null)
     {
         throw new UnityException("Not properly inited");
     }
     Check();
     LogUtils.Log("Buy special offer " + replacement.sku);
     if (!replacement.product.availableToPurchase)
     {
         LogUtils.Log("Product " + replacement.product.definition.id + " is not available to purchase");
         return;
     }
     _store.InitiatePurchase(replacement.product, null);
 }
예제 #5
0
 public void Buy(Product product)
 {
     if (_store == null)
     {
         throw new UnityException("Not properly inited");
     }
     Check();
     LogUtils.Log("Buy " + product.definition.id);
     if (!product.availableToPurchase)
     {
         LogUtils.Log("Product " + product.definition.id + " is not available to purchase");
         return;
     }
     _store.InitiatePurchase(product, null);
 }
예제 #6
0
 private void OnDeviceToken(string token)
 {
     if (string.IsNullOrEmpty(token))
     {
         return;
     }
     if (!isLogged)
     {
         return;
     }
     GetPlayerId(playerId =>
     {
         LogUtils.Log("DeviceToken:" + token);
         _client.Token(Settings.instance.gameKey, playerId, token);
     });
 }
예제 #7
0
        void IStoreListener.OnInitialized(IStoreController controller, IExtensionProvider extensions)
        {
            LogUtils.Log("IStoreListener.OnInitialized");
            _store    = controller;
            _storeExt = extensions;

            var appleExt = _storeExt.GetExtension <IAppleExtensions>();

            appleExt.RegisterPurchaseDeferredListener(OnDeferred);

            _specialOffers.Init(_store);

            isReady = true;
            if (Initialized != null)
            {
                Initialized();
            }
        }
예제 #8
0
 private void OnDeferred(Product item)
 {
     LogUtils.Log("Purchase deferred: " + item.definition.id);
 }