IPoolingObject CreateAndPushObject(GameObject _prefab) { if (!Common.CheckIsNull(_prefab)) { return(null); } GameObject newGameObject = Instantiate(_prefab); if (newGameObject != null) { IPoolingObject NO = newGameObject.GetComponent <IPoolingObject>(); if (!Common.CheckIsNull(NO)) { return(null); } newGameObject.name = _prefab.name + "_" + transform.childCount.ToString(); NO.Initialize(this.gameObject); PushToPool(NO); m_ListMyPoolingObject.Add(NO); return(NO); } return(null); }
public void DestroyObject(GameObject go) { IPoolingObject poolingObject = go.GetComponent <IPoolingObject>(); if (poolingObject == null) { Destroy(go); return; } PoolingManager.Instance.PushToPool(go); }
public IPoolingObject PopFromPool() { if (m_QActiveObject.Count == 0) { CreateAndPushObject(m_OriginalPrefab); } IPoolingObject newObject = m_QActiveObject.Dequeue(); newObject.OnPopFromQueue(); return(newObject); }
public T instantiate <T>(T newResouces, Transform parent = null) where T : UnityEngine.Object { if (newResouces == null) { Debug.LogError("Fail Instantiate Resource"); return(null); } IPoolingObject poolingObj = (newResouces as GameObject).GetComponent <IPoolingObject>(); if (poolingObj == null) { return(Object.Instantiate(newResouces, parent)); } else { return(PoolingManager.Instance.PopFromPool(newResouces as GameObject, Vector3.zero, Quaternion.identity) as T); } }
public void PushToPool(GameObject go) { if (go == null) { return; } IPoolingObject poolObject = go.GetComponent <IPoolingObject>(); if (poolObject == null) { return; } string[] str = go.name.Split('_'); CreatePool($"@{str[0]}", go, poolObject.StartCount); m_dicPool[$"@{str[0]}"].PushToPool(poolObject); go.SetActive(false); }
public GameObject PopFromPool(GameObject go, Vector3 pos, Quaternion quat) { if (go == null) { return(null); } string[] str = go.name.Split('_'); IPoolingObject poolingObject = go.GetComponent <IPoolingObject>(); if (poolingObject == null) { return(null); } CreatePool($"@{str[0]}", go, poolingObject.StartCount); if (m_dicPool.ContainsKey($"@{str[0]}") == false) { return(null); } IPoolingObject obj = m_dicPool[$"@{str[0]}"].PopFromPool(); if (obj == null) { return(null); } else { GameObject newGo = (obj as MonoBehaviour).gameObject; newGo.transform.position = pos; newGo.transform.rotation = quat; newGo.SetActive(true); return(newGo); } }
public void PushToPool(IPoolingObject po) { m_QActiveObject.Enqueue(po); (po as MonoBehaviour).transform.SetParent(transform); po.OnPushToQueue(); }