|
|
|
@ -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,6 +124,8 @@ public class ShopManager : MonoBehaviour, IDetailedStoreListener
|
|
|
|
|
var product = purchaseEvent.purchasedProduct;
|
|
|
|
|
|
|
|
|
|
print("Purchase Complete" + product.definition.id);
|
|
|
|
|
if (currentPurchaseType == PurchaseType.Coins)
|
|
|
|
|
{
|
|
|
|
|
for (int h = 0; h < cItem.Count; h++)
|
|
|
|
|
{
|
|
|
|
|
if (product.definition.id == cItem[h].Id)//consumable item is pressed
|
|
|
|
@ -129,6 +143,28 @@ public class ShopManager : MonoBehaviour, IDetailedStoreListener
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (currentPurchaseType == PurchaseType.Pipes)
|
|
|
|
|
{
|
|
|
|
|
for (int h = 0; h < pItem.Count; h++)
|
|
|
|
|
{
|
|
|
|
|
if (product.definition.id == pItem[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;
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|