public GameObject GetObject() { GameObject ret = null; ResShell shell = null; if (m_unusedShells.Count == 0) { ret = GameObject.Instantiate(this.res); ToolHelper.IdentityLocalTransform(ret.transform); shell = new ResShell(ret); int id = ret.GetInstanceID(); m_shells[id] = shell; Debug.LogWarning("object pool instantiate a obj in RUNTIME named : " + this.res); } else { shell = m_unusedShells.First.Value; ret = shell.res; m_unusedShells.RemoveFirst(); } ret.transform.SetParent(null); ret.SetActive(true); if (shell.trail != null) { shell.trail.Clear(); } return(ret); }
public ResShell GetResShell() { ResShell shell = null; if (m_unusedShells.Count == 0) { var res = GameObject.Instantiate(this.res); ToolHelper.IdentityLocalTransform(res.transform); shell = new ResShell(res); int id = res.GetInstanceID(); m_shells[id] = shell; } else { shell = m_unusedShells.First.Value; m_unusedShells.RemoveFirst(); } shell.res.transform.SetParent(null); shell.res.SetActive(true); if (shell.trail != null) { shell.trail.Clear(); } return(shell); }
public void AddObject(int count) { if (this.res == null) { Debug.LogWarning("object pool add object failed cause res : " + this.resPath + " is NULL.."); return; } for (int i = 0; i < count; i++) { var item = GameObject.Instantiate(this.res); ToolHelper.IdentityLocalTransform(item.transform); item.SetActive(false); item.transform.SetParent(this.root); var shell = new ResShell(item); int id = item.GetInstanceID(); m_shells[id] = shell; m_unusedShells.AddLast(shell); } }