void RequestNonConsumableProduct(ShopInApp inapp, ShopDelegate callback) { Flow.game_native.startLoading(); UIManager.instance.blockInput = true; #if UNITY_ANDROID string id = inapp.androidBundle; #elif UNITY_IPHONE string id = inapp.appleBundle; #else Flow.game_native.stopLoading(); Flow.game_native.showMessage("Currently Unavailable", "Purchasing only available in mobile devices."); return; #endif IAP.purchaseNonconsumableProduct(id, didSucceed => { Flow.game_native.stopLoading(); UIManager.instance.blockInput = false; if (didSucceed) { if (inapp.type == ShopInAppType.NonConsumable && inapp.appleBundle.ToLower().Contains("noads")) { Save.Set(PlayerPrefsKeys.NOADS, true); Advertisement.NoAdsPurchased(); Save.SaveAll(); } callback(ShopResultStatus.Success, id); } else { callback(ShopResultStatus.Failed, id); } }); }
void RequestNonConsumableProduct(ShopInApp inapp, ShopDelegate callback) { Flow.game_native.startLoading(); #if UNITY_ANDROID string id = inapp.androidBundle; #elif UNITY_IPHONE string id = inapp.appleBundle; #else Flow.game_native.stopLoading(); Flow.game_native.showMessage("Currently Unavailable","Purchasing only available in mobile devices."); return; #endif IAP.purchaseNonconsumableProduct(id, didSucceed => { Flow.game_native.stopLoading(); if(didSucceed) { if(inapp.type == ShopInAppType.NonConsumable && inapp.appleBundle.ToLower().Contains("noads")) { Save.Set(PlayerPrefsKeys.NOADS, true); Save.SaveAll(); } callback(ShopResultStatus.Success, id); } else { callback(ShopResultStatus.Failed, id); } }); }
void RequestConsumableProduct(ShopInApp inapp, ShopDelegate callback) { Flow.game_native.startLoading(); UIManager.instance.blockInput = true; #if UNITY_ANDROID string id = inapp.androidBundle; #elif UNITY_IPHONE string id = inapp.appleBundle; #else Flow.game_native.stopLoading(); Flow.game_native.showMessage("Currently Unavailable", "Purchasing only available in mobile devices."); return; #endif IAP.purchaseConsumableProduct(id, didSucceed => { Flow.game_native.stopLoading(); UIManager.instance.blockInput = false; if (didSucceed) { if (inapp.isPackOfCoins) { //int coinStock = Save.GetInt(PlayerPrefsKeys.COINS); Flow.header.coins += inapp.coinsCount; //Save.Set(PlayerPrefsKeys.COINS,coinStock); //Save.SaveAll(); } callback(ShopResultStatus.Success, id); if (Save.HasKey(PlayerPrefsKeys.TOKEN)) { // se a compra deu sucesso e o cara esta logado, registrar no server GameJsonAuthConnection conn = new GameJsonAuthConnection(Flow.URL_BASE + "login/shop/coins.php", BuyingConfirmation); WWWForm form = new WWWForm(); form.AddField("coins", Flow.header.coins); conn.connect(form); } } else { callback(ShopResultStatus.Failed, id); /*Debug.Log("Falha na compra de "+id); * purchaseDialog.Show(); * purchaseDialog.SetMessage("Purchase failed"); * purchaseDialog.SetType(PurchaseDialog.DialogTypeEnum.OK);*/ } /*slider.RefreshSliceValues(); * cashMachineSound.audio.Play();*/ }); }
public ShopInApp GetInApp(string appleBundle) { ShopInApp inapp = new ShopInApp(); for (int i = 0; i < inappsList.Length; i++) { if (inappsList[i].appleBundle == appleBundle) { inapp = inappsList[i]; break; } } return(inapp); }
public void PurchaseInApp(string id, ShopDelegate callback) { //Debug.Log("PurchaseInApp"); ShopInApp inapp = GetInApp(id); if (inapp.type == ShopInAppType.Consumable) { //Debug.Log("Consumable"); RequestConsumableProduct(inapp, callback); } else { //Debug.Log("NonConsumable"); RequestNonConsumableProduct(inapp, callback); } }
public void OnRefreshShop(string error, IJSonObject data, object state) { bool refreshPrime = (bool)state; if (error != null) { Debug.Log(error); } else { //Debug.Log(data); IJSonObject inapps = data["inapps"]; IJSonObject items = data["items"]; IJSonObject features = data["features"]; foreach (IJSonObject inapp in inapps.ArrayItems) { ShopInApp tempInApp = new ShopInApp(); tempInApp.androidBundle = inapp["android"].StringValue; tempInApp.appleBundle = inapp["apple"].StringValue; tempInApp.dolarPrice = inapp["price"].ToFloat(); tempInApp.name = inapp["name"].StringValue; tempInApp.id = inapp["id"].Int32Value; tempInApp.description = inapp["description"].StringValue; tempInApp.isPackOfCoins = inapp["coins"].Int32Value > 0; tempInApp.type = inapp["type"].StringValue == "Consumable"? ShopInAppType.Consumable : ShopInAppType.NonConsumable; tempInApp.goodCount = inapp["goodCount"].Int32Value; tempInApp.coinsCount = inapp["coins"].Int32Value; //Debug.Log(tempInApp.name); bool foundInApp = false; for (int i = 0; i < Flow.config.GetComponent <ConfigManager>().shopInApps.Length; i++) { if (Flow.config.GetComponent <ConfigManager>().shopInApps[i].appleBundle == tempInApp.appleBundle || Flow.config.GetComponent <ConfigManager>().shopInApps[i].androidBundle == tempInApp.androidBundle) { tempInApp.image = Flow.config.GetComponent <ConfigManager>().shopInApps[i].image; Flow.config.GetComponent <ConfigManager>().shopInApps[i] = tempInApp; foundInApp = true; break; } } if (!foundInApp) { Flow.config.GetComponent <ConfigManager>().shopInApps.Add(tempInApp, ref Flow.config.GetComponent <ConfigManager>().shopInApps); } } Array.Sort(Flow.config.GetComponent <ConfigManager>().shopInApps, delegate(ShopInApp a, ShopInApp b) { return(a.id.CompareTo(b.id)); }); bool hasToRefreshGoodsScroll = false; foreach (IJSonObject item in items.ArrayItems) { ShopItem tempItem = new ShopItem(); tempItem.id = item["item_id"].StringValue; tempItem.name = item["name"].StringValue; tempItem.coinPrice = item["price"].Int32Value; tempItem.type = item["type"].StringValue == "Item"? ShopItemType.NonConsumable : ShopItemType.Consumable; tempItem.hide = item["hide"].Int32Value == 1; string[] ids = {}; string[] counts = {}; try { ids = item["itemsWithin"].StringValue.Split(','); counts = item["itemsCount"].StringValue.Split(','); } catch { ids = new string[] { item["itemsWithin"].StringValue }; counts = new string[] { item["itemsCount"].StringValue }; } if (!item["itemsWithin"].IsNull) { List <ShopItem> tempIWList = new List <ShopItem>(); for (int i = 0; i < ids.Length; i++) { //Debug.Log("iti: "+ids[i]); //Debug.Log("counti: "+counts[i]); ShopItem iw = GetShopItem(ids[i].Trim()); //ShopItem jose = new ShopItem(); iw.count = int.Parse(counts[i]); iw.id = ids[i].Trim(); tempIWList.Add(iw); } tempItem.arraySize = tempIWList.Count; tempItem.itemsWithin = tempIWList.ToArray(); } else { tempItem.arraySize = 0; tempItem.itemsWithin = new ShopItem[] {}; } tempItem.description = item["description"].StringValue; //tempItem.hide = item["hide"].Int32Value == 1; //Debug.Log("item: "+tempItem.name); bool foundItem = false; for (int i = 0; i < Flow.config.GetComponent <ConfigManager>().shopItems.Length; i++) { if (Flow.config.GetComponent <ConfigManager>().shopItems[i].id == tempItem.id) { tempItem.image = Flow.config.GetComponent <ConfigManager>().shopItems[i].image; Flow.config.GetComponent <ConfigManager>().shopItems[i] = tempItem; foundItem = true; hasToRefreshGoodsScroll = true; break; } } if (!foundItem) { //Debug.Log("adicionando "+tempItem.name); hasToRefreshGoodsScroll = true; Flow.config.GetComponent <ConfigManager>().shopItems.Add(tempItem, ref Flow.config.GetComponent <ConfigManager>().shopItems); } } Array.Sort(Flow.config.GetComponent <ConfigManager>().shopItems, delegate(ShopItem a, ShopItem b) { return(a.id.CompareTo(b.id)); }); Flow.config.GetComponent <ConfigManager>().shopFeatures.coinsFacebook = features["facebook"].Int32Value; Flow.config.GetComponent <ConfigManager>().shopFeatures.coinsInvite = features["invite"].Int32Value; Flow.config.GetComponent <ConfigManager>().shopFeatures.coinsLike = features["like"].Int32Value; Flow.config.GetComponent <ConfigManager>().shopFeatures.coinsRate = features["rate"].Int32Value; Flow.config.GetComponent <ConfigManager>().shopFeatures.coinsShare = features["share"].Int32Value; Flow.config.GetComponent <ConfigManager>().shopFeatures.coinsVideo = features["video"].Int32Value; Flow.config.GetComponent <ConfigManager>().shopFeatures.coinsWidget = features["widget"].Int32Value; if (refreshPrime && hasToRefreshGoodsScroll && Application.loadedLevelName == "Mainmenu") { UIPanelManager.instance.transform.FindChild("ShopScenePanel").GetComponent <Shop>().RefreshItemsScroll(); } } if (refreshPrime) { Init(); } }
public void OfferCoinPackAndBuyItem(ShopDelegate callback, ShopItem item) { // nao tem coins int difference = item.coinPrice - Flow.header.coins; ShopInApp coinPackToOffer = new ShopInApp(); ShopInApp biggestPack = new ShopInApp(); foreach (ShopInApp pack in coinPacks) { Debug.Log(pack.coinsCount); if (pack.coinsCount >= difference) { Debug.Log("coinpack selecionado: " + pack.appleBundle); coinPackToOffer = pack; break; } int mostCoins = 0; if (mostCoins < pack.coinsCount) { mostCoins = pack.coinsCount; biggestPack = pack; } } if (coinPackToOffer.name == null) { coinPackToOffer = biggestPack; } #if UNITY_ANDROID && !UNITY_EDITOR string packBundle = coinPackToOffer.androidBundle; #elif UNITY_IPHONE && !UNITY_EDITOR string packBundle = coinPackToOffer.appleBundle; Debug.Log("caiu no iOS e o packBundle: " + coinPackToOffer.appleBundle); #else string packBundle; Flow.game_native.showMessage("Not Enough Coins", "You don't have enough coins to buy this item"); return; #endif //List<string> tList = new List<string>(); Flow.game_native.startLoading(); UIManager.instance.blockInput = true; IAP.purchaseConsumableProduct(packBundle, purchased => { Flow.game_native.stopLoading(); UIManager.instance.blockInput = false; if (purchased) { Flow.header.coins += coinPackToOffer.coinsCount; if (Flow.header.coins >= item.coinPrice) { Flow.header.coins -= item.coinPrice; foreach (ShopItem iw in item.itemsWithin) { //comprou o pack e agora tem coins suficientes pra comprar o item if (Save.HasKey(PlayerPrefsKeys.ITEM + iw.id) && iw.type == ShopItemType.Consumable) { int userStock = Save.GetInt(PlayerPrefsKeys.ITEM + iw.id); userStock += iw.count; Save.Set(PlayerPrefsKeys.ITEM + iw.id, userStock); } else if (!Save.HasKey(PlayerPrefsKeys.ITEM + iw.id) && iw.type == ShopItemType.NonConsumable) { Save.Set(PlayerPrefsKeys.ITEM + iw.id, 1); } else { Save.Set(PlayerPrefsKeys.ITEM + iw.id, iw.count); } } Save.SaveAll(); callback(ShopResultStatus.Success, item.id); if (Save.HasKey(PlayerPrefsKeys.TOKEN)) { // se a compra deu sucesso e o cara esta logado, registrar no server GameJsonAuthConnection conn = new GameJsonAuthConnection(Flow.URL_BASE + "login/shop/buy.php", BuyingConfirmation); WWWForm form = new WWWForm(); for (int i = 0; i < item.itemsWithin.Length; i++) { form.AddField("items[" + i + "][id]", item.itemsWithin[i].id); form.AddField("items[" + i + "][count]", Save.GetInt(PlayerPrefsKeys.ITEM + item.itemsWithin[i].id)); form.AddField("coins", Flow.header.coins); } conn.connect(form); } } else { // comprou o pack e mesmo assim nao tem coins suficientes pra comprar o item Flow.game_native.showMessage("Not Enough Coins", "You'll need to buy another pack to buy this item!"); callback(ShopResultStatus.Failed, item.id); } //Save.Set(PlayerPrefsKeys.COINS.ToString(),Flow.header.coins); } else { // nao tem coins para comprar o item Flow.game_native.showMessage("Not Enough Coins", "You don't have enough coins to buy this item"); callback(ShopResultStatus.Failed, item.id); } }); }
void ShopSettings(ConfigManager config) { EditorGUILayout.LabelField("Game In Apps", EditorStyles.miniBoldLabel); if (GUILayout.Button(!config.showInApps ? "Open InApps" : "Close InApps")) { config.showInApps = !config.showInApps; } if (!config.showInApps) { EditorGUILayout.LabelField("Mostra InApps", EditorStyles.whiteMiniLabel); } else { ConfigManagerShop.DrawInApps(config); EditorGUILayout.Space(); if (GUILayout.Button("New InApp")) { ShopInApp inapp = new ShopInApp(); config.shopInApps.Add(inapp, ref config.shopInApps); } } EditorGUILayout.LabelField("Game Items", EditorStyles.miniBoldLabel); if (GUILayout.Button(!config.showShopItems ? "Open Shop Items" : "Close Shop Items")) { config.showShopItems = !config.showShopItems; } if (!config.showShopItems) { EditorGUILayout.LabelField("Mostra Itens comprados com coins", EditorStyles.whiteMiniLabel); } else { ConfigManagerShop.DrawShopItems(config); EditorGUILayout.Space(); if (GUILayout.Button("New Shop Item")) { ShopItem shopItem = new ShopItem(); config.shopItems.Add(shopItem, ref config.shopItems); } } EditorGUILayout.LabelField("Game Features", EditorStyles.miniBoldLabel); if (GUILayout.Button(!config.showShopFeatures ? "Open Shop Features" : "Close Shop Features")) { config.showShopFeatures = !config.showShopFeatures; } if (!config.showShopFeatures) { EditorGUILayout.LabelField("Mostra Features", EditorStyles.whiteMiniLabel); } else { ConfigManagerShop.DrawFeatures(config); } if (GUILayout.Button("Download Shop Info From Server")) { Debug.Log("tamanho da lista: " + config.shopItems.Length); config.GetComponent <ShopManager>().RefreshShop(false); } if (GUILayout.Button("Delete All")) { config.shopInApps = new ShopInApp[] {}; config.shopFeatures = new ShopFeatures(); config.shopItems = new ShopItem[] {}; } }
void ShopSettings(ConfigManager config) { EditorGUILayout.LabelField("Game In Apps", EditorStyles.miniBoldLabel); if (GUILayout.Button(!config.showInApps ? "Open InApps" : "Close InApps")) config.showInApps = !config.showInApps; if (!config.showInApps) { EditorGUILayout.LabelField("Mostra InApps", EditorStyles.whiteMiniLabel); } else { ConfigManagerShop.DrawInApps(config); EditorGUILayout.Space(); if(GUILayout.Button("New InApp")) { ShopInApp inapp = new ShopInApp(); config.shopInApps.Add(inapp,ref config.shopInApps); } } EditorGUILayout.LabelField("Game Items", EditorStyles.miniBoldLabel); if (GUILayout.Button(!config.showShopItems ? "Open Shop Items" : "Close Shop Items")) config.showShopItems = !config.showShopItems; if (!config.showShopItems) { EditorGUILayout.LabelField("Mostra Itens comprados com coins", EditorStyles.whiteMiniLabel); } else { ConfigManagerShop.DrawShopItems(config); EditorGUILayout.Space(); if(GUILayout.Button("New Shop Item")) { ShopItem shopItem = new ShopItem(); config.shopItems.Add(shopItem,ref config.shopItems); } } EditorGUILayout.LabelField("Game Features", EditorStyles.miniBoldLabel); if (GUILayout.Button(!config.showShopFeatures ? "Open Shop Features" : "Close Shop Features")) config.showShopFeatures = !config.showShopFeatures; if (!config.showShopFeatures) { EditorGUILayout.LabelField("Mostra Features", EditorStyles.whiteMiniLabel); } else { ConfigManagerShop.DrawFeatures(config); } if(GUILayout.Button("Download Shop Info From Server")) { Debug.Log("oi"); config.GetComponent<ShopManager>().RefreshShop(false); } if(GUILayout.Button("Delete All")) { config.shopInApps = new ShopInApp[]{}; config.shopFeatures = new ShopFeatures(); config.shopItems = new ShopItem[]{}; } }
public void OnRefreshShop(string error, IJSonObject data, object state) { bool refreshPrime = (bool) state; if(error != null) Debug.Log(error); else { //Debug.Log(data); IJSonObject inapps = data["inapps"]; IJSonObject items = data["items"]; IJSonObject features = data["features"]; foreach(IJSonObject inapp in inapps.ArrayItems) { ShopInApp tempInApp = new ShopInApp(); tempInApp.androidBundle = inapp["android"].StringValue; tempInApp.appleBundle = inapp["apple"].StringValue; tempInApp.dolarPrice = inapp["price"].ToFloat(); tempInApp.name = inapp["name"].StringValue; tempInApp.id = inapp["id"].Int32Value; tempInApp.description = inapp["description"].StringValue; tempInApp.isPackOfCoins = inapp["coins"].Int32Value > 0; tempInApp.type = inapp["type"].StringValue == "Consumable"? ShopInAppType.Consumable : ShopInAppType.NonConsumable; tempInApp.goodCount = inapp["goodCount"].Int32Value; tempInApp.coinsCount = inapp["coins"].Int32Value; //Debug.Log(tempInApp.name); bool foundInApp = false; for(int i = 0 ; i < Flow.config.GetComponent<ConfigManager>().shopInApps.Length ; i++) { if(Flow.config.GetComponent<ConfigManager>().shopInApps[i].appleBundle == tempInApp.appleBundle || Flow.config.GetComponent<ConfigManager>().shopInApps[i].androidBundle == tempInApp.androidBundle) { tempInApp.image = Flow.config.GetComponent<ConfigManager>().shopInApps[i].image; Flow.config.GetComponent<ConfigManager>().shopInApps[i] = tempInApp; foundInApp = true; break; } } if(!foundInApp) { Flow.config.GetComponent<ConfigManager>().shopInApps.Add(tempInApp, ref Flow.config.GetComponent<ConfigManager>().shopInApps); } } Array.Sort(Flow.config.GetComponent<ConfigManager>().shopInApps, delegate(ShopInApp a, ShopInApp b) { return a.id.CompareTo(b.id); }); bool hasToRefreshGoodsScroll = false; foreach(IJSonObject item in items.ArrayItems) { ShopItem tempItem = new ShopItem(); tempItem.id = item["item_id"].StringValue; tempItem.name = item["name"].StringValue; tempItem.coinPrice = item["price"].Int32Value; tempItem.type = item["type"].StringValue == "Item"? ShopItemType.NonConsumable : ShopItemType.Consumable; tempItem.hide = item["hide"].Int32Value == 1; string[] ids = {}; string[] counts = {}; try { ids = item["itemsWithin"].StringValue.Split(','); counts = item["itemsCount"].StringValue.Split(','); } catch { ids = new string[]{ item["itemsWithin"].StringValue }; counts = new string[]{ item["itemsCount"].StringValue }; } if(!item["itemsWithin"].IsNull) { List<ShopItem> tempIWList = new List<ShopItem>(); for(int i = 0 ; i < ids.Length ; i++) { //Debug.Log("iti: "+ids[i]); //Debug.Log("counti: "+counts[i]); ShopItem iw = GetShopItem(ids[i].Trim()); //ShopItem jose = new ShopItem(); iw.count = int.Parse(counts[i]); iw.id = ids[i].Trim(); tempIWList.Add(iw); } tempItem.arraySize = tempIWList.Count; tempItem.itemsWithin = tempIWList.ToArray(); } else { tempItem.arraySize = 0; tempItem.itemsWithin = new ShopItem[]{}; } tempItem.description = item["description"].StringValue; //tempItem.hide = item["hide"].Int32Value == 1; //Debug.Log("item: "+tempItem.name); bool foundItem = false; for(int i = 0 ; i < Flow.config.GetComponent<ConfigManager>().shopItems.Length ; i++) { if(Flow.config.GetComponent<ConfigManager>().shopItems[i].id == tempItem.id) { tempItem.image = Flow.config.GetComponent<ConfigManager>().shopItems[i].image; Flow.config.GetComponent<ConfigManager>().shopItems[i] = tempItem; foundItem = true; hasToRefreshGoodsScroll = true; break; } } if(!foundItem) { //Debug.Log("adicionando "+tempItem.name); hasToRefreshGoodsScroll = true; Flow.config.GetComponent<ConfigManager>().shopItems.Add(tempItem, ref Flow.config.GetComponent<ConfigManager>().shopItems); } } Array.Sort(Flow.config.GetComponent<ConfigManager>().shopItems, delegate(ShopItem a, ShopItem b) { return a.id.CompareTo(b.id); }); Flow.config.GetComponent<ConfigManager>().shopFeatures.coinsFacebook = features["facebook"].Int32Value; Flow.config.GetComponent<ConfigManager>().shopFeatures.coinsInvite = features["invite"].Int32Value; Flow.config.GetComponent<ConfigManager>().shopFeatures.coinsLike = features["like"].Int32Value; Flow.config.GetComponent<ConfigManager>().shopFeatures.coinsRate = features["rate"].Int32Value; Flow.config.GetComponent<ConfigManager>().shopFeatures.coinsShare = features["share"].Int32Value; Flow.config.GetComponent<ConfigManager>().shopFeatures.coinsVideo = features["video"].Int32Value; Flow.config.GetComponent<ConfigManager>().shopFeatures.coinsWidget = features["widget"].Int32Value; if(refreshPrime && hasToRefreshGoodsScroll && Application.loadedLevelName == "Mainmenu") UIPanelManager.instance.transform.FindChild("ShopScenePanel").GetComponent<Shop>().RefreshItemsScroll(); } if(refreshPrime) Init(); }
public void OfferCoinPackAndBuyItem(ShopDelegate callback, ShopItem item) { // nao tem coins int difference = item.coinPrice - Flow.header.coins; ShopInApp coinPackToOffer = new ShopInApp(); ShopInApp biggestPack = new ShopInApp(); foreach(ShopInApp pack in coinPacks) { Debug.Log(pack.coinsCount); if(pack.coinsCount >= difference) { Debug.Log("coinpack selecionado: "+ pack.appleBundle); coinPackToOffer = pack; break; } int mostCoins = 0; if(mostCoins < pack.coinsCount) { mostCoins = pack.coinsCount; biggestPack = pack; } } if(coinPackToOffer.name == null) { coinPackToOffer = biggestPack; } #if UNITY_ANDROID && !UNITY_EDITOR string packBundle = coinPackToOffer.androidBundle; #elif UNITY_IPHONE && !UNITY_EDITOR string packBundle = coinPackToOffer.appleBundle; Debug.Log("caiu no iOS e o packBundle: "+ coinPackToOffer.appleBundle); #else string packBundle; Flow.game_native.showMessage("Not Enough Coins", "You don't have enough coins to buy this item"); return; #endif //List<string> tList = new List<string>(); Flow.game_native.startLoading(); UIManager.instance.blockInput = true; IAP.purchaseConsumableProduct(packBundle, purchased => { Flow.game_native.stopLoading(); UIManager.instance.blockInput = false; if(purchased) { Flow.header.coins += coinPackToOffer.coinsCount; if(Flow.header.coins >= item.coinPrice) { Flow.header.coins -= item.coinPrice; foreach(ShopItem iw in item.itemsWithin) { //comprou o pack e agora tem coins suficientes pra comprar o item if(Save.HasKey(PlayerPrefsKeys.ITEM+iw.id) && iw.type == ShopItemType.Consumable) { int userStock = Save.GetInt(PlayerPrefsKeys.ITEM+iw.id); userStock += iw.count; Save.Set (PlayerPrefsKeys.ITEM+iw.id,userStock); } else if(!Save.HasKey(PlayerPrefsKeys.ITEM+iw.id) && iw.type == ShopItemType.NonConsumable) { Save.Set(PlayerPrefsKeys.ITEM+iw.id,1); } else { Save.Set(PlayerPrefsKeys.ITEM+iw.id, iw.count); } } Save.SaveAll(); callback(ShopResultStatus.Success, item.id); if(Save.HasKey(PlayerPrefsKeys.TOKEN)) { // se a compra deu sucesso e o cara esta logado, registrar no server GameJsonAuthConnection conn = new GameJsonAuthConnection(Flow.URL_BASE + "login/shop/buy.php", BuyingConfirmation); WWWForm form = new WWWForm(); for(int i = 0 ; i < item.itemsWithin.Length ; i++) { form.AddField("items["+i+"][id]", item.itemsWithin[i].id); form.AddField("items["+i+"][count]", Save.GetInt(PlayerPrefsKeys.ITEM+item.itemsWithin[i].id)); form.AddField("coins", Flow.header.coins); } conn.connect(form); } } else { // comprou o pack e mesmo assim nao tem coins suficientes pra comprar o item Flow.game_native.showMessage("Not Enough Coins", "You'll need to buy another pack to buy this item!"); callback(ShopResultStatus.Failed, item.id); } //Save.Set(PlayerPrefsKeys.COINS.ToString(),Flow.header.coins); } else { // nao tem coins para comprar o item Flow.game_native.showMessage("Not Enough Coins", "You don't have enough coins to buy this item"); callback(ShopResultStatus.Failed, item.id); } }); }
public ShopInApp GetInApp(string appleBundle) { ShopInApp inapp = new ShopInApp(); for (int i = 0 ; i < inappsList.Length ; i++) { if(inappsList[i].appleBundle == appleBundle) { inapp = inappsList[i]; break; } } return inapp; }
void RequestConsumableProduct(ShopInApp inapp, ShopDelegate callback) { Flow.game_native.startLoading(); UIManager.instance.blockInput = true; #if UNITY_ANDROID string id = inapp.androidBundle; #elif UNITY_IPHONE string id = inapp.appleBundle; #else Flow.game_native.stopLoading(); Flow.game_native.showMessage("Currently Unavailable","Purchasing only available in mobile devices."); return; #endif IAP.purchaseConsumableProduct(id, didSucceed => { Flow.game_native.stopLoading(); UIManager.instance.blockInput = false; if(didSucceed) { if(inapp.isPackOfCoins) { //int coinStock = Save.GetInt(PlayerPrefsKeys.COINS); Flow.header.coins += inapp.coinsCount; //Save.Set(PlayerPrefsKeys.COINS,coinStock); //Save.SaveAll(); } callback(ShopResultStatus.Success, id); if(Save.HasKey(PlayerPrefsKeys.TOKEN)) { // se a compra deu sucesso e o cara esta logado, registrar no server GameJsonAuthConnection conn = new GameJsonAuthConnection(Flow.URL_BASE + "login/shop/coins.php", BuyingConfirmation); WWWForm form = new WWWForm(); form.AddField("coins", Flow.header.coins); conn.connect(form); } } else { callback(ShopResultStatus.Failed, id); /*Debug.Log("Falha na compra de "+id); purchaseDialog.Show(); purchaseDialog.SetMessage("Purchase failed"); purchaseDialog.SetType(PurchaseDialog.DialogTypeEnum.OK);*/ } /*slider.RefreshSliceValues(); cashMachineSound.audio.Play();*/ }); }
void RequestConsumableProduct(ShopInApp inapp, ShopDelegate callback) { Flow.game_native.startLoading(); #if UNITY_ANDROID string id = inapp.androidBundle; #elif UNITY_IPHONE string id = inapp.appleBundle; #else Flow.game_native.stopLoading(); Flow.game_native.showMessage("Currently Unavailable","Purchasing only available in mobile devices."); return; #endif IAP.purchaseConsumableProduct(id, didSucceed => { Flow.game_native.stopLoading(); if(didSucceed) { if(inapp.isPackOfCoins) { int coinStock = Save.GetInt(PlayerPrefsKeys.COINS); coinStock += inapp.coinsCount; Save.Set(PlayerPrefsKeys.COINS,coinStock); Save.SaveAll(); } callback(ShopResultStatus.Success, id); /*Debug.Log("Sucesso na compra de "+id); int currentCoins = PlayerPrefs.GetInt(PlayerPrefsKeys.Coins.ToString()); if(id.Contains("coins_10k")) { PlaceOrder(currentCoins, Coins_Package_1); } else if(id.Contains("coins_25k")) { PlaceOrder(currentCoins, Coins_Package_2); } else if(id.Contains("coins_50k")) { PlaceOrder(currentCoins, Coins_Package_3); } else if(id.Contains("coins_100k")) { PlayerPrefs.SetInt(PlayerPrefsKeys.DoNotBotherTheUsers.ToString(), 1); PlaceOrder(currentCoins, Coins_Package_4); }*/ } else { callback(ShopResultStatus.Failed, id); /*Debug.Log("Falha na compra de "+id); purchaseDialog.Show(); purchaseDialog.SetMessage("Purchase failed"); purchaseDialog.SetType(PurchaseDialog.DialogTypeEnum.OK);*/ } /*slider.RefreshSliceValues(); cashMachineSound.audio.Play();*/ }); }