コード例 #1
0
 //删除gameobject 所有从GameObjectPool中
 static void DestroyGameObject(this GameObjectPoolComponent self, GameObject inst)
 {
     if (self.__instPathCache.TryGetValue(inst, out string path))
     {
         if (self.__goInstCountCache.TryGetValue(path, out int count))
         {
             if (count <= 0)
             {
                 Log.Error("__goInstCountCache[path] must > 0");
             }
             else
             {
                 self.__CheckRecycleInstIsDirty(path, inst, () =>
                 {
                     GameObject.Destroy(inst);
                     self.__goInstCountCache[path] = self.__goInstCountCache[path] - 1;
                 });
             }
         }
     }
     else
     {
         Log.Error("DestroyGameObject inst not found from __instPathCache");
     }
 }
コード例 #2
0
        //回收
        public static void RecycleGameObject(this GameObjectPoolComponent self, GameObject inst, bool isclear = false)
        {
            if (!self.__instPathCache.ContainsKey(inst))
            {
                Log.Error("RecycleGameObject inst not found from __instPathCache");
                return;
            }
            var path = self.__instPathCache[inst];

            if (!isclear)
            {
                self.__CheckRecycleInstIsDirty(path, inst, null);
                inst.transform.SetParent(self.__cacheTransRoot, false);
                inst.SetActive(false);
                if (!self.__instCache.ContainsKey(path))
                {
                    self.__instCache[path] = new List <GameObject>();
                }
                self.__instCache[path].Add(inst);
            }
            else
            {
                self.DestroyGameObject(inst);
            }

            //self.CheckCleanRes(path);
        }