Kaynağa Gözat

Recycle 回收的时候会判断 IsFromPool 以防止多次入池,所以Fetch 的时候需要设置 IsFromPool 为true (#502)

Co-authored-by: yyds <>
anjiev5 2 yıl önce
ebeveyn
işleme
a22a72a44a

+ 6 - 1
Unity/Assets/Scripts/Core/World/Module/ObjectPool/ObjectPool.cs

@@ -27,7 +27,12 @@ namespace ET
         public object Fetch(Type type)
         public object Fetch(Type type)
         {
         {
             Pool pool = GetPool(type);
             Pool pool = GetPool(type);
-            return pool.Get();
+            object obj = pool.Get();
+            if (obj is IPool p)
+            {
+                p.IsFromPool = true;
+            }
+            return obj;
         }
         }
 
 
         public void Recycle(object obj)
         public void Recycle(object obj)