|
|
|
@ -42,6 +42,7 @@ public class ShopManager : MonoBehaviour, IDetailedStoreListener
|
|
|
|
|
|
|
|
|
|
public List<ConsumableItem> cItem;
|
|
|
|
|
public List<ConsumableItem> pItem;
|
|
|
|
|
public List<ConsumableItem> eItem;
|
|
|
|
|
public List<int> coinsRewards;
|
|
|
|
|
//public NonConsumableItem ncItem;
|
|
|
|
|
//public SubscriptionItem sItem;
|
|
|
|
@ -54,7 +55,9 @@ public class ShopManager : MonoBehaviour, IDetailedStoreListener
|
|
|
|
|
public PayloadData payloadData;
|
|
|
|
|
|
|
|
|
|
public List<ButtonState> PipeButtons;
|
|
|
|
|
public List<ButtonState> EffectButtons;
|
|
|
|
|
//public List<Button> PurchaseButtons;
|
|
|
|
|
public GameObject NotEnoughCoinsObj;
|
|
|
|
|
[Serializable]
|
|
|
|
|
public class ButtonState
|
|
|
|
|
{
|
|
|
|
@ -70,6 +73,7 @@ public class ShopManager : MonoBehaviour, IDetailedStoreListener
|
|
|
|
|
coinTxt.text = coins.ToString();
|
|
|
|
|
SetupBuilder();
|
|
|
|
|
PipePrefGetter();
|
|
|
|
|
EffectPrefGetter();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -147,21 +151,50 @@ public class ShopManager : MonoBehaviour, IDetailedStoreListener
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
void EffectPrefGetter()
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < EffectButtons.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
EffectButtons[i].isEquipped = PlayerPrefs.GetInt("EffectButtonIsEquipped" + i) == 1 ? true : false;
|
|
|
|
|
EffectButtons[i].isPurchased = PlayerPrefs.GetInt("EffectButtonIsPurchased" + i) == 1 ? true : false;
|
|
|
|
|
|
|
|
|
|
if (EffectButtons[i].isPurchased == false)
|
|
|
|
|
{
|
|
|
|
|
EffectButtons[i].PurchaseButton.gameObject.SetActive(true);
|
|
|
|
|
EffectButtons[i].EquipButton.gameObject.SetActive(false);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
EffectButtons[i].EquipButton.gameObject.SetActive(true);
|
|
|
|
|
EffectButtons[i].PurchaseButton.gameObject.SetActive(false);
|
|
|
|
|
if (EffectButtons[i].isEquipped == true)
|
|
|
|
|
{
|
|
|
|
|
EffectButtons[i].equipButtonText.text = "Equipped";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
EffectButtons[i].equipButtonText.text = "Equip";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region setup and initialize
|
|
|
|
|
void SetupBuilder()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
var builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < cItem.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
builder.AddProduct(cItem[i].Id, ProductType.Consumable);
|
|
|
|
|
}
|
|
|
|
|
for (int i = 1; i < pItem.Count; i++)//Starting from 1 because 1 set of pipe is already bought by default.
|
|
|
|
|
{
|
|
|
|
|
builder.AddProduct(pItem[i].Id, ProductType.NonConsumable);
|
|
|
|
|
}
|
|
|
|
|
//for (int i = 0; i < eItem.Count; i++)//Starting from 1 because 1 set of pipe is already bought by default.
|
|
|
|
|
//{
|
|
|
|
|
// builder.AddProduct(eItem[i].Id, ProductType.NonConsumable);
|
|
|
|
|
//}
|
|
|
|
|
//builder.AddProduct(ncItem.Id, ProductType.NonConsumable);
|
|
|
|
|
//builder.AddProduct(sItem.Id, ProductType.Subscription);
|
|
|
|
|
|
|
|
|
@ -191,9 +224,13 @@ public class ShopManager : MonoBehaviour, IDetailedStoreListener
|
|
|
|
|
currentPurchaseType = PurchaseType.Pipes;
|
|
|
|
|
Debug.Log("Purchasing pipes1... : " + pItem[index].Id);
|
|
|
|
|
m_StoreController.InitiatePurchase(pItem[index].Id);
|
|
|
|
|
|
|
|
|
|
//Debug.Log("Purchasing pipes2... : "+ pItem[index].Id);
|
|
|
|
|
}
|
|
|
|
|
public void Consumable_Btn_Pressed_Effects(int index)
|
|
|
|
|
{
|
|
|
|
|
currentPurchaseType = PurchaseType.Effects;
|
|
|
|
|
AddEffects(index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//public void NonConsumable_Btn_Pressed()
|
|
|
|
|
//{
|
|
|
|
@ -212,7 +249,7 @@ public class ShopManager : MonoBehaviour, IDetailedStoreListener
|
|
|
|
|
public PurchaseType currentPurchaseType;
|
|
|
|
|
public enum PurchaseType
|
|
|
|
|
{
|
|
|
|
|
Coins, Pipes,
|
|
|
|
|
Coins, Pipes, Effects,
|
|
|
|
|
}
|
|
|
|
|
#region main
|
|
|
|
|
//processing purchase
|
|
|
|
@ -265,6 +302,28 @@ public class ShopManager : MonoBehaviour, IDetailedStoreListener
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//else if (currentPurchaseType == PurchaseType.Effects)
|
|
|
|
|
//{
|
|
|
|
|
// for (int h = 0; h < eItem.Count; h++)
|
|
|
|
|
// {
|
|
|
|
|
// Debug.Log("product.definition.id : " + product.definition.id);
|
|
|
|
|
// Debug.Log("pItem[h].Id : " + eItem[h].Id);
|
|
|
|
|
// if (product.definition.id == eItem[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++)
|
|
|
|
|
// //{
|
|
|
|
|
// AddEffects(h);
|
|
|
|
|
// //}
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
//else if (product.definition.id == ncItem.Id)//non consumable
|
|
|
|
|
//{
|
|
|
|
@ -396,7 +455,14 @@ public class ShopManager : MonoBehaviour, IDetailedStoreListener
|
|
|
|
|
coins += toAdd;
|
|
|
|
|
PlayerPrefs.SetInt("Coin", coins);
|
|
|
|
|
StartCoroutine(startCoinShakeEffect(coins - toAdd, coins, .5f));
|
|
|
|
|
}
|
|
|
|
|
void SubtractCoins(int coinsToSubtract)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
int coins = PlayerPrefs.GetInt("Coin");
|
|
|
|
|
coins -= coinsToSubtract;
|
|
|
|
|
PlayerPrefs.SetInt("Coin", coins);
|
|
|
|
|
StartCoroutine(startCoinShakeEffect(coins + coinsToSubtract, coins, .5f));
|
|
|
|
|
}
|
|
|
|
|
public void EquipUnEquipPipe(int buttonIndex)
|
|
|
|
|
{
|
|
|
|
@ -428,10 +494,48 @@ public class ShopManager : MonoBehaviour, IDetailedStoreListener
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void EquipUnEquipEffect(int buttonIndex)
|
|
|
|
|
{
|
|
|
|
|
if (EffectButtons[buttonIndex].isEquipped)
|
|
|
|
|
{
|
|
|
|
|
PlayerPrefs.SetInt("EffectButtonIsEquipped" + buttonIndex, 0);
|
|
|
|
|
PlayerPrefs.SetInt("EffectButtonIsEquipped-1", 1);
|
|
|
|
|
EffectIndexSetter(-1);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < EffectButtons.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
if (i != buttonIndex)
|
|
|
|
|
{
|
|
|
|
|
EffectButtons[i].isEquipped = false;
|
|
|
|
|
PlayerPrefs.SetInt("EffectButtonIsEquipped" + i, 0);
|
|
|
|
|
EffectButtons[i].equipButtonText.text = "Equip";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
EffectButtons[i].isEquipped = true;
|
|
|
|
|
PlayerPrefs.SetInt("EffectButtonIsEquipped" + i, 1);
|
|
|
|
|
EffectButtons[i].equipButtonText.text = "Equipped";
|
|
|
|
|
EffectIndexSetter(buttonIndex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void PipeIndexSetter(int index)
|
|
|
|
|
{
|
|
|
|
|
GameManager.PipeIndex = index;
|
|
|
|
|
}
|
|
|
|
|
public void EffectIndexSetter(int index)
|
|
|
|
|
{
|
|
|
|
|
GameManager.EffectIndex = index;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AddPipes(int index)
|
|
|
|
|
{
|
|
|
|
|
PlayerPrefs.SetInt("PipeButtonIsPurchased" + index, 1);
|
|
|
|
@ -440,6 +544,23 @@ public class ShopManager : MonoBehaviour, IDetailedStoreListener
|
|
|
|
|
PipeButtons[index].PurchaseButton.gameObject.SetActive(false);
|
|
|
|
|
Debug.Log("Pipe " + index + " purchased");
|
|
|
|
|
}
|
|
|
|
|
void AddEffects(int index)
|
|
|
|
|
{
|
|
|
|
|
int coins = PlayerPrefs.GetInt("Coin");
|
|
|
|
|
if (coins > eItem[index].price)
|
|
|
|
|
{
|
|
|
|
|
SubtractCoins((int)eItem[index].price);
|
|
|
|
|
PlayerPrefs.SetInt("EffectButtonIsPurchased" + index, 1);
|
|
|
|
|
EffectButtons[index].isPurchased = true;
|
|
|
|
|
EffectButtons[index].EquipButton.gameObject.SetActive(true);
|
|
|
|
|
EffectButtons[index].PurchaseButton.gameObject.SetActive(false);
|
|
|
|
|
Debug.Log("Effect " + index + " purchased");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
NotEnoughCoinsObj.SetActive(true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
float val;
|
|
|
|
|
IEnumerator startCoinShakeEffect(int oldValue, int newValue, float animTime)
|
|
|
|
|
{
|
|
|
|
|