miepzerino
2025-04-02 034ed30da10c2117e9c2507ed1fef3cab43ee79c
#36 load all items into itemDatabase on startup
3 files modified
2 files renamed
2 files added
55 ■■■■ changed files
Assets/Resources.meta 8 ●●●●● patch | view | raw | blame | history
Assets/Resources/Items.meta 8 ●●●●● patch | view | raw | blame | history
Assets/Resources/Items/IronOreItem.prefab patch | view | raw | blame | history
Assets/Resources/Items/IronOreItem.prefab.meta patch | view | raw | blame | history
Assets/Scenes/GameplayScene.unity 10 ●●●●● patch | view | raw | blame | history
Assets/Scripts/Inventory/ItemDatabase.cs 27 ●●●●● patch | view | raw | blame | history
Assets/TileSets/Palettes/DrillIronOre.prefab 2 ●●● patch | view | raw | blame | history
Assets/Resources.meta
New file
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 4ac220fd0e1536641a480531bbb38c65
folderAsset: yes
DefaultImporter:
  externalObjects: {}
  userData:
  assetBundleName:
  assetBundleVariant:
Assets/Resources/Items.meta
New file
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: dd3098fe15f11cf41b0623e380a01529
folderAsset: yes
DefaultImporter:
  externalObjects: {}
  userData:
  assetBundleName:
  assetBundleVariant:
Assets/Resources/Items/IronOreItem.prefab
Assets/Resources/Items/IronOreItem.prefab.meta
Assets/Scenes/GameplayScene.unity
@@ -697,7 +697,7 @@
  m_GameObject: {fileID: 519420028}
  serializedVersion: 2
  m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
  m_LocalPosition: {x: -6.15, y: -24.87, z: -10}
  m_LocalPosition: {x: 62, y: -22.89, z: -10}
  m_LocalScale: {x: 1, y: 1, z: 1}
  m_ConstrainProportionsScale: 0
  m_Children: []
@@ -2576,8 +2576,6 @@
  m_Script: {fileID: 11500000, guid: e4d1fabb0e4577b4d987741f664e3d68, type: 3}
  m_Name: 
  m_EditorClassIdentifier: 
  items:
  - {fileID: 7215668260114684477, guid: ead8eea59ce41c244814a994365e1129, type: 3}
--- !u!1 &1190838619
GameObject:
  m_ObjectHideFlags: 0
@@ -4186,7 +4184,7 @@
  m_GameObject: {fileID: 1624236510}
  serializedVersion: 2
  m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
  m_LocalPosition: {x: -6.15, y: -24.87, z: -10}
  m_LocalPosition: {x: 62, y: -22.89, z: -10}
  m_LocalScale: {x: 1, y: 1, z: 1}
  m_ConstrainProportionsScale: 0
  m_Children:
@@ -5743,11 +5741,11 @@
      objectReference: {fileID: 0}
    - target: {fileID: 2368348636056148999, guid: c220ec455fce341408d66d880b464cad, type: 3}
      propertyPath: m_LocalPosition.x
      value: -6.15
      value: 62
      objectReference: {fileID: 0}
    - target: {fileID: 2368348636056148999, guid: c220ec455fce341408d66d880b464cad, type: 3}
      propertyPath: m_LocalPosition.y
      value: -24.87
      value: -22.89
      objectReference: {fileID: 0}
    - target: {fileID: 2368348636056148999, guid: c220ec455fce341408d66d880b464cad, type: 3}
      propertyPath: m_LocalPosition.z
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();
Assets/TileSets/Palettes/DrillIronOre.prefab
@@ -76,7 +76,7 @@
  m_EditorClassIdentifier: 
  isGenerateable: 1
  weight: 7
  clusterWeight: 40
  clusterWeight: 30
  minClusterSize: 8
  tile: {fileID: 11400000, guid: bbc5a3964d8331546a4dbc880f8ae9fc, type: 2}
  maxSpawnHeight: 250