Просмотр исходного кода

entity dispose中删除components生成了一个数组,会有gc,去除

tanghai 7 лет назад
Родитель
Сommit
1d4557c534
2 измененных файлов с 22 добавлено и 6 удалено
  1. 11 3
      Unity/Assets/Scripts/Base/Object/Entity.cs
  2. 11 3
      Unity/Hotfix/Base/Object/Entity.cs

+ 11 - 3
Unity/Assets/Scripts/Base/Object/Entity.cs

@@ -34,7 +34,9 @@ namespace ETModel
 				return;
 			}
 			
-			foreach (Component component in this.GetComponents())
+			base.Dispose();
+			
+			foreach (Component component in this.componentDict.Values)
 			{
 				try
 				{
@@ -46,8 +48,6 @@ namespace ETModel
 				}
 			}
 			
-			base.Dispose();
-			
 			this.components.Clear();
 			this.componentDict.Clear();
 		}
@@ -161,6 +161,10 @@ namespace ETModel
 
 		public void RemoveComponent<K>() where K : Component
 		{
+			if (this.IsDisposed)
+			{
+				return;
+			}
 			Type type = typeof (K);
 			Component component;
 			if (!this.componentDict.TryGetValue(type, out component))
@@ -176,6 +180,10 @@ namespace ETModel
 
 		public void RemoveComponent(Type type)
 		{
+			if (this.IsDisposed)
+			{
+				return;
+			}
 			Component component;
 			if (!this.componentDict.TryGetValue(type, out component))
 			{

+ 11 - 3
Unity/Hotfix/Base/Object/Entity.cs

@@ -34,7 +34,9 @@ namespace ETHotfix
 				return;
 			}
 			
-			foreach (Component component in this.GetComponents())
+			base.Dispose();
+			
+			foreach (Component component in this.componentDict.Values)
 			{
 				try
 				{
@@ -46,8 +48,6 @@ namespace ETHotfix
 				}
 			}
 
-			base.Dispose();
-
 			this.components.Clear();
 			this.componentDict.Clear();
 		}
@@ -161,6 +161,10 @@ namespace ETHotfix
 
 		public void RemoveComponent<K>() where K : Component
 		{
+			if (this.IsDisposed)
+			{
+				return;
+			}
 			Type type = typeof (K);
 			Component component;
 			if (!this.componentDict.TryGetValue(type, out component))
@@ -176,6 +180,10 @@ namespace ETHotfix
 
 		public void RemoveComponent(Type type)
 		{
+			if (this.IsDisposed)
+			{
+				return;
+			}
 			Component component;
 			if (!this.componentDict.TryGetValue(type, out component))
 			{