Shop Manager is added .

posted in: Weekly Progress | 0

Through shop different things will be upgraded.

These are :

a) Magnet Bar

b) Super Weapon

c) Slow motion time

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class ShopManager : MonoBehaviour
{
public Sprite [] LevelBarImageArray;

public GameObject MagnetLevelBar;
public GameObject MagnetUpdatePriceLabel;

public GameObject SuperWeaponLevelBar;
public GameObject SuperWeaponUpdatePriceLabel;

public GameObject SnailLevelBar;
public GameObject SnailUpdatePriceLabel;

public GameObject SheepOfTimePriceLabel;
public int SheepOfTimePrice;

public float MagnetUpdatefactor;
public int MagnetStartPrice;
public int MagnetMaxLevel;

public float SuperWeaponUpdatefactor;
public int SuperWeaponStartPrice;
public int SuperWeaponMaxLevel;

public float SnailUpdatefactor;
public int SnailStartPrice;
public int SnailMaxLevel;

public string MaxLevelReached;
private int _magnetUpgradePrice;
private int _superWeaponUpgradePrice;
private int _snailUpgradePrice;

void Start()
{
_magnetUpgradePrice = MagnetStartPrice;
_superWeaponUpgradePrice = SuperWeaponStartPrice;
_snailUpgradePrice = SnailStartPrice;
UpdateUI();
}

public void UpdateUI()
{
UpdateMagnetLevelsTexture();
UpdateMagnetLevelPriceLabel();

UpdateSuperWeaponLevelsTexture();
UpdateSuperWeaponLevelPriceLabel();

UpdateSnailLevelsTexture();
UpdateSnailLevelPriceLabel();

UpdateSheepOfTimeCountLabel();
}

public void UpdateMagnetLevelsTexture()
{
MagnetLevelBar.GetComponent<Image>().sprite = LevelBarImageArray[InventoryManager.Instance.Inventory.MagnetLevel];
}

public void UpdateMagnetLevelPriceLabel()
{
_magnetUpgradePrice = GetMagnetUpdatePrice();

if(InventoryManager.Instance.Inventory.MagnetLevel >= MagnetMaxLevel)
MagnetUpdatePriceLabel.GetComponent<Text>().text = MaxLevelReached;
else
MagnetUpdatePriceLabel.GetComponent<Text>().text = _magnetUpgradePrice.ToString();
}

public void UpdateSuperWeaponLevelsTexture()
{
SuperWeaponLevelBar.GetComponent<Image>().sprite = LevelBarImageArray[InventoryManager.Instance.Inventory.SuperWeaponLevel];
}

public void UpdateSuperWeaponLevelPriceLabel()
{
_superWeaponUpgradePrice = GetSuperWeaponUpdatePrice();

if(InventoryManager.Instance.Inventory.SuperWeaponLevel >= SuperWeaponMaxLevel)
SuperWeaponUpdatePriceLabel.GetComponent<Text>().text = MaxLevelReached;
else
SuperWeaponUpdatePriceLabel.GetComponent<Text>().text = _superWeaponUpgradePrice.ToString();
}

public void UpdateSnailLevelsTexture()
{
SnailLevelBar.GetComponent<Image>().sprite = LevelBarImageArray[InventoryManager.Instance.Inventory.SnailLevel];
}

public void UpdateSnailLevelPriceLabel()
{
_snailUpgradePrice = (int)GetSnailUpdatePrice();

if(InventoryManager.Instance.Inventory.SnailLevel >= SnailMaxLevel)
SnailUpdatePriceLabel.GetComponent<Text>().text = MaxLevelReached;
else
SnailUpdatePriceLabel.GetComponent<Text>().text = _snailUpgradePrice.ToString();
}

public int GetMagnetUpdatePrice()
{
_magnetUpgradePrice = MagnetStartPrice;
for(int i = 0; i < InventoryManager.Instance.Inventory.MagnetLevel ; i++)
{
_magnetUpgradePrice = (int)(_magnetUpgradePrice * MagnetUpdatefactor);
}
return _magnetUpgradePrice;
}

public int GetSuperWeaponUpdatePrice()
{
_superWeaponUpgradePrice = SuperWeaponStartPrice;
for(int i = 0; i < InventoryManager.Instance.Inventory.SuperWeaponLevel ; i++)
{
_superWeaponUpgradePrice = (int)(_superWeaponUpgradePrice * SuperWeaponUpdatefactor);
}
return _superWeaponUpgradePrice;
}

public int GetSnailUpdatePrice()
{
_snailUpgradePrice = SnailStartPrice;
for(int i = 0; i < InventoryManager.Instance.Inventory.SnailLevel ; i++)
{
_snailUpgradePrice = (int)(_snailUpgradePrice * SnailUpdatefactor);
}
return _snailUpgradePrice;
}

public void OnButtonClickedMagnetUpgrade()
{
if (InventoryManager.Instance.Inventory.TotalCoins >= _magnetUpgradePrice)
{
if(InventoryManager.Instance.Inventory.MagnetLevel >= MagnetMaxLevel)
return;

InventoryManager.Instance.Inventory.MagnetLevel++;
InventoryManager.Instance.Inventory.TotalCoins = InventoryManager.Instance.Inventory.TotalCoins – _magnetUpgradePrice;
UpdateMagnetLevelsTexture();
UpdateMagnetLevelPriceLabel();

InventoryManager.Instance.SaveInventory();
InventoryManager.Instance.LoadInventory();
}
}

public void OnButtonClickedSuperWeaponUpgrade()
{
if (InventoryManager.Instance.Inventory.TotalCoins >= _superWeaponUpgradePrice)
{
if(InventoryManager.Instance.Inventory.SuperWeaponLevel >= MagnetMaxLevel)
return;

InventoryManager.Instance.Inventory.SuperWeaponLevel++;
InventoryManager.Instance.Inventory.TotalCoins = InventoryManager.Instance.Inventory.TotalCoins – _superWeaponUpgradePrice;
UpdateSuperWeaponLevelsTexture();
UpdateSuperWeaponLevelPriceLabel();

InventoryManager.Instance.SaveInventory();
InventoryManager.Instance.LoadInventory();
}
}

public void OnButtonClickedSnailUpgrade()
{
if (InventoryManager.Instance.Inventory.TotalCoins >= _snailUpgradePrice)
{
if(InventoryManager.Instance.Inventory.SnailLevel >= SnailMaxLevel)
return;

InventoryManager.Instance.Inventory.SnailLevel++;
InventoryManager.Instance.Inventory.TotalCoins = InventoryManager.Instance.Inventory.TotalCoins – _snailUpgradePrice;
UpdateSnailLevelsTexture();
UpdateSnailLevelPriceLabel();

InventoryManager.Instance.SaveInventory();
InventoryManager.Instance.LoadInventory();
}
}

public void OnButtonClickedBuySheepOfTime()
{
if(InventoryManager.Instance.Inventory.TotalCoins >= SheepOfTimePrice)
{
InventoryManager.Instance.Inventory.SheepOfTimeCount++;
InventoryManager.Instance.Inventory.TotalCoins = InventoryManager.Instance.Inventory.TotalCoins – SheepOfTimePrice;

InventoryManager.Instance.SaveInventory();
InventoryManager.Instance.LoadInventory();
}
}

public void UpdateSheepOfTimeCountLabel()
{
SheepOfTimePriceLabel.GetComponent<Text>().text = SheepOfTimePrice.ToString();
}
}

Leave a Reply