public void Recycle(GameObject go) { if (go == null) { return; } m_Strategy.OnRecycle(go); PoolObjectReset itemComponent = go.GetComponent <PoolObjectReset>(); if (itemComponent != null) { itemComponent.OnReset2Cache(); } if (m_MaxCount > 0) { if (m_CacheStack.Count >= m_MaxCount) { GameObject.Destroy(go); return; } } if (go.GetComponent <ICacheAble>() != null) { go.GetComponent <ICacheAble>().cacheFlag = true; go.GetComponent <ICacheAble>().OnCacheReset(); } go.transform.SetParent(m_Root, true); go.SetActive(false); //某些情况不需要处理这步 m_CacheStack.Push(go); }
public void Recycle(GameObject t) { if (t == null) { return; } if (m_CacheStack == null) { m_CacheStack = new Stack <GameObject>(); } else if (m_MaxCount > 0) { if (m_CacheStack.Count >= m_MaxCount) { PoolObjectComponent comItem = t.GetComponent <PoolObjectComponent>(); if (comItem != null) { comItem.OnReset2Cache(); } GameObject.Destroy(t); return; } } t.transform.SetParent(m_Root, true); m_Strategy.OnRecycle(t); m_CacheStack.Push(t); PoolObjectComponent item = t.GetComponent <PoolObjectComponent>(); if (item != null) { item.OnReset2Cache(); } //是否处理active false }