using System.Collections; using System.Collections.Generic; using System.IO; using UnityEngine; using Noah; namespace Noah { public class ResourceManager { public Dictionary _sprites = new Dictionary(); public void Init() { } public T Load(string path) where T : Object { if (typeof(T) == typeof(Sprite)) { if (_sprites.TryGetValue(path, out Sprite sprite)) return sprite as T; Sprite sp = Resources.Load(path); _sprites.Add(path, sp); return sp as T; } return Resources.Load(path); } public GameObject Instantiate(string path, Transform parent = null) { GameObject prefab = Load($"Prefabs/{path}"); if (prefab == null) { Debug.Log($"Failed to load prefab : {path}"); return null; } return Instantiate(prefab, parent); } public GameObject Instantiate(GameObject prefab, Transform parent = null) { GameObject go = Object.Instantiate(prefab, parent); go.name = prefab.name; return go; } public void Destroy(GameObject go) { if (go == null) return; Object.Destroy(go); } } }