From f5e15fa93d84acbae6a26b86fddf20add38bb485 Mon Sep 17 00:00:00 2001 From: miepzerino <o.skotnik@gmail.com> Date: Tue, 01 Apr 2025 13:21:41 +0000 Subject: [PATCH] #31 added inventory to savefile, added itemDatabase --- Assets/Scripts/Inventory/Inventory.cs | 25 +++++++++++++++++++++++++ 1 files changed, 25 insertions(+), 0 deletions(-) diff --git a/Assets/Scripts/Inventory/Inventory.cs b/Assets/Scripts/Inventory/Inventory.cs index edb224e..f622519 100644 --- a/Assets/Scripts/Inventory/Inventory.cs +++ b/Assets/Scripts/Inventory/Inventory.cs @@ -1,3 +1,4 @@ +using System; using System.Collections; using System.Collections.Generic; using UnityEngine; @@ -18,6 +19,30 @@ { Destroy(gameObject); } + if (SaveSystem.isGameLoaded) + { + LoadInventory(); + } + } + + private void LoadInventory() + { + SaveDataPlayer save = SaveSystem.LoadPlayer(); + if (save != null) + { + foreach (SaveDataInventorySlot item in save.inventoryItems) + { + Item loadedItem = ItemDatabase.Instance.GetItem(item.itemId); + if (loadedItem != null) + { + items.Add(new InventorySlot(loadedItem, item.quantity)); + } + else + { + Debug.LogError($"Failed to load item with ID: {item.itemId}"); + } + } + } } public bool AddItem(Item item, int quantity = 1) -- Gitblit v1.9.3