/// <summary> /// Create a new object. /// </summary> public GameObject Create() { if (mTemplate == null) { mTemplate = Resources.Load(mPath) as GameObject; if (mTemplate == null) { Debug.LogError("[" + typeof(MyPool).Name + "] Create(): Could not find file \"" + mPath + "\""); return(null); } } GameObject newObj = GameObject.Instantiate(mTemplate); newObj.SetActive(true); newObj.name = mObjectName; newObj.transform.SetParent(mOccupied.transform, false); MyPooledObject poolObject = newObj.GetComponent <MyPooledObject>(); if (poolObject == null) { poolObject = newObj.AddComponent <MyPooledObject>(); } poolObject.SetPool(mPath); mListOccupiedObject.Add(newObj); return(newObj); }
/// <summary> /// Add an object back into the pool. /// </summary> public void Return(GameObject obj) { if (obj != null) { MyPooledObject poolObject = obj.GetComponent <MyPooledObject>(); if (poolObject != null) { if (mDictPooler.ContainsKey(poolObject.Pool)) { mDictPooler[poolObject.Pool].Return(obj); } } } }