Esempio n. 1
0
 /**
  *  Sets the instance of the awake method.
  */
 void Awake()
 {
     _instance = this;
     if (canvas == null)
     {
         canvas = CanvasHelper.GetCanvas(false);
         if (canvas == null)
         {
             Debug.LogError("MobyShop: Error finding canvas for ShopViews");
         }
     }
 }
Esempio n. 2
0
 /**
  * This method is invoked when we initialize the billing on device.
  */
 static void BillingUnityEditor_BuyProductWithSimulatedBilling(ProductInfo product, System.Action <bool, string, Shop.BuyResponse> callback)
 {
     if (product == null)
     {
         Debug.LogError("Error product was null - cannot puchase");
     }
     if (instance == null)
     {
         Debug.LogError("Error singleton instance is null");
     }
     if (instance.editorBillingUI == null)
     {
         if (instance.billingSimulatorUIPrefab == null)
         {
             Debug.LogError("Error prefab is null editorBillingUIPrefab", instance.gameObject);
         }
         var goBillingSimulator = ((GameObject)GameObject.Instantiate(instance.billingSimulatorUIPrefab));
         if (goBillingSimulator == null)
         {
             Debug.LogError("Error instanciating prefab of simulated billing UI");
         }
         if (instance.canvas == null)
         {
             Debug.LogWarning("MobyShop: Warning: Canvas was null, we're autocreating one but please setup a UI canvas in the project");
             instance.canvas = CanvasHelper.GetCanvas();
         }
         if (instance.canvas == null)
         {
             Debug.LogError("MobyShop: Error no instance of the canvas set");
         }
         goBillingSimulator.transform.SetParent(instance.canvas.transform);
         var rt = goBillingSimulator.GetComponent <RectTransform> ();
         if (rt == null)
         {
             Debug.LogError("Error the RectTransform component was not found on the Billing UI object.");
         }
         rt.FitAnchorsToCorners();
         instance.editorBillingUI = goBillingSimulator.GetComponent <SimulatedBillingUI>();
         if (instance.editorBillingUI == null)
         {
             Debug.LogError("MobyShop: Error cannot show billing simulator UI becaurse no instance is set.");
         }
     }
     if (BillingSimulator.instance == null)
     {
         MobyShop.Shop.Instance.gameObject.AddComponent <BillingSimulator> ();
     }
     if (BillingSimulator.instance == null)
     {
         Debug.LogError("MobyShop: Error - instance of billing simulator is not present and could NOT create instance.");
     }
     BillingSimulator.instance.billingSimulatorUI = instance.editorBillingUI;
     BillingSimulator.BuyProduct(product.BillingId, (bool _ok, string _m) => {
         if (_ok)
         {
             CallUnlockProduct(BoughtOrRestored.Bought, product);
         }
         else
         {
         }
         callback(_ok, _m, _ok ? Shop.BuyResponse.Ok : Shop.BuyResponse.Failed);
     });
 }
Esempio n. 3
0
        /**
         * This method initializes the inapp purchase.
         */
        static void BillingUnityEditor_BuyProductInGameCurrency(ProductInfo product, System.Action <bool, string, Shop.BuyResponse> callback, ShopConfirm shopConfirmInterface, ShopNotEnoughCoins notEnoughCoinsInterface)
        {
            if (MobyShop.Shop.Verbose)
            {
                Debug.Log("MobyShop: Buying product with virtual currency (" + product.ingameCurrencyClass + "); price=" + product.PriceTag + "; currency class=" + product.ingameCurrencyClass);
            }

            if (product.billing != BillingType.IngameCurrency)
            {
                throw new System.Exception("MobyShop: Billing with virtual currency is only allowed for : " + product.ProductId);
            }

            // Currency Class
            if (string.IsNullOrEmpty(product.ingameCurrencyClass))
            {
                Debug.LogError("MobyShop: Error currecy class did not exist : '" + product.ingameCurrencyClass + "'");
                callback(false, "Invalid product setup - no currency class given", Shop.BuyResponse.Failed);
            }

            if (ShopConfig.GetProductByClassId(product.ingameCurrencyClass) == null)
            {
                Debug.Log("MobyShop: Warning: No Product's exists with currency class id : '" +
                          product.ingameCurrencyClass +
                          "'\nNOTE: This might be okay if you don't intent for the user to buy the currency in the game shop");
            }

            // Debug.Log( "MobyShop: Buy product with virtual currency (coins)" );
            int amount = Mathf.Abs(Shop.GetProductClassAmount(product.ingameCurrencyClass));

            if (amount < Mathf.Abs(product.price))
            {
                //Debug.Log ("Not enough coins");

                if (notEnoughCoinsInterface == null)
                {
                    var uigo = instance.NotEnoughCoins;
                    if (uigo == null)
                    {
                        if (Billing.instance.PrefabNotEnoughCoins == null)
                        {
                            Debug.LogError("MobyShop: Error 'Not Enough Coins' Dialog Prefab was not found");
                            callback(false, "", Shop.BuyResponse.Cancelled);
                            return;
                        }
                        var goNotEn = GameObject.Instantiate(Billing.instance.PrefabNotEnoughCoins);
                        uigo = goNotEn;
                    }
                    var canvas = CanvasHelper.GetCanvas();
                    uigo.transform.localPosition = Vector2.zero;
                    uigo.gameObject.SetActive(true);
                    uigo.transform.parent = canvas.transform;
                    var rt = uigo.GetComponent <RectTransform> ();
                    rt.FitAnchorsToCorners();
                    uigo.GetComponentCompatibleWith <global::MobyShop.ShopNotEnoughCoins> ().onDismissed = (global::MobyShop.ShopNotEnoughCoins.Dismissed dismissedWith) => {
                        var response = dismissedWith == global::MobyShop.ShopNotEnoughCoins.Dismissed.BuyMoreCoins ? Shop.BuyResponse.BuyMoreCoins : Shop.BuyResponse.Cancelled;
                        callback(false, "Not enough coins available", response);
                    };
                    return;
                }
                else
                {
                    notEnoughCoinsInterface.onDismissed = (ShopNotEnoughCoins.Dismissed dismissedWith) => {
                        var response = dismissedWith == ShopNotEnoughCoins.Dismissed.BuyMoreCoins ? Shop.BuyResponse.BuyMoreCoins : Shop.BuyResponse.Cancelled;
                        callback(false, "Not enough coins available", response);
                    };
                    notEnoughCoinsInterface.Show();
                    return;
                }
                //return;
            }
            else
            {
                //
                if (shopConfirmInterface == null)
                {
                    var uigo = MobyShop.Shop.BillingIngameCurrentUI;
                    if (uigo == null)
                    {
                        callback(false, "Failed to get UI confirm object.", Shop.BuyResponse.Failed);
                        return;
                    }
                    var canvas = CanvasHelper.GetCanvas();
                    uigo.transform.localPosition = Vector2.zero;
                    uigo.gameObject.SetActive(true);
                    uigo.transform.parent = canvas.transform;
                    var rt = uigo.GetComponent <RectTransform> ();
                    rt.offsetMin = rt.offsetMax = Vector2.zero;
                    rt.anchorMin = Vector2.zero;
                    rt.anchorMax = Vector2.one;
                    uigo.GetComponentCompatibleWith <global::ShopConfirm> ().onDismissed = (BillingInGameCurrency.AcceptOrCancel result) => {
                        //Debug.Log("OnBuyResult : " + result );
                        if (result == BillingInGameCurrency.AcceptOrCancel.Accepted)
                        {
                            Shop.IncrementProductClassAmount(product.ingameCurrencyClass, -Mathf.Abs(product.price));
                            CallUnlockProduct(BoughtOrRestored.Bought, product);
                            callback(true, "", Shop.BuyResponse.Ok);
                        }
                        else
                        {
                            callback(false, "User cancelled", Shop.BuyResponse.Cancelled);
                        }
                    };
                }
                else
                {
                    shopConfirmInterface.onDismissed = (BillingInGameCurrency.AcceptOrCancel result) => {
                        if (result == BillingInGameCurrency.AcceptOrCancel.Accepted)
                        {
                            Shop.IncrementProductClassAmount(product.ingameCurrencyClass, -Mathf.Abs(product.price));
                            CallUnlockProduct(BoughtOrRestored.Bought, product);
                            callback(true, "", Shop.BuyResponse.Ok);
                        }
                        else
                        {
                            callback(false, "User cancelled", Shop.BuyResponse.Cancelled);
                        }
                    };
                    shopConfirmInterface.Show(   );
                    return;
                }
            }
        }