ItemSlot.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. using System.Collections.Generic;
  2. using Assets.HeroEditor4D.InventorySystem.Scripts.Data;
  3. using Assets.HeroEditor4D.InventorySystem.Scripts.Enums;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. namespace Assets.HeroEditor4D.InventorySystem.Scripts.Elements
  7. {
  8. /// <summary>
  9. /// Represents equipment slot. Inventory items can be placed here.
  10. /// </summary>
  11. public class ItemSlot : MonoBehaviour
  12. {
  13. public Image Icon;
  14. public Image Background;
  15. public Sprite ActiveSprite;
  16. public Sprite LockedSprite;
  17. public List<ItemType> Types;
  18. public List<ItemClass> Classes;
  19. public bool Locked
  20. {
  21. get => Icon.sprite == LockedSprite;
  22. set
  23. {
  24. Icon.sprite = value ? LockedSprite : ActiveSprite;
  25. Background.color = value ? new Color32(150, 150, 150, 255) : new Color32(255, 255, 255, 255);
  26. }
  27. }
  28. public bool Supports(Item item)
  29. {
  30. return Types.Contains(item.Params.Type) && (Classes.Count == 0 || Classes.Contains(item.Params.Class)) && !Locked;
  31. }
  32. }
  33. }