InventoryManager.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using UnityEngine;
  2. using System.Collections.Generic;
  3. /// <summary>
  4. /// This component is responsible of the Inventory which listens for purchases from the StoreManager, and increments the inventory count
  5. /// for items being tracked in the inventory
  6. ///
  7. /// It keeps the inventory stored in PlayerPrefs.
  8. /// Besides keeping count, it also helps in keeping track of items to be equipped in the next game using ToggleEquip.
  9. /// Once the equipped items need to be consumed (i.e. item count needs to be decremented), ConsumeEquipped needs to be called.
  10. /// Other query methods for UI purposes are available (HasEquipped and GetPowerupCount)
  11. ///
  12. /// Note that each purchase counts as 5 items of the bought product, e.g. LifePack is 5 hearts. This might change in the future and might need to updated accordingly
  13. /// </summary>
  14. public class InventoryManager : GenericInventoryManager<StoreProductId, InventoryItem>
  15. {
  16. private const string ALREADY_GIVEN_START_WAVES = "awgpbdfge";
  17. private const int START_WAVES = 3;
  18. void Start()
  19. {
  20. CoreNotificationCenter.AddListener(OnReceivedStoreProducts, CoreNotificationType.ReceivedStoreProducts);
  21. }
  22. void OnDestroy()
  23. {
  24. CoreNotificationCenter.RemoveListener(OnReceivedStoreProducts, CoreNotificationType.ReceivedStoreProducts);
  25. }
  26. void OnReceivedStoreProducts(CoreNotification note)
  27. {
  28. if (PlayerPrefs.GetInt(ALREADY_GIVEN_START_WAVES, 0) == 0)
  29. {
  30. for (int i = 0; i < START_WAVES; i++)
  31. {
  32. InventoryManager.Instance.Increment(InventoryItem.specialwave);
  33. }
  34. PlayerPrefs.SetInt(ALREADY_GIVEN_START_WAVES, 1);
  35. PlayerPrefs.Save();
  36. }
  37. }
  38. }