68 lines
1.6 KiB
C#
68 lines
1.6 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
|
|
// GameItemManager.cs
|
|
// Responsible for managing the game items
|
|
public class GameItemManager : MonoBehaviour
|
|
{
|
|
public static GameItemManager Instance;
|
|
public List<GameItem> gameItems = new();
|
|
|
|
private void Awake()
|
|
{
|
|
if (Instance == null)
|
|
{
|
|
Instance = this;
|
|
DontDestroyOnLoad(gameObject);
|
|
}
|
|
else
|
|
{
|
|
Destroy(gameObject);
|
|
}
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
Debug.Log("GameItem Manager Start");
|
|
InitializeGameItems();
|
|
}
|
|
|
|
|
|
public void AddItem(GameItem item)
|
|
{
|
|
var clone = Instantiate(item);
|
|
gameItems.Add(item);
|
|
Debug.Log("Added item: " + item.itemName);
|
|
}
|
|
|
|
public void RemoveItem(GameItem item)
|
|
{
|
|
gameItems.Remove(item);
|
|
Debug.Log("Removed item: " + item.itemName);
|
|
}
|
|
|
|
|
|
public GameItem GetRandomItem()
|
|
{
|
|
var clone = Instantiate(gameItems[Random.Range(0, gameItems.Count - 1)]);
|
|
return clone;
|
|
}
|
|
|
|
public GameItem GetRandomCategoryItem(GameItem.ItemType itemType)
|
|
{
|
|
var items = gameItems.FindAll(item => item.type == itemType);
|
|
|
|
return Instantiate(items[Random.Range(0, items.Count - 1)]);
|
|
}
|
|
|
|
public void InitializeGameItems()
|
|
{
|
|
// Add predefined items to the inventory list
|
|
// Example items (replace with your actual items)
|
|
Debug.Log("Initializing items from Resources/GameItems");
|
|
var items = Resources.LoadAll<GameItem>("GameItems");
|
|
|
|
foreach (var item in items) AddItem(item);
|
|
}
|
|
} |