/** * Get the value of product class. */ public static int GetProductClassValue(string productClass) { if (productClass == "") { Debug.LogError("MobyShop: Invalid product class - Empty String"); return(-1); } int fnd = 0; var availClasses = new System.Collections.Generic.List <string>(); ProductInfo product = null; foreach (var p in ProductList) { if (fnd == 0 && p.ProductClass == productClass) { product = p; fnd++; } else if (fnd > 0 && p.ProductClass == productClass) { fnd++; } availClasses.Add(p.ProductClass); } if (fnd == 0) { Debug.LogError("MobyShop: Product class :" + productClass + " was not found!\nAvailable classes:" + string.Join(",", availClasses.ToArray())); return(-1); } return(product.GetClassAmount()); }
/** * 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"); } }
static void CallUnlockProduct(BoughtOrRestored state, ProductInfo product) { try { product.OnBought(); if (OnProductUnlocked != null) { OnProductUnlocked.Invoke(state, product, product.GetClassAmount()); } }catch (System.Exception e) { Debug.LogError("MobyShop: Exception unlocking product :" + e.ToString()); } }