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

Loading…
Cancel
Save