miepzerino
2025-04-02 d4552adc9ec0998725e663c47114e6836061ad2c
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using Assets.Scripts.Helpers;
using System;
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;
                    UIHelper.UpdateItemMaxCountText(gameObject.transform.Find("ItemQuantity").GetComponent<TextMeshProUGUI>(), inventorySlot.quantity, inventorySlot.item.maxStackSize);
                    break;
                case ItemUIType.ItemDescription:
                    string description = $"<b>Description</b>\n{inventorySlot.item.itemDescription}\n";
 
                    GenerateableDatabase.Instance.TryGetGenerateables(inventorySlot.item.itemId, out var variants);
                    if (variants != null)
                    {
                        description += $"\n<b>Generation</b>";
                        foreach (var variant in variants)
                        {
                            if (variant.maxHeight > 0 || variant.minHeight > 0)
                            {
                                description += $"\nSpawns between Y: {variant.minHeight} - {variant.maxHeight}. Amount: {variant.dropRange}";
                            }
                        }
                    }
                    gameObject.transform.Find("ItemTextDescription").GetComponent<TextMeshProUGUI>().text = description;
                    break;
            }
        }
    }
    private void OnDestroy()
    {
        gameObject.GetComponent<Button>()?.onClick?.RemoveAllListeners();
    }
}