public static GameObject Instantiate(GameObject gameObject, Vector3 position, Quaternion rotation, Transform parent) { GameObject res = null; ReusablePrefab reusablePrefab = gameObject.GetComponent <ReusablePrefab>(); if (reusablePrefab == null) { res = Object.Instantiate(gameObject, position, rotation, parent); return(res); } int index = (int)reusablePrefab.Prefab; //命中 lock (blocks[index].BlkMutex) { GameObject obj = blocks[index].Pop(); if (obj != null) { obj.transform.SetPositionAndRotation(position, rotation); obj.transform.SetParent(parent); obj.SetActive(true); res = obj; } //不命中 else { res = Object.Instantiate(gameObject, position, rotation, parent); } } return(res); }
public static GameObject Instantiate(GameObject gameObject, Vector3 position, Quaternion rotation, Transform parent) { GameObject res = null; ReusablePrefab reusablePrefab = gameObject.GetComponent <ReusablePrefab>(); if (reusablePrefab == null) { res = Object.Instantiate(gameObject, position, rotation, parent); return(res); } int index = (int)reusablePrefab.Prefab; //命中 lock (blocks[index].objStack) { if (blocks[index].objStack.Count > 0) { GameObject obj = blocks[index].objStack.Pop(); obj.transform.SetPositionAndRotation(position, rotation); obj.transform.SetParent(parent); obj.SetActive(true); res = obj; blocks[index].prevAccessedTime = Time.time; } //不命中 else { res = Object.Instantiate(gameObject, position, rotation, parent); } } return(res); }
public static void Destroy(GameObject gameObject) { ReusablePrefab reusablePrefab = gameObject.GetComponent <ReusablePrefab>(); gameObject.SetActive(false); if (reusablePrefab == null) { Object.Destroy(gameObject, DESTROY_DELAY); return; } int index = (int)reusablePrefab.Prefab; lock (blocks[index].BlkMutex) { blocks[index].Cache(gameObject); } gameObject.transform.SetParent(GameDB.Instance.ReusableObjectPool); }
public static void Destroy(GameObject gameObject) { ReusablePrefab reusablePrefab = gameObject.GetComponent <ReusablePrefab>(); gameObject.SetActive(false); if (reusablePrefab == null) { Object.Destroy(gameObject, DESTROY_DELAY); return; } int index = (int)reusablePrefab.Prefab; lock (blocks[index].objStack) { blocks[index].objStack.Push(gameObject); blocks[index].prevAccessedTime = Time.time; gameObject.transform.SetParent(GameDB.Instance.ReusableObjectPool); } }