| | |
| | | { |
| | | 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>(); |
| | | |
| | |
| | | if (Instance == null) |
| | | { |
| | | Instance = this; |
| | | LoadItemsFromResources(); |
| | | InitializeItemDictionary(); |
| | | } |
| | | else |
| | |
| | | } |
| | | } |
| | | |
| | | 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(); |