| 123456789101112131415161718192021222324252627282930313233343536 |
- using UnityEngine;
- using UnityEngine.UI;
- using TMPro;
- public class InventoryUIController : MonoBehaviour
- {
- public GameObject slotPrefab;
- public Transform gridContainer;
- private CharacterInGroup boundCharacter;
- public void Bind(CharacterInGroup character)
- {
- boundCharacter = character;
- Refresh();
- }
- public void Refresh()
- {
- foreach (Transform child in gridContainer)
- Destroy(child.gameObject);
- foreach (var item in boundCharacter.inventory.items)
- {
- GameObject slot = Instantiate(slotPrefab, gridContainer);
- slot.GetComponentInChildren<Image>().sprite = item.icon;
- slot.GetComponent<DragDropItem>().Init(item, this, boundCharacter);
- }
- }
- public void TransferItem(InventoryItem item, CharacterInGroup receiver)
- {
- boundCharacter.inventory.items.Remove(item);
- receiver.inventory.items.Add(item);
- Refresh();
- }
- }
|