public void OnGUI() { if (GUILayout.Button("创建")) { for (int i = 0; i < 3; i++) { Vector3 pos = new Vector3(Random.Range(-5, 5), 0, Random.Range(-5, 5)); poolobj.CreateObject(names[0], prefabs[0], pos, Quaternion.identity); } } if (GUILayout.Button("回收")) { var go = GameObject.FindGameObjectWithTag(names[0]); print(go); if (go != null) { poolobj.CollectObject(go); } } if (GUILayout.Button("全部回收")) { poolobj.ClearAll(); } }
public static void Clear(string prefabName) { if (_instance == null) { return; } if (string.IsNullOrEmpty(prefabName)) { _instance.ClearAll(); return; } _instance.ClearPool(prefabName); }
// Update is called once per frame void OnGUI() { if (GUILayout.Button("创建")) { Vector3 pos1 = new Vector3(Random.Range(-10, 10), 0, Random.Range(-10, 10)); poolobj.CreateObject(names[0], prefabs[0], pos1, Quaternion.identity); } if (GUILayout.Button("释放 ,彻底删除")) { poolobj.ClearAll(); } if (GUILayout.Button("回收")) { //找到某一个,回收 var go = GameObject.FindGameObjectWithTag(names[0]); if (go != null) { poolobj.CollectObject(go); } } }