/// <summary> /// Purchase this instance. /// </summary> public bool Purchase(Action <IAPPackage> callback = null) { bool result = false; if (fetchFromStore) { // Debug.Log("purcahse " + _callback); _purchaseCallback = callback; IAPManager.OnIAPProcessPurchase += handleOnIAPProcessPurchaseInternal; IAPManager.OnIAPPurchaseFailed += handleOnIAPPurchaseFailedInternal; IAPManager.PurchaseProduct(uid); } else { if (productType == IAPProductType.NonConsumable && amount > 0) { //For non-consumable products, only purcahse one } else { // Get the currency IAPCurrency cur = IAPInventoryManager.GetCurrency(this.currency); // Check if enough currency if (cur != null && cur.Consume(this.price)) { DeliveryProduct(); result = true; } } } return(result); }
/// <summary> /// Purchase this instance. /// </summary> public bool Upgrade() { bool result = false; // Get the currency IAPCurrency cur = IAPInventoryManager.GetCurrency(this.currency); // Get the Level Object IAPAbilityLevel lv = null; if (levels != null && level < levels.Count - 1) { lv = levels[level]; // Check if enough currency // Consume package, delay the save process until next save if (cur != null && cur.Consume(lv.price, true)) { // Upgrade _data.lv += 1; result = true; // Save(); } } return(result); }