Răsfoiți Sursa

Entity Dispose的时候先释放Child再清理Component,因为Child可能会用到父亲的组件。比如一个场景中的buff可能用到该场景的定时器

tanghai 2 ani în urmă
părinte
comite
6ab4a589ff
1 a modificat fișierele cu 24 adăugiri și 24 ștergeri
  1. 24 24
      Unity/Assets/Scripts/Core/Module/Entity/Entity.cs

+ 24 - 24
Unity/Assets/Scripts/Core/Module/Entity/Entity.cs

@@ -450,30 +450,6 @@ namespace ET
             this.IsRegister = false;
             this.InstanceId = 0;
 
-            // 清理Component
-            if (this.components != null)
-            {
-                foreach (KeyValuePair<Type, Entity> kv in this.components)
-                {
-                    kv.Value.Dispose();
-                }
-
-                this.components.Clear();
-                ObjectPool.Instance.Recycle(this.components);
-                this.components = null;
-
-                // 创建的才需要回到池中,从db中不需要回收
-                if (this.componentsDB != null)
-                {
-                    this.componentsDB.Clear();
-                    if (this.IsNew)
-                    {
-                        ObjectPool.Instance.Recycle(this.componentsDB);
-                        this.componentsDB = null;
-                    }
-                }
-            }
-
             // 清理Children
             if (this.children != null)
             {
@@ -497,6 +473,30 @@ namespace ET
                     }
                 }
             }
+            
+            // 清理Component
+            if (this.components != null)
+            {
+                foreach (KeyValuePair<Type, Entity> kv in this.components)
+                {
+                    kv.Value.Dispose();
+                }
+
+                this.components.Clear();
+                ObjectPool.Instance.Recycle(this.components);
+                this.components = null;
+
+                // 创建的才需要回到池中,从db中不需要回收
+                if (this.componentsDB != null)
+                {
+                    this.componentsDB.Clear();
+                    if (this.IsNew)
+                    {
+                        ObjectPool.Instance.Recycle(this.componentsDB);
+                        this.componentsDB = null;
+                    }
+                }
+            }
 
             // 触发Destroy事件
             if (this is IDestroy)