You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
866 B

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class InventoryUI : MonoBehaviour
  5. {
  6. public Inventory inventory;
  7. [SerializeField]
  8. private BagItem ItemPrefab;
  9. [SerializeField]
  10. private Transform Parent;
  11. private void Start()
  12. {
  13. UpdateUI();
  14. }
  15. private void OnEnable()
  16. {
  17. inventory.OnItemsUpdated += UpdateUI;
  18. }
  19. private void OnDisable()
  20. {
  21. inventory.OnItemsUpdated -= UpdateUI;
  22. }
  23. [ContextMenu("Update UI")]
  24. public void UpdateUI()
  25. {
  26. foreach(Transform child in Parent)
  27. Destroy(child.gameObject);
  28. foreach (Inventory.Data data in inventory.BagItems)
  29. {
  30. BagItem item = Instantiate(ItemPrefab.gameObject, Parent).GetComponent<BagItem>();
  31. item.Initialise(data);
  32. }
  33. }
  34. }