Exemplo n.º 1
0
        protected override void OnBackButtonPressed()
        {
            CoroutineRunner.Instance.StartCoroutine(LeaveGameCoroutine());

            IEnumerator LeaveGameCoroutine()
            {
                if (this.isLeaveGameCoroutineRunning)
                {
                    yield break;
                }

                this.isLeaveGameCoroutineRunning = true;

                this.Dialog.Hide();

                yield return(WaitForUtil.Seconds(0.25f));

                var leaveGamePrompt = PlayFabMessages.ShowExitAppPrompt();

                yield return(leaveGamePrompt);

                if (leaveGamePrompt.Value == YesNoResult.Yes)
                {
                    Platform.QuitApplication();
                    yield break;
                }

                this.Dialog.Show();

                this.isLeaveGameCoroutineRunning = false;
            }
        }
Exemplo n.º 2
0
        private IEnumerator <bool> ChangeDisplayNameCoroutine(string newDisplayName)
        {
            var updateDisplayName = PF.Do(new UpdateUserTitleDisplayNameRequest
            {
                DisplayName = newDisplayName,
            });

            while (updateDisplayName.IsDone == false)
            {
                yield return(default(bool));
            }

            // Early out if we got an error
            if (updateDisplayName.HasError)
            {
                PlayFabMessages.HandleError(updateDisplayName.Exception);
                yield return(false);

                yield break;
            }

            // TODO [bgish]: Fire off DisplayName changed event?
            // Updating the display name
            this.DisplayName = newDisplayName;

            yield return(true);
        }
Exemplo n.º 3
0
        private void ForgotPassword()
        {
            CoroutineRunner.Instance.StartCoroutine(ForgotPasswordCoroutine());

            IEnumerator ForgotPasswordCoroutine()
            {
                if (this.isForgotPasswordCoroutineRunning)
                {
                    yield break;
                }

                this.isForgotPasswordCoroutineRunning = true;

                this.Dialog.Hide();
                yield return(WaitForUtil.Seconds(.25f));

                var forgot = PlayFabMessages.ShowForgotPasswordPrompt(this.emailInputField.text);

                if (forgot.Value == YesNoResult.Yes)
                {
                    var accountRecovery = PF.Login.SendAccountRecoveryEmail(this.emailInputField.text, this.forgotEmailTemplateId);

                    yield return(accountRecovery);

                    if (accountRecovery.HasError)
                    {
                        yield return(PlayFabMessages.HandleError(accountRecovery.Exception));
                    }
                }

                this.Dialog.Show();

                this.isForgotPasswordCoroutineRunning = false;
            }
        }
Exemplo n.º 4
0
        private IEnumerator <bool> ChangeDisplayNameWithPopupCoroutine()
        {
            var stringInputBox = PlayFabMessages.ShowChangeDisplayNameInputBox(PF.User.DisplayName);

            while (stringInputBox.IsDone == false)
            {
                yield return(default(bool));
            }

            if (stringInputBox.Value == StringInputResult.Cancel)
            {
                yield return(false);

                yield break;
            }

            var updateDisplayName = PF.Do(new UpdateUserTitleDisplayNameRequest
            {
                DisplayName = StringInputBox.Instance.Text,
            });

            while (updateDisplayName.IsDone == false)
            {
                yield return(default(bool));
            }

            // Early out if we got an error
            if (updateDisplayName.HasError)
            {
                PlayFabMessages.HandleError(updateDisplayName.Exception);
                yield return(false);

                yield break;
            }

            // TODO [bgish]: Fire off DisplayName changed event?
            // Updating the display name
            this.DisplayName = StringInputBox.Instance.Text;

            yield return(true);
        }
Exemplo n.º 5
0
        private void SignIn()
        {
            CoroutineRunner.Instance.StartCoroutine(SignInCoroutine());

            IEnumerator SignInCoroutine()
            {
                if (this.isSignUpCoroutineRunning)
                {
                    yield break;
                }

                this.isSignUpCoroutineRunning = true;

                var login = PF.Login.LoginWithEmail(true, this.emailInputField.text, this.passwordInputField.text);

                yield return(login);

                if (login.HasError)
                {
                    yield return(PlayFabMessages.HandleError(login.Exception));
                }
                else
                {
                    PF.Login.HasEverLoggedIn       = true;
                    PF.Login.LastLoginEmail        = this.emailInputField.text;
                    PF.Login.AutoLoginWithDeviceId = this.autoLoginToggle.isOn;

                    if (PF.Login.AutoLoginWithDeviceId)
                    {
                        PF.Login.LinkDeviceId(PF.Login.DeviceId);
                    }

                    this.Dialog.Hide();
                }

                this.isSignUpCoroutineRunning = false;
            }
        }
Exemplo n.º 6
0
        public UnityTask <PurchaseResult> ShowStoreItem(bool automaticallyPerformPurchase, string storeId, StoreItem storeItem, Sprite icon, string title, string description, Action insufficientFundsStore = null)
        {
            this.automaticallyPerformPurchase = automaticallyPerformPurchase;

            return(UnityTask <PurchaseResult> .Run(Coroutine()));

            IEnumerator <PurchaseResult> Coroutine()
            {
                // resetting the result, and caching the items
                this.result    = PurchaseResult.Cancel;
                this.storeId   = storeId;
                this.storeItem = storeItem;

                // Figuring out which currecy this item costs
                string virtualCurrencyId = null;

                foreach (var virtualCurrencyPrice in storeItem.VirtualCurrencyPrices)
                {
                    if (virtualCurrencyPrice.Value > 0)
                    {
                        virtualCurrencyId = virtualCurrencyPrice.Key;
                    }
                }

                if (virtualCurrencyId == null)
                {
                    Debug.LogErrorFormat("StoreItem {0} has unknown currency.", storeItem.ItemId);
                    yield return(PurchaseResult.Cancel);

                    yield break;
                }

                bool isIapItem = virtualCurrencyId == "RM";

                // Turning on the correct button
                this.iapBuyButton.gameObject.SafeSetActive(isIapItem);
                this.virtualCurrencyBuyButton.gameObject.SafeSetActive(!isIapItem);

                if (isIapItem)
                {
                    string purchasePrice = string.Empty;

                    #if USING_UNITY_PURCHASING && !UNITY_XBOXONE
                    purchasePrice = IAP.UnityPurchasingManager.Instance.GetLocalizedPrice(storeItem.ItemId);
                    #else
                    purchasePrice = string.Format("${0}.{1:D2}", currencyPrice / 100, currencyPrice % 100);
                    #endif

                    this.iapBuyButtonText.text = purchasePrice;
                }
                else
                {
                    int  virtualCurrencyPrice = storeItem.GetVirtualCurrenyPrice(virtualCurrencyId);
                    bool hasSufficientFunds   = PF.VC[virtualCurrencyId] >= virtualCurrencyPrice;

                    if (hasSufficientFunds == false && insufficientFundsStore != null)
                    {
                        var insufficientFundsMessage = PlayFabMessages.ShowInsufficientCurrency();

                        while (insufficientFundsMessage.IsDone == false)
                        {
                            yield return(default(PurchaseResult));
                        }

                        if (insufficientFundsMessage.Value == YesNoResult.Yes)
                        {
                            insufficientFundsStore.Invoke();
                        }
                        else
                        {
                            yield return(PurchaseResult.Cancel);

                            yield break;
                        }
                    }

                    this.virtualCurrencyBuyButton.interactable = hasSufficientFunds;
                    this.virtualCurrencyBuyButtonIcon.sprite   = this.GetSprite(virtualCurrencyId);
                    this.virtualCurrencyBuyButtonText.text     = virtualCurrencyPrice.ToString();
                }

                // Setting the item image/texts
                this.storeItemIcon.sprite      = icon;
                this.storeItemTitle.text       = title;
                this.storeItemDescription.text = description;

                this.Dialog.Show();

                // waiting for it to start showing
                while (this.Dialog.IsShowing == false)
                {
                    yield return(default(PurchaseResult));
                }

                // waiting for it to return to the hidden state
                while (this.Dialog.IsHidden == false)
                {
                    yield return(default(PurchaseResult));
                }

                yield return(this.result);
            }
        }
Exemplo n.º 7
0
        private IEnumerator <bool> ProcessPurchaseCoroutine(PurchaseEventArgs e, string storeId)
        {
            var catalogItem = PF.Catalog.GetCatalogItem(e.purchasedProduct.definition.id);

            Debug.AssertFormat(catalogItem != null, "Couln't find CatalogItem {0}", e.purchasedProduct.definition.id);

            Debug.AssertFormat(e.purchasedProduct.hasReceipt, "Purchased item {0} doesn't have a receipt", e.purchasedProduct.definition.id);
            var receipt = (Dictionary <string, object>)Lost.AppConfig.MiniJSON.Json.Deserialize(e.purchasedProduct.receipt);

            Debug.AssertFormat(receipt != null, "Unable to parse receipt {0}", e.purchasedProduct.receipt);

            var store         = (string)receipt["Store"];
            var transactionId = (string)receipt["TransactionID"];
            var payload       = (string)receipt["Payload"];

            Debug.AssertFormat(string.IsNullOrEmpty(store) == false, "Unable to parse store from {0}", e.purchasedProduct.receipt);
            Debug.AssertFormat(string.IsNullOrEmpty(transactionId) == false, "Unable to parse transactionID from {0}", e.purchasedProduct.receipt);
            Debug.AssertFormat(string.IsNullOrEmpty(payload) == false, "Unable to parse payload from {0}", e.purchasedProduct.receipt);

            var  currencyCode   = e.purchasedProduct.metadata.isoCurrencyCode;
            var  purchasePrice  = this.GetPurchasePrice(e);
            bool wasSuccessfull = false;

            if (Platform.CurrentDevicePlatform == DevicePlatform.iOS)
            {
                var validate = PF.Do(new ValidateIOSReceiptRequest()
                {
                    CurrencyCode  = currencyCode,
                    PurchasePrice = purchasePrice,
                    ReceiptData   = payload,
                });

                while (validate.IsDone == false)
                {
                    yield return(default(bool));
                }

                if (validate.HasError)
                {
                    Debug.LogErrorFormat("Unable to validate iOS IAP Purchase: {0}", validate?.Exception?.ToString());
                    this.LogErrorReceiptFailedInfo(catalogItem, e);
                    Debug.LogErrorFormat("ReceiptData = " + payload);

                    PlayFabMessages.HandleError(validate.Exception);
                }
                else
                {
                    wasSuccessfull = true;
                }
            }
            else if (Platform.CurrentDevicePlatform == DevicePlatform.Android)
            {
                var details = (Dictionary <string, object>)Lost.AppConfig.MiniJSON.Json.Deserialize(payload);
                Debug.AssertFormat(details != null, "Unable to parse Receipt Payload {0}", payload);

                Debug.AssertFormat(details.ContainsKey("json"), "Receipt Payload doesn't have \"json\" key: {0}", payload);
                Debug.AssertFormat(details.ContainsKey("signature"), "Receipt Payload doesn't have \"signature\" key: {0}", payload);

                var receiptJson = (string)details["json"];
                var signature   = (string)details["signature"];

                var validate = PF.Do(new ValidateGooglePlayPurchaseRequest()
                {
                    CurrencyCode  = currencyCode,
                    PurchasePrice = (uint)purchasePrice,
                    ReceiptJson   = receiptJson,
                    Signature     = signature,
                });

                while (validate.IsDone == false)
                {
                    yield return(default(bool));
                }

                if (validate.HasError)
                {
                    Debug.LogErrorFormat("Unable to validate Google Play IAP Purchase: {0}", validate?.Exception?.ToString());
                    this.LogErrorReceiptFailedInfo(catalogItem, e);
                    Debug.LogErrorFormat("Receipt Json = " + receiptJson);
                    Debug.LogErrorFormat("Signature = " + signature);

                    PlayFabMessages.HandleError(validate.Exception);
                }
                else
                {
                    wasSuccessfull = true;
                }
            }
            else
            {
                Debug.LogErrorFormat("Tried to make IAP Purchase on Unknown Platform {0}", Application.platform.ToString());
            }

            if (wasSuccessfull == false)
            {
                yield break;
            }

            float  price    = catalogItem.GetVirtualCurrenyPrice("RM") / 100.0f;
            string itemId   = e.purchasedProduct.definition.id;
            string itemType = catalogItem.ItemClass;
            string level    = SceneManager.GetActiveScene().name;

            Analytics.AnalyticsEvent.IAPTransaction(storeId, price, itemId, itemType, level, transactionId, new Dictionary <string, object>
            {
                { "localized_price", e.purchasedProduct.metadata.localizedPrice },
                { "iso_currency_code", e.purchasedProduct.metadata.isoCurrencyCode },
                { "store", store },
            });

            PF.Inventory.InvalidateUserInventory();

            yield return(true);
        }
Exemplo n.º 8
0
        private IEnumerator <bool> PurchaseStoreItemInternal(string storeId, StoreItem storeItem, Action showStore)
        {
            bool isIapItem = storeItem.GetVirtualCurrenyPrice("RM") > 0;

            if (isIapItem)
            {
                #if USING_UNITY_PURCHASING && !UNITY_XBOXONE
                // Making sure we're properly initialized
                if (this.IsInitialized == false)
                {
                    var initialize = this.Initialize();

                    while (initialize.IsDone == false)
                    {
                        yield return(default(bool));
                    }

                    // Early out if initialization failed
                    if (initialize.HasError || this.IsInitialized == false)
                    {
                        if (initialize.HasError)
                        {
                            PlayFabMessages.HandleError(initialize.Exception);
                        }

                        yield return(false);

                        yield break;
                    }
                }

                var iapPurchaseItem = Lost.IAP.UnityPurchasingManager.Instance.PurchaseProduct(storeItem.ItemId);

                while (iapPurchaseItem.IsDone == false)
                {
                    yield return(default(bool));
                }

                if (iapPurchaseItem.HasError)
                {
                    PlayFabMessages.HandleError(iapPurchaseItem.Exception);
                }
                else
                {
                    if (Debug.isDebugBuild || Application.isEditor)
                    {
                        var purchase = UnityTask <bool> .Run(this.DebugPurchaseStoreItem(iapPurchaseItem.Value));

                        while (purchase.IsDone == false)
                        {
                            yield return(default(bool));
                        }

                        yield return(purchase.Value);
                    }
                    else
                    {
                        var purchase = UnityTask <bool> .Run(this.ProcessPurchaseCoroutine(iapPurchaseItem.Value, storeId));

                        while (purchase.IsDone == false)
                        {
                            yield return(default(bool));
                        }

                        yield return(purchase.Value);
                    }
                }
                #else
                throw new NotImplementedException("Trying to buy IAP Store Item when USING_UNITY_PURCHASING is not defined!");
                #endif
            }
            else
            {
                string virtualCurrency = storeItem.GetVirtualCurrencyId();
                int    storeItemCost   = storeItem.GetCost(virtualCurrency);

                bool hasSufficientFunds = PF.VC[virtualCurrency] >= storeItemCost;

                if (hasSufficientFunds == false)
                {
                    var messageBoxDialog = PlayFabMessages.ShowInsufficientCurrency();

                    while (messageBoxDialog.IsDone == false)
                    {
                        yield return(default(bool));
                    }

                    if (messageBoxDialog.Value == YesNoResult.Yes)
                    {
                        showStore?.Invoke();
                    }

                    yield break;
                }

                var coroutine = this.Do(new PurchaseItemRequest
                {
                    ItemId          = storeItem.ItemId,
                    Price           = storeItemCost,
                    VirtualCurrency = virtualCurrency,
                    StoreId         = storeId,
                });

                while (coroutine.keepWaiting)
                {
                    yield return(default(bool));
                }

                bool isSuccessful = coroutine.Value != null;

                if (isSuccessful)
                {
                    PF.Inventory.InvalidateUserInventory();
                }

                yield return(isSuccessful);
            }
        }