// pool public GObject GetEntity(GObject.ObjectType oType) { GObject gobj = GetFromPool(oType); if (gobj != null) { gobj.gameObject.SetActive(true); return(gobj); } else { GameObject gameObject = null; switch (oType) { case GObject.ObjectType.SwimmerStatic: gameObject = GameObject.Instantiate(m_SwimmerStatic, Vector3.zero, Quaternion.identity); break; case GObject.ObjectType.Swimmer: gameObject = GameObject.Instantiate(m_Swimmer, Vector3.zero, Quaternion.identity); break; case GObject.ObjectType.Mine: gameObject = GameObject.Instantiate(m_Mine, Vector3.zero, Quaternion.identity); break; } if (gameObject != null) { gobj = gameObject.GetComponent <GObject>(); } } return(gobj); }
GObject GetFromPool(GObject.ObjectType oType) { int index = -1; for (int i = 0; i < m_ObjectsInPool.Count; i++) { if (m_ObjectsInPool[i].m_ObjectType == oType) { index = i; break; } } if (index >= 0) { GObject gobj = m_ObjectsInPool[index]; m_ObjectsInPool.RemoveAt(index); return(gobj); } return(null); }
// pool public GObject GetEntity(GObject.ObjectType oType) { GObject gobj = GetFromPool(oType); if (gobj != null) { gobj.gameObject.SetActive(true); gobj.m_PhysBody.Activate(); return(gobj); } else { GameObject gameObject = null; switch (oType) { case GObject.ObjectType.Enemy: gameObject = GameObject.Instantiate(m_Enemy, Vector3.zero, Quaternion.identity); break; case GObject.ObjectType.Ball: gameObject = GameObject.Instantiate(m_Ball, Vector3.zero, Quaternion.identity); break; case GObject.ObjectType.Bonus: gameObject = GameObject.Instantiate(m_Bonus, Vector3.zero, Quaternion.identity); break; } if (gameObject != null) { gobj = gameObject.GetComponent <GObject>(); gobj.PreInit(); } } return(gobj); }