using UnityEngine; public class ResourceManager { public T Load(string path) where T : Object { if(typeof(T) == typeof(GameObject)) { string name = path; int index = name.LastIndexOf('/'); if (index >= 0) { name = name.Substring(index + 1); } GameObject go = Managers.Pool.GetOriginal(name); if (go != null) { return go as T; } } return Resources.Load(path); } public GameObject Instantiate(string path, Transform parent = null) { GameObject original = Load($"Prefabs/{path}"); if (original == null) { Debug.Log($"Failed to load prefab : {path}"); return null; } if (original.GetComponent() != null) { return Managers.Pool.Pop(original, parent).gameObject; } GameObject go = Object.Instantiate(original, parent); go.name = original.name; return go; } public void Destroy(GameObject go) { if (go == null) { return; } Poolable poolable = go.GetComponent(); if (poolable != null) { Managers.Pool.Push(poolable); return; } Object.Destroy(go); } }