public void OnInit() { m_isInPool = false; #if !ART_DEBUG m_soundCfg = FxSoundCfg.Get(this.gameObject.name); #endif }
//复制游戏对象到对象池,注意对象池是靠对象名字识别的,如果预制体名和对象名不同可能会出现异常 //addIfNo = true,如果有了就不要预加载了 public void PreLoad(GameObject go, bool addIfNo = true) { if (go == null) { Debuger.LogError("预制体为空?不能放入对象池"); return; } //删除后缀 string name = go.name; int idx = name.IndexOf(" ("); if (idx != -1) { name = name.Substring(0, idx - 1); } idx = name.IndexOf(" ("); if (idx != -1) { name = name.Substring(0, idx - 1); } //已经有了就不用预加载了 LinkedList <GameObjectPoolObject> l = m_pools.GetNewIfNo(name); if (l.Count > 0 && addIfNo) { return; } //增加到对象池 s_isPreloading = true; GameObject goNew = GameObject.Instantiate(go); s_isPreloading = false; goNew.name = name; GameObjectPoolObject poolObj = goNew.AddComponentIfNoExist <GameObjectPoolObject>(); poolObj.OnInit(); Put(l, poolObj); ++m_counter;//每Instantiate一个计数下,用于检查泄露 //预加载对应的音效 #if !ART_DEBUG if (m_poolType == enPool.Fx) { FxSoundCfg.PreLoad(name); } #endif }
public void PreLoad(string name, bool checkPreLoading = true) { LinkedList <GameObjectPoolObject> l = m_pools.Get(name); //已经加载过的 if (l != null) { return; } //正在加载中的 PoolRequests poolReqs = m_requests.Get(name); if (poolReqs != null) { return; } if (string.IsNullOrEmpty(name)) { Debuger.LogError("预加载的时候传进来空的资源名"); return; } if (checkPreLoading && !s_checkPreLoading) { Debuger.LogError("PutPrefab.没有在预加载期间加载资源:{0}", name); } //没有加载过的 ResourceRequest resReq = Resources.LoadAsync <GameObject>(name); poolReqs = new PoolRequests(this, name, resReq); m_requests[name] = poolReqs; //预加载对应的音效 #if !ART_DEBUG if (m_poolType == enPool.Fx) { FxSoundCfg.PreLoad(name); } #endif }