miepzerino
2025-03-31 b55bc192f403826120d4721630934f27e028edba
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using static UnityEditor.Progress;
 
public enum ItemUIType
{
    ItemNameDescription,
    ItemDescription
}
 
public class ItemUIScript : MonoBehaviour
{
    private InventorySlot inventorySlot;
 
    public ItemUIType itemUIType;
 
    public InventorySlot InventorySlot
    { 
        get => inventorySlot;
        set
        {
            inventorySlot = value;
            switch (itemUIType)
            {
                case ItemUIType.ItemNameDescription:
                    gameObject.transform.Find("ItemName").GetComponent<TextMeshProUGUI>().text = inventorySlot.item.itemName;
                    gameObject.transform.Find("ItemQuantity").GetComponent<TextMeshProUGUI>().text = inventorySlot.quantity.ToString() + "x";
                    gameObject.transform.Find("ItemIcon").GetComponent<Image>().sprite = inventorySlot.item.itemIcon;
                    break;
                case ItemUIType.ItemDescription:
                    gameObject.transform.Find("ItemTextDescription").GetComponent<TextMeshProUGUI>().text = inventorySlot.item.itemDescription;
                    break;
            }
        }
    }
    private void OnDestroy()
    {
        gameObject.GetComponent<Button>()?.onClick?.RemoveAllListeners();
    }
}