IAP Pipes

dev-hazim
Ali Sharoz 1 month ago
parent 2a137f67f5
commit 8be0000faf

File diff suppressed because it is too large Load Diff

@ -7,6 +7,7 @@ using System.Collections.Generic;
using static UnityEngine.Networking.UnityWebRequest; using static UnityEngine.Networking.UnityWebRequest;
using UnityEngine.Purchasing.Extension; using UnityEngine.Purchasing.Extension;
using UnityEngine.UI; using UnityEngine.UI;
using UnityEngine.WSA;
[Serializable] [Serializable]
public class ConsumableItem public class ConsumableItem
@ -39,6 +40,7 @@ public class ShopManager : MonoBehaviour, IDetailedStoreListener
IStoreController m_StoreContoller; IStoreController m_StoreContoller;
public List<ConsumableItem> cItem; public List<ConsumableItem> cItem;
public List<ConsumableItem> pItem;
public List<int> coinsRewards; public List<int> coinsRewards;
//public NonConsumableItem ncItem; //public NonConsumableItem ncItem;
//public SubscriptionItem sItem; //public SubscriptionItem sItem;
@ -86,6 +88,13 @@ public class ShopManager : MonoBehaviour, IDetailedStoreListener
public void Consumable_Btn_Pressed(int index) public void Consumable_Btn_Pressed(int index)
{ {
//AddCoins(50); //AddCoins(50);
currentPurchaseType = PurchaseType.Coins;
m_StoreContoller.InitiatePurchase(cItem[index].Id);
}
public void Consumable_Btn_Pressed_Pipes(int index)
{
//AddCoins(50);
currentPurchaseType = PurchaseType.Pipes;
m_StoreContoller.InitiatePurchase(cItem[index].Id); m_StoreContoller.InitiatePurchase(cItem[index].Id);
} }
@ -102,8 +111,11 @@ public class ShopManager : MonoBehaviour, IDetailedStoreListener
// m_StoreContoller.InitiatePurchase(sItem.Id); // m_StoreContoller.InitiatePurchase(sItem.Id);
//} //}
#endregion #endregion
public PurchaseType currentPurchaseType;
public enum PurchaseType
{
Coins, Pipes,
}
#region main #region main
//processing purchase //processing purchase
public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs purchaseEvent) public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs purchaseEvent)
@ -112,23 +124,47 @@ public class ShopManager : MonoBehaviour, IDetailedStoreListener
var product = purchaseEvent.purchasedProduct; var product = purchaseEvent.purchasedProduct;
print("Purchase Complete" + product.definition.id); print("Purchase Complete" + product.definition.id);
for (int h = 0; h < cItem.Count; h++) if (currentPurchaseType == PurchaseType.Coins)
{ {
if (product.definition.id == cItem[h].Id)//consumable item is pressed for (int h = 0; h < cItem.Count; h++)
{ {
string receipt = product.receipt; if (product.definition.id == cItem[h].Id)//consumable item is pressed
data = JsonUtility.FromJson<Data>(receipt); {
payload = JsonUtility.FromJson<Payload>(data.Payload); string receipt = product.receipt;
payloadData = JsonUtility.FromJson<PayloadData>(payload.json); data = JsonUtility.FromJson<Data>(receipt);
payload = JsonUtility.FromJson<Payload>(data.Payload);
payloadData = JsonUtility.FromJson<PayloadData>(payload.json);
int quantity = payloadData.quantity; int quantity = payloadData.quantity;
for (int i = 0; i < quantity; i++) for (int i = 0; i < quantity; i++)
{
AddCoins(h);
}
}
}
}
else if (currentPurchaseType == PurchaseType.Pipes)
{
for (int h = 0; h < pItem.Count; h++)
{
if (product.definition.id == pItem[h].Id)//consumable item is pressed
{ {
AddCoins(h); string receipt = product.receipt;
data = JsonUtility.FromJson<Data>(receipt);
payload = JsonUtility.FromJson<Payload>(data.Payload);
payloadData = JsonUtility.FromJson<PayloadData>(payload.json);
int quantity = payloadData.quantity;
for (int i = 0; i < quantity; i++)
{
AddPipes(h);
}
} }
} }
} }
//else if (product.definition.id == ncItem.Id)//non consumable //else if (product.definition.id == ncItem.Id)//non consumable
//{ //{
// RemoveAds(); // RemoveAds();
@ -255,9 +291,15 @@ public class ShopManager : MonoBehaviour, IDetailedStoreListener
{ {
int toAdd = coinsRewards[index]; int toAdd = coinsRewards[index];
int coins = PlayerPrefs.GetInt("Coin"); int coins = PlayerPrefs.GetInt("Coin");
Debug.Log(toAdd + " Coins purchased");
coins += toAdd; coins += toAdd;
PlayerPrefs.SetInt("Coin", coins); PlayerPrefs.SetInt("Coin", coins);
StartCoroutine(startCoinShakeEffect(coins - toAdd, coins, .5f)); StartCoroutine(startCoinShakeEffect(coins - toAdd, coins, .5f));
}
void AddPipes(int index)
{
Debug.Log("Pipe " + index + " purchased");
} }
float val; float val;
IEnumerator startCoinShakeEffect(int oldValue, int newValue, float animTime) IEnumerator startCoinShakeEffect(int oldValue, int newValue, float animTime)

Loading…
Cancel
Save