public CharObj BorrowObj(BattleObjManager.E_BATTLE_OBJECT_TYPE type) { CharObj obj = null; QObjPool <CharObj> pool = null; m_pools.TryGetValue(type, out pool); if (pool == null) { InitBattleObjPool( CharObjPoolConfigerMediator.Instance.GetConfiger(type).Paths, type, CharObjPoolConfigerMediator.Instance.GetConfiger(type).Count); m_pools.TryGetValue(type, out pool); //return obj; } if (pool == null) { return(obj); } obj = pool.BorrowObj(); return(obj); }
/// <summary> /// </summary> /// <param name="path"> /// path[0] meshbaker生成器资源路径 /// path[1] meshbaker材质资源路径 /// path[2] meshbaker贴图资源路径 /// path[3] meshbaker合并对象资源路径 /// </param> /// <param name="type"></param> /// <param name="count"></param> public CharObjCreator(string[] paths, BattleObjManager.E_BATTLE_OBJECT_TYPE type, int count) { bool retCode = false; m_meshbakerGo = ResourcesManagerMediator. GetGameObjectFromResourcesManager(paths[0]); if (m_meshbakerGo == null) { Debug.LogError("加载baker生成器资源出错" + paths[0]); return; } MB3_TextureBaker textureBaker = m_meshbakerGo.GetComponent <MB3_TextureBaker>(); m_meshBaker = m_meshbakerGo.GetComponentInChildren <MB3_MeshBaker>(); retCode = InitBaker(paths, textureBaker, m_meshBaker); if (!retCode) { Debug.LogError("MeshBaker初始化失败"); return; } m_seed = ResourcesManagerMediator.GetGameObjectFromResourcesManager(paths[3]); if (m_seed == null) { Debug.LogError("加载种子资源失败 " + paths[3]); return; } m_seed.transform.position = INIT_POS; m_count = count; }
private void AddOneConfig(BattleObjManager.E_BATTLE_OBJECT_TYPE type, int count, string[] paths) { CharObjPoolConfiger cfg = new CharObjPoolConfiger(count, paths); m_cfgs.Add(type, cfg); }
private void InitBattleObjPool(string[] paths, BattleObjManager.E_BATTLE_OBJECT_TYPE type, int count) { QObjCreatorFactory <CharObj> creatorFactory = new CharObjCreatorFactory( paths, type, count); QObjPool <CharObj> pool = new QObjPool <CharObj>(); pool.Init(null, creatorFactory); m_pools.Add(type, pool); }
public CharObjPoolConfiger GetConfiger(BattleObjManager.E_BATTLE_OBJECT_TYPE type) { CharObjPoolConfiger cfg = null; m_cfgs.TryGetValue(type, out cfg); if (cfg == null) { Debug.LogError("没有这类对象的pool参数 " + type.ToString()); } return(cfg); }
/// <summary> /// 在场景取一个对象必须是已知类型,服务器的两个编号的 /// </summary> /// <param name="type"></param> /// <param name="serverEntityID"></param> /// <param name="serverEntityType">暂时冗余参数,目前暂时全部填0</param> /// <returns></returns> public CharObj BorrowCharObj(BattleObjManager.E_BATTLE_OBJECT_TYPE type, int serverEntityID, int serverEntityType) { bool retCode = false; CharObj obj = null; //Debug.Log("BorrowCharObj " + serverEntityID); //先从缓存中取 obj = CharObjCache.Instance.Find(serverEntityID); if (obj != null) { //Debug.Log("缓存中找到 " + serverEntityID); //obj.Deactive(); return(obj); } //缓存中没有才从对象池中取 obj = CharObjPoolManager.Instance.BorrowObj(type); if (obj == null) { Debug.LogError("CharObjPoolManager.Instance.BorrowObj 取到空Obj " + type.ToString()); return(obj); } //retCode = obj.IsValid(); //if (!retCode) //{ // Debug.LogError("取到CharObj非法,请联系BattleObjManager作者"); // return obj; //} //为CharObj打上身份证号:) obj.ServerEntityID = serverEntityID; obj.Type = type; //obj.CharController.ServerEntityID = serverEntityID; //obj.CharController.CharType = type; //Debug.Log(type.ToString()); //从对象池中取出的对象要放入缓存中 CharObjCache.Instance.Add(obj); return(obj); }
/// <summary> /// </summary> /// <param name="path"> /// path[0] meshbaker生成器资源路径 /// path[1] meshbaker材质资源路径 /// path[2] meshbaker贴图资源路径 /// path[3] meshbaker合并对象资源路径 /// </param> /// <param name="type"></param> /// <param name="count"></param> public CharObjCreatorFactory(string[] paths, BattleObjManager.E_BATTLE_OBJECT_TYPE type, int count) { m_paths = paths; m_type = type; m_count = count; }