From 034ed30da10c2117e9c2507ed1fef3cab43ee79c Mon Sep 17 00:00:00 2001
From: miepzerino <o.skotnik@gmail.com>
Date: Wed, 02 Apr 2025 08:56:56 +0000
Subject: [PATCH] #36 load all items into itemDatabase on startup
---
Assets/Resources.meta | 8 ++++++++
Assets/Scripts/Inventory/ItemDatabase.cs | 27 +++++++++++++++++++++++++--
Assets/Resources/Items/IronOreItem.prefab.meta | 0
Assets/Resources/Items.meta | 8 ++++++++
Assets/Scenes/GameplayScene.unity | 10 ++++------
Assets/Resources/Items/IronOreItem.prefab | 0
Assets/TileSets/Palettes/DrillIronOre.prefab | 2 +-
7 files changed, 46 insertions(+), 9 deletions(-)
diff --git a/Assets/Resources.meta b/Assets/Resources.meta
new file mode 100644
index 0000000..09c3897
--- /dev/null
+++ b/Assets/Resources.meta
@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: 4ac220fd0e1536641a480531bbb38c65
+folderAsset: yes
+DefaultImporter:
+ externalObjects: {}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Resources/Items.meta b/Assets/Resources/Items.meta
new file mode 100644
index 0000000..78101c4
--- /dev/null
+++ b/Assets/Resources/Items.meta
@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: dd3098fe15f11cf41b0623e380a01529
+folderAsset: yes
+DefaultImporter:
+ externalObjects: {}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Prefabs/Ore/IronOreItem.prefab b/Assets/Resources/Items/IronOreItem.prefab
similarity index 100%
rename from Assets/Prefabs/Ore/IronOreItem.prefab
rename to Assets/Resources/Items/IronOreItem.prefab
diff --git a/Assets/Prefabs/Ore/IronOreItem.prefab.meta b/Assets/Resources/Items/IronOreItem.prefab.meta
similarity index 100%
rename from Assets/Prefabs/Ore/IronOreItem.prefab.meta
rename to Assets/Resources/Items/IronOreItem.prefab.meta
diff --git a/Assets/Scenes/GameplayScene.unity b/Assets/Scenes/GameplayScene.unity
index e90f5a2..6d5aa06 100644
--- a/Assets/Scenes/GameplayScene.unity
+++ b/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
diff --git a/Assets/Scripts/Inventory/ItemDatabase.cs b/Assets/Scripts/Inventory/ItemDatabase.cs
index c0a0067..b4832cb 100644
--- a/Assets/Scripts/Inventory/ItemDatabase.cs
+++ b/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();
diff --git a/Assets/TileSets/Palettes/DrillIronOre.prefab b/Assets/TileSets/Palettes/DrillIronOre.prefab
index c94273e..5f06d3b 100644
--- a/Assets/TileSets/Palettes/DrillIronOre.prefab
+++ b/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
--
Gitblit v1.10.0