miepzerino
2025-04-02 034ed30da10c2117e9c2507ed1fef3cab43ee79c
Assets/Scripts/Inventory/ItemDatabase.cs
@@ -5,9 +5,7 @@
{
    public static ItemDatabase Instance { get; private set; }
    [SerializeField]
    private List<Item> items = new List<Item>();
    private Dictionary<string, Item> itemDictionary = new Dictionary<string, Item>();
    private Dictionary<int, Item> itemIdDictionary = new Dictionary<int, Item>();
@@ -16,6 +14,7 @@
        if (Instance == null)
        {
            Instance = this;
            LoadItemsFromResources();
            InitializeItemDictionary();
        }
        else
@@ -24,6 +23,30 @@
        }
    }
    private void LoadItemsFromResources()
    {
        // Load all Item prefabs from the "Resources/Items" folder
        GameObject[] itemPrefabs = Resources.LoadAll<GameObject>("Items");
        foreach (GameObject prefab in itemPrefabs)
        {
            Item item = prefab.GetComponent<Item>();
            if (item != null)
            {
                items.Add(item);
            }
            else
            {
                Debug.LogWarning($"Prefab {prefab.name} does not have an Item component");
            }
        }
        if (items.Count == 0)
        {
            Debug.LogWarning("No items found in Resources/Items folder");
        }
    }
    private void InitializeItemDictionary()
    {
        itemDictionary.Clear();