Explorar el Código

ObjectPool增加Clear方法,在切换场景时可以清空下对象池

tanghai hace 7 años
padre
commit
a17a4c450c

+ 13 - 0
Unity/Assets/Hotfix/Base/Object/ObjectPool.cs

@@ -45,5 +45,18 @@ namespace ETHotfix
 			}
 			queue.Enqueue(obj);
 		}
+		
+		public void Clear()
+		{
+			foreach (var kv in this.dictionary)
+			{
+				foreach (Component component in kv.Value)
+				{
+					component.IsFromPool = false;
+					component.Dispose();
+				}
+			}
+			this.dictionary.Clear();
+		}
 	}
 }

+ 13 - 0
Unity/Assets/Model/Base/Object/ObjectPool.cs

@@ -45,5 +45,18 @@ namespace ETModel
             }
             queue.Enqueue(obj);
         }
+
+	    public void Clear()
+	    {
+		    foreach (var kv in this.dictionary)
+		    {
+			    foreach (Component component in kv.Value)
+			    {
+				    component.IsFromPool = false;
+				    component.Dispose();
+			    }
+		    }
+		    this.dictionary.Clear();
+	    }
     }
 }