Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections.Generic;
- public class StorageSystem : MonoBehaviour
- {
- public static StorageSystem Instance { get; private set; }
- private Dictionary<Item, List<Item>> storageInventories = new Dictionary<Item, List<Item>>();
- private InventorySystem inventorySystem;
- private UIManager uiManager;
- private void Awake()
- {
- if (Instance == null)
- {
- Instance = this;
- DontDestroyOnLoad(gameObject);
- }
- else
- {
- Destroy(gameObject);
- }
- }
- private void Start()
- {
- inventorySystem = InventorySystem.Instance;
- uiManager = UIManager.Instance;
- if (uiManager == null)
- {
- Debug.LogError("Failed to find UIManager instance");
- }
- }
- public void OpenStorage(Item storageItem)
- {
- if (uiManager == null)
- {
- Debug.LogError("UIManager reference is null in StorageSystem");
- return;
- }
- if (storageItem == null)
- {
- Debug.LogError("Attempted to open storage for a null item");
- return;
- }
- uiManager.ShowInventoryPrompt(storageItem);
- }
- public void AddItemToStorage(Item storageItem, Item itemToStore)
- {
- if (!storageInventories.ContainsKey(storageItem))
- {
- storageInventories[storageItem] = new List<Item>();
- }
- storageInventories[storageItem].Add(itemToStore);
- }
- public List<Item> GetStorageInventory(Item storageItem)
- {
- if (storageInventories.TryGetValue(storageItem, out List<Item> items))
- {
- return items;
- }
- return new List<Item>();
- }
- public void RemoveItemFromStorage(Item storageItem, Item itemToRemove)
- {
- if (storageInventories.TryGetValue(storageItem, out List<Item> items))
- {
- items.Remove(itemToRemove);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement