public void UnLoadRes(string path) { if (!AllResItems.ContainsKey(path)) { return; } var refs = AllResItems[path].resRefs; for (int i = 0; i < refs.Count; i++) { if (refs[i].IsAlive) { Debug.LogError("该资源还有引用--->" + path); return; } } Resources.UnloadAsset(AllResItems[path].Res); }
// 载入资源并带有一个弱引用 public T LoadRes <T>(UnityEngine.Object resRef, string path) where T : UnityEngine.Object { if (AllResItems.ContainsKey(path)) { if (resRef != null) { AllResItems[path].AddRef(resRef); } return(AllResItems[path] as T); } T tmp = Resources.Load <T>(path); var res = new ResItem(); res.Res = tmp; if (resRef != null) { res.AddRef(resRef); } AllResItems[path] = res; return(tmp); }