91 lines
2.2 KiB
C#
91 lines
2.2 KiB
C#
using Components.Grid;
|
|
using UnityEngine;
|
|
using Utils;
|
|
|
|
public class PrefabManager : MonoBehaviour
|
|
{
|
|
public static PrefabManager Instance;
|
|
public GameObject slotPrefab;
|
|
public GameObject itemPrefab;
|
|
public GameObject hotkeyEntryPrefab;
|
|
public GameObject tilePrefab;
|
|
public GameObject cropPrefab;
|
|
public Object interactablePrefab;
|
|
|
|
public GameObject[] cropPrefabs;
|
|
public GameObject[] treePrefabs;
|
|
public GameObject[] rockPrefabs;
|
|
public GameObject[] boxPrefabs;
|
|
public GameObject[] bushPrefabs;
|
|
|
|
private void Awake()
|
|
{
|
|
GameLogger.Log("PrefabManager Awake");
|
|
if (Instance == null)
|
|
{
|
|
Instance = this;
|
|
DontDestroyOnLoad(gameObject);
|
|
LoadCropPrefabs();
|
|
}
|
|
else
|
|
{
|
|
Destroy(gameObject);
|
|
}
|
|
}
|
|
|
|
private void LoadCropPrefabs()
|
|
{
|
|
cropPrefabs = Resources.LoadAll<GameObject>("Prefabs/Interactable/Crops");
|
|
GameLogger.Log("Loaded " + cropPrefabs.Length + " crop prefabs");
|
|
}
|
|
|
|
public GameObject GetSlotPrefab()
|
|
{
|
|
GameLogger.Log("Getting Slot Pefab");
|
|
if (slotPrefab == null) GameLogger.LogWarning("SlotPrefab is null");
|
|
return slotPrefab;
|
|
}
|
|
|
|
public GameObject GetHotkeyEntryPrefab()
|
|
{
|
|
GameLogger.Log("Getting HotkeyEntry Pefab");
|
|
if (hotkeyEntryPrefab == null) GameLogger.LogWarning("HotkeyEntryPrefab is null");
|
|
return hotkeyEntryPrefab;
|
|
}
|
|
|
|
public GameObject GetItemPrefab()
|
|
{
|
|
return itemPrefab;
|
|
}
|
|
|
|
public GameObject GetTilePrefab()
|
|
{
|
|
return tilePrefab;
|
|
}
|
|
|
|
public GameObject GetCropPrefab()
|
|
{
|
|
return cropPrefab;
|
|
}
|
|
|
|
public Object GetInteractablePrefab()
|
|
{
|
|
return interactablePrefab;
|
|
}
|
|
|
|
public GameObject GetRandomCropPrefabInstance()
|
|
{
|
|
var randomIndex = Random.Range(0, cropPrefabs.Length - 1);
|
|
|
|
var crop = Instantiate(cropPrefabs[randomIndex]);
|
|
|
|
// get new
|
|
|
|
var cropInteractable = crop.GetComponent<CropInteractiveComponent>();
|
|
|
|
cropInteractable.Initialize();
|
|
|
|
GameLogger.Log("Crop Prefab Instance initialized");
|
|
return crop;
|
|
}
|
|
} |