Example #1
0
        /**
         * Initializes a session to buy a product,
         * The functino takes a product id, this is the id that you have configured the product to use
         * in the product configuration editor.
         * a callback can be given wihch will return true or false when he product has been buyght.
         * If you want to listen on the event emitted.
         */
        public static void BuyProduct(string productId, System.Action <bool /*okay*/, string /*message*/, Shop.BuyResponse> callback, ShopConfirm confirmInterface, ShopNotEnoughCoins notEnoughCoinsInterface)
        {
            ProductInfo product = ShopConfig.GetProductByProductId(productId);

            if (product != null)
            {
                Billing.BuyProduct(product, (bool okay, string message, Shop.BuyResponse response) => {
                    if (_instance != null && Verbose)
                    {
                        Debug.Log("MobyShop: On Buy Product Result : " + okay + " msg=" + message);
                    }
                    if (callback != null)
                    {
                        callback(okay, message, response);
                    }
                    //OnBuyProductResult();
                    if (okay && OnProductBought != null)
                    {
                        //ProductInfo productBought = null;
                        OnProductBought.Invoke(BoughtOrRestored.Bought, product, product.GetClassAmount());
                    }
                }, confirmInterface, notEnoughCoinsInterface);
            }
            else
            {
                Debug.LogError("MobyShop:Error buying products");
            }
        }
Example #2
0
        /**
         * Increment the product class amount can be used to increment the value of a product class
         * for instance if you have 3 products which gives you gold coins you might also want the player
         * to be able to pickup gold coins in the game. You can use this to increment the value that the
         * player pick's up in the game.
         */
        public static void IncrementProductClassAmount(string productClass, int incrementWith)
        {
            var prod = ShopConfig.GetProductByClassId(productClass);

            if (prod != null)
            {
                prod.AddValueToProductAmountAndSaveLocalData(incrementWith);
            }
            else
            {
                Debug.LogError("MobyShop: Couldn't find a Product With Class Name : " + productClass + "\nAvailable classes :" + string.Join(",", ShopConfig.ProductClasses));
                // Error porduct doesnt exists...
            }
        }
        public static void Open(ShopConfig config = null)
        {
            var wnd = EditorWindow.GetWindow <ShopConfigurationEditor>(true);

            wnd.Show();
            if (config != null)
            {
                wnd.shopcfg = config;
            }
            else
            {
                wnd.shopcfg = ShopConfig.instance;
            }
            wnd.CenterOnMainWin();
        }
 void CreateProduct()
 {
     ShopConfig.CreateProduct("NewProduct" + Random.Range(0, int.MaxValue));
     SaveConfig();
 }
        void DrawSelectedProduct()
        {
            GUILayout.BeginVertical(new GUILayoutOption[0]);
            GUILayout.BeginVertical(new GUILayoutOption[] {
                GUILayout.Width(500f)
            });


            if (SelectedProductIdx < 0)
            {
                GUILayout.Label("", ShopConfigurationEditor.styles.title, new GUILayoutOption[0]);
            }
            else
            {
                GUILayout.Label("" + Products[SelectedProductIdx].ProductDisplayName, ShopConfigurationEditor.styles.title, new GUILayoutOption[0]);
            }

            this.productInspectorScroll = GUILayout.BeginScrollView(this.productInspectorScroll, "OL Box");

            if (SelectedProductIdx < 0)
            {
                DrawCenterMessage("No product selected");
            }
            else
            {
                DrawProductProperties();
            }

            GUILayout.EndScrollView();
            GUILayout.EndVertical();
            GUILayout.Space(10f);
            //BuildTarget buildTarget = BuildPlayerWindow.CalculateSelectedBuildTarget();
            GUILayout.BeginHorizontal(new GUILayoutOption[0]);
            GUI.enabled = true;             //(BuildPipeline.IsBuildTargetSupported(buildTarget) && BuildPipeline.GetBuildTargetGroup(EditorUserBuildSettings.activeBuildTarget) != BuildPipeline.GetBuildTargetGroup(buildTarget));



            if (Selected == null)
            {
                GUILayout.Label("");                 // empry space..
            }
            else
            {
                if (GUILayout.Button("Delete product"))
                {
                    try {
                        //var billingId = jobs[selectedJob].BillingId;
                        var  id       = Products[SelectedProductIdx].ProductId;
                        var  dispName = Products[SelectedProductIdx].ProductDisplayName;
                        bool no       = EditorUtility.DisplayDialog("Are you sure?", "Do you want to permanently delete the product : " + dispName, "Cancel", "Delete");
                        if (!no)
                        {
                            ShopConfig.RemoveProduct(id);
                            SelectedProductIdx = -1;
                        }
                        else
                        {
                        }
                    } catch (System.Exception e) {
                        Debug.LogError("Exception: " + e);
                    }
                }
            }



            //GUI.enabled = BuildPipeline.IsBuildTargetSupported(buildTarget);
            //if (GUILayout.Button(new GUIContent("Player Settings..."), new GUILayoutOption[] { GUILayout.Width(110f) })) {
            //Selection.activeObject = Unsupported.GetSerializedAssetInterfaceSingleton("PlayerSettings");
            //}
            GUILayout.EndHorizontal();
            GUI.enabled = true;
            GUILayout.EndVertical();
        }
Example #6
0
 /**
  * Initiallize the singleton instance.
  */
 void Awake()
 {
     _instance = this;
 }
Example #7
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;
                }
            }
        }
Example #8
0
 public static void ClearAllPurchaseData()
 {
     ShopConfig.ClearPrefsForPurchases();
 }
Example #9
0
 /**
  * Returns all the available product classes
  */
 public static string[] GetAvailableProductClasses( )
 {
     return(ShopConfig.GetAvailableProductClasses( ));
 }
Example #10
0
 /**
  * Return true if the product class exists, false if not.
  * it. call it with 'coins' and if there is one or more products declared
  * with the id 'coins' as the product class. then this will return true.
  */
 public static bool ProductClassExists(string productClass)
 {
     return(ShopConfig.ProductClassExists(productClass));
 }
Example #11
0
 /**
  * Used to get the value of a product with a specified class, for instance if you have 3 products which should all add
  * to the value type "gold coins" you should use this to get the value of the gold coins bought or accumulated.
  */
 public static int GetProductClassAmount(string productClass)
 {
     return(ShopConfig.GetProductClassValue(productClass));
 }
Example #12
0
 /**
  * GetProduct returns a ProductInfo instance based on the ProductId.
  * The ProductInfo instance holds the configuration of a product as
  * well has handles to getting the status of the product.
  */
 public static ProductInfo GetProduct(string productId)
 {
     return(ShopConfig.GetProductByProductId(productId));
 }