//从对象池取出 public void getObj(string url, Action <GameObject> callBack, E_PoolType pType) { if (!pools.ContainsKey(url)) { BasePool bp = new BasePool(url, pType); pools.Add(url, bp); } pools[url].getObj(callBack); }
/// <summary> /// 创建池 /// </summary> /// <param name="resName"></param> /// <param name="mode"></param> /// <param name="pType"></param> /// <param name="time"></param> private void createPool(string resName, E_PoolMode mode = E_PoolMode.Time, E_PoolType pType = E_PoolType.None, float time = 60) { if (!pools.ContainsKey(resName)) { string resPath = Path.Combine(Define.abPre, resName).ToLower(); BasePool p = PoolFactory.create(resName, resPath, mode, pType, time); pools.Add(resName, p); } }
private List <string> depends = new List <string>(); //依赖 public BasePool(string url, E_PoolType pt) { this.url = url; this.PType = pt; string name = "[{0}][{1}][{2}]"; name = string.Format(name, "root", pt.ToString(), url.ToString()); GameObject go = new GameObject(name); root = go.transform; ManifestMgr.getDepends(url, ref depends); root.SetParent(PoolMgr.Instance.PoolRoot); root.transform.localPosition = Vector3.zero; }
static int resGet(IntPtr L) { try { int count = LuaDLL.lua_gettop(L); if (count == 2) { string arg0 = ToLua.CheckString(L, 1); System.Action <UnityEngine.GameObject> arg1 = (System.Action <UnityEngine.GameObject>)ToLua.CheckDelegate <System.Action <UnityEngine.GameObject> >(L, 2); LuaExtend.resGet(arg0, arg1); return(0); } else if (count == 3) { string arg0 = ToLua.CheckString(L, 1); System.Action <UnityEngine.GameObject> arg1 = (System.Action <UnityEngine.GameObject>)ToLua.CheckDelegate <System.Action <UnityEngine.GameObject> >(L, 2); E_PoolMode arg2 = (E_PoolMode)ToLua.CheckObject(L, 3, typeof(E_PoolMode)); LuaExtend.resGet(arg0, arg1, arg2); return(0); } else if (count == 4) { string arg0 = ToLua.CheckString(L, 1); System.Action <UnityEngine.GameObject> arg1 = (System.Action <UnityEngine.GameObject>)ToLua.CheckDelegate <System.Action <UnityEngine.GameObject> >(L, 2); E_PoolMode arg2 = (E_PoolMode)ToLua.CheckObject(L, 3, typeof(E_PoolMode)); E_PoolType arg3 = (E_PoolType)ToLua.CheckObject(L, 4, typeof(E_PoolType)); LuaExtend.resGet(arg0, arg1, arg2, arg3); return(0); } else if (count == 5) { string arg0 = ToLua.CheckString(L, 1); System.Action <UnityEngine.GameObject> arg1 = (System.Action <UnityEngine.GameObject>)ToLua.CheckDelegate <System.Action <UnityEngine.GameObject> >(L, 2); E_PoolMode arg2 = (E_PoolMode)ToLua.CheckObject(L, 3, typeof(E_PoolMode)); E_PoolType arg3 = (E_PoolType)ToLua.CheckObject(L, 4, typeof(E_PoolType)); float arg4 = (float)LuaDLL.luaL_checknumber(L, 5); LuaExtend.resGet(arg0, arg1, arg2, arg3, arg4); return(0); } else { return(LuaDLL.luaL_throw(L, "invalid arguments to method: LuaExtend.resGet")); } } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
public BasePool(string resName, string resPath, E_PoolMode mode, E_PoolType pType, float time) { this.resName = resName; this.resPath = resPath; pMode = mode; this.pType = pType; lifeTime = time; string poolName = string.Format("[{0}][{1}][{2}]", mode.ToString(), pType.ToString(), resName); GameObject go = new GameObject(poolName); this.poolRoot = go.transform; this.poolRoot.SetParent(PoolMgr.Instance.PoolRoot); this.poolRoot.transform.localPosition = Vector3.zero; initialize(); }
public static BasePool create(string resName, string resPath, E_PoolMode mode, E_PoolType pType, float time) { BasePool p = null; switch (pType) { case E_PoolType.UICache: p = new UICachePool(resName, resPath, mode, pType, time); break; case E_PoolType.Atlas: p = new AtlasPool(resName, resPath, mode, pType, time); break; case E_PoolType.Model: p = new ModelPool(resName, resPath, mode, pType, time); break; default: p = new BasePool(resName, resPath, mode, pType, time); break; } return(p); }
private void OnGUI() { //释放所有ab if (GUILayout.Button("释放所有ab")) { AssetMgr.dispose(true); } //释放所有池子 if (GUILayout.Button("释放所有池子")) { PoolMgr.Instance.onDispose(); } //释放一个池子 if (GUILayout.Button("释放一个池子")) { if (roleObj != null) { string resName = roleObj.GetComponent <PoolObj>().resName; PoolMgr.Instance.disposePool(resName); UnityEngine.Debug.LogError("释放池子 " + resName); } } //创建一个模型 if (GUILayout.Button("创建一个模型")) { //watch.Start(); string role = "AssetBundle/Prefabs/model/role_ueman/model/role_ueman"; UnityEngine.Debug.LogError("加载role_ueman"); PoolMgr.Instance.getObj(role, onLoadUEManFinish); //UnityEngine.Debug.LogError("取消加载role_ueman"); //PoolMgr.Instance.unLoad(role, onLoadUEManFinish); } //回收一个模型 if (GUILayout.Button("回收一个模型")) { PoolMgr.Instance.recyleObj(roleObj); } //设置img的sprite if (GUILayout.Button("设置img的sprite")) { if (img != null) { string spName = "CZ_5".ToLower(); PoolMgr.Instance.getObj(spName, (sp, resName) => { img.sprite = sp; }); } else { UnityEngine.Debug.LogError("img == null "); } } //预加载模型 if (GUILayout.Button("预加载")) { watch.Start(); foreach (var item in preLoads) { E_PoolType pType = item.Key; int cacheCount = pType == E_PoolType.Model ? 3 : pType == E_PoolType.UICache ? 2 : 0; for (int i = 0; i < item.Value.Count; i++) { PoolMgr.Instance.preLoad(item.Value[i], preLoadCount, E_PoolMode.Overall, pType, cacheCount); } } } //打开技能UI if (GUILayout.Button("打开技能UI")) { string uiName = "assetbundle/prefabs/ui/BottomSkillUI"; PoolMgr.Instance.getObj(uiName, onLoadSkillUIFinish); } }
/// <summary> /// 预创建池子 /// 可能在进入场景的时候需要预加载一些gameobject或者load一些bundle /// </summary> /// <param name="resName"></param> /// <param name="callBack"></param> /// <param name="mode"></param> /// <param name="pType"></param> /// <param name="preLoadCount"></param> 初始化个数 /// <param name="time"></param> public void preLoad(string resName, Action <string> callBack, E_PoolMode mode, E_PoolType pType, int preLoadCount = 0, float time = 60) { resName = resName.ToLower(); createPool(resName, mode, pType, time); pools[resName].preLoad(callBack, preLoadCount); }
//获取Sprite public void getObj(string spName, Action <Sprite> callBack, E_PoolMode mode = E_PoolMode.Time, E_PoolType pType = E_PoolType.Atlas, float time = 60) { if (AtlasMgr.hasKey(spName)) { string resName = AtlasMgr.getName(spName); createPool(resName, mode, pType, time); pools[resName].getObj(spName, callBack); } else { Debug.LogError("没有找到bundle名称 spName " + spName); } }
//获取gameObject public void getObj(string resName, Action <GameObject> callBack, E_PoolMode mode = E_PoolMode.Time, E_PoolType pType = E_PoolType.None, float time = 60) { resName = resName.ToLower(); createPool(resName, mode, pType, time); pools[resName].getObj(callBack); }
public BaseGameObjPool(string resName, string resPath, E_PoolMode mode, E_PoolType pType, float time) : base(resName, resPath, mode, pType, time) { }
public static void setSprite(string spName, Action <Sprite, string> callBack, E_PoolMode mode = E_PoolMode.Time, E_PoolType pType = E_PoolType.Atlas, float time = 60) { PoolMgr.Instance.getObj(spName, callBack, mode, pType, time); }
public static void resGet(string resName, Action <GameObject> callBack, E_PoolMode mode = E_PoolMode.Time, E_PoolType pType = E_PoolType.None, float time = 60) { PoolMgr.Instance.getObj(resName, callBack, mode, pType, time); }
public UICachePool(string resName, string resPath, E_PoolMode mode, E_PoolType pType, float time) : base(resName, resPath, mode, pType, time) { }
//需要再封装一层 提供完整url PoolType public void getObj(string url, Action <GameObject> callBack, E_PoolType pType = E_PoolType.UseTime) { PoolMgr.Instance.getObj(url, callBack, pType); }