public override void getObj(string name, Action <Sprite, string> callBack, bool forceRemove = false) { //bundle池有 if (AssetMgr.has(resName)) { PackAsset pab = AssetMgr.get(resName); pab.getObj <Sprite>(name, callBack); } else { if (forceRemove) { Debug.LogError("加载资源失败 path " + resName); } else { if (!handler.ContainsKey(name)) { handler.Add(name, new List <Action <Sprite, string> >()); } handler[name].Add(callBack); LoadItemMgr.add(resName, resPath, loadFinish); } } }
//预加载 public virtual void preLoad(Action <string> preLoad, int preLoadCount = 0) { this.preLoadCount = preLoadCount; this.preLoadHandler = preLoad; if (!AssetMgr.has(resName)) { if (cacheLst != null && cacheLst.Count > 0) { Debug.LogError("预创建错误 gameobject池子有缓存 但是assetbundle已经不存在(可能造成预设资源丢失)"); } LoadItemMgr.add(resName, resPath, onPerCreate); } else { onPerCreate(resName); } }
//销毁池 public virtual void onDispose() { LoadItemMgr.remove(resName, loadFinish); if (cacheLst != null) { int count = cacheLst.Count; //释放静态引用 if (count > 0) { for (int i = 0; i < deps.Count; i++) { AssetMgr.subRef(deps[i], count); } AssetMgr.subRef(resName, count); } //释放动态引用 for (int i = 0; i < cacheLst.Count; i++) { PoolObj po = cacheLst[i].GetComponent <PoolObj>(); if (po.getDepsNum() > 0) { List <string> dyDeps = po.getDeps(); for (int j = 0; j < dyDeps.Count; j++) { AssetMgr.subRef(dyDeps[i]); } } } //销毁gameobject for (int i = 0; i < cacheLst.Count; i++) { GameObject.Destroy(cacheLst[i]); } cacheLst.Clear(); cacheLst = null; } if (deps != null) { deps.Clear(); deps = null; } GameObject.Destroy(this.poolRoot.gameObject); }
public virtual void getObj(Action <GameObject> callBack, bool forceRemove = false, int count = 0) { if (cacheLst.Count > count) { //缓存池有 GameObject obj = cacheLst[0]; cacheLst.RemoveAt(0); obj.transform.SetParent(null); callBack(obj); } else { //bundle池有 if (AssetMgr.has(resName)) { PackAsset pab = AssetMgr.get(resName); pab.getObj(callBack); } else { if (forceRemove) { Debug.LogError("加载资源失败 path " + resName); } else { //都没有 先load ab if (handler == null) { handler = new List <Action <GameObject> >(); } handler.Add(callBack); LoadItemMgr.add(resName, resPath, loadFinish); } } } }