コード例 #1
0
    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();
        }
    }
コード例 #2
0
 public static void Clear(string prefabName)
 {
     if (_instance == null)
     {
         return;
     }
     if (string.IsNullOrEmpty(prefabName))
     {
         _instance.ClearAll();
         return;
     }
     _instance.ClearPool(prefabName);
 }
コード例 #3
0
 // 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);
         }
     }
 }