Răsfoiți Sursa

修复运行报错

tanghai 1 an în urmă
părinte
comite
477baf0d3a

+ 0 - 4
Unity/Assets/Scripts/Core/Entity/ChildrenCollection.cs

@@ -12,10 +12,6 @@ namespace ET
         
         public bool IsFromPool { get; set; }
         
-        private ChildrenCollection()
-        {
-        }
-        
         public void Dispose()
         {
             if (!this.IsFromPool)

+ 0 - 4
Unity/Assets/Scripts/Core/Entity/ComponentsCollection.cs

@@ -11,10 +11,6 @@ namespace ET
         }
         
         public bool IsFromPool { get; set; }
-        
-        private ComponentsCollection()
-        {
-        }
 
         public void Dispose()
         {

+ 25 - 48
Unity/Assets/Scripts/Core/Entity/Entity.cs

@@ -206,7 +206,7 @@ namespace ET
                         return;
                     }
 
-                    this.parent.RemoveFromChildren(this);
+                    this.parent.RemoveChildNoDispose(this);
                 }
 
                 this.parent = value;
@@ -270,7 +270,7 @@ namespace ET
                         return;
                     }
 
-                    this.parent.RemoveFromComponents(this);
+                    this.parent.RemoveComponentNoDispose(this);
                 }
 
                 this.parent = value;
@@ -386,18 +386,22 @@ namespace ET
             this.Children.Add(entity.Id, entity);
         }
 
-        private void RemoveFromChildren(Entity entity)
+        private void RemoveChildNoDispose(Entity entity)
         {
             if (this.children == null)
             {
                 return;
             }
 
-            this.children.Remove(entity.Id);
+            if (!this.children.Remove(entity.Id))
+            {
+                return;
+            }
 
             if (this.children.Count == 0)
             {
-                ObjectPool.Recycle(ref this.children);
+                this.children.Dispose();
+                this.children = null;
             }
         }
 
@@ -480,11 +484,11 @@ namespace ET
             {
                 if (this.IsComponent)
                 {
-                    this.parent.RemoveComponent(this);
+                    this.parent.RemoveComponentNoDispose(this);
                 }
                 else
                 {
-                    this.parent.RemoveFromChildren(this);
+                    this.parent.RemoveChildNoDispose(this);
                 }
             }
 
@@ -505,14 +509,17 @@ namespace ET
             this.Components.Add(GetLongHashCodeByType(component.GetType()), component);
         }
 
-        private void RemoveFromComponents(Entity component)
+        private void RemoveComponentNoDispose(Entity component)
         {
             if (this.components == null)
             {
                 return;
             }
 
-            this.components.Remove(GetLongHashCodeByType(component.GetType()));
+            if (!this.components.Remove(GetLongHashCodeByType(component.GetType())))
+            {
+                return;
+            }
 
             if (this.components.Count == 0)
             {
@@ -544,13 +551,13 @@ namespace ET
                 return;
             }
             
-            child.Dispose();
-            
             if (this.children.Count == 0)
             {
                 this.children.Dispose();
                 this.children = null;
             }
+            
+            child.Dispose();
         }
 
         public void RemoveComponent<K>() where K : Entity
@@ -566,59 +573,29 @@ namespace ET
             }
 
             Type type = typeof (K);
-            
-            Entity c;
-            if (!this.components.TryGetValue(GetLongHashCodeByType(type), out c))
+
+            if (this.components.Remove(GetLongHashCodeByType(type), out Entity c))
             {
-                return;
+                c.Dispose();
             }
-
-            this.RemoveFromComponents(c);
-            c.Dispose();
         }
 
-        private void RemoveComponent(Entity component)
+        public void RemoveComponent(Type type)
         {
             if (this.IsDisposed)
             {
                 return;
             }
-
+            
             if (this.components == null)
             {
                 return;
             }
 
-            Entity c;
-            if (!this.components.TryGetValue(GetLongHashCodeByType(component.GetType()), out c))
+            if (this.components.Remove(GetLongHashCodeByType(type), out Entity c))
             {
-                return;
-            }
-
-            if (c.InstanceId != component.InstanceId)
-            {
-                return;
+                c.Dispose();
             }
-
-            this.RemoveFromComponents(c);
-            c.Dispose();
-        }
-
-        public void RemoveComponent(Type type)
-        {
-            if (this.IsDisposed)
-            {
-                return;
-            }
-
-            Entity c;
-            if (!this.components.TryGetValue(GetLongHashCodeByType(type), out c))
-            {
-                return;
-            }
-
-            RemoveFromComponents(c);
-            c.Dispose();
         }
 
         public K GetComponent<K>() where K : Entity

+ 12 - 13
Unity/Assets/Scripts/Hotfix/Server/Module/ActorLocation/MessageLocationSenderComponentSystem.cs

@@ -42,24 +42,23 @@ namespace ET.Server
 
         private static void Check(this MessageLocationSenderOneType self)
         {
-            using (ListComponent<long> list = ListComponent<long>.Create())
+            using ListComponent<long> list = ListComponent<long>.Create();
+            
+            long timeNow = TimeInfo.Instance.ServerNow();
+            foreach ((long key, Entity value) in self.Children)
             {
-                long timeNow = TimeInfo.Instance.ServerNow();
-                foreach ((long key, Entity value) in self.Children)
-                {
-                    MessageLocationSender messageLocationMessageSender = (MessageLocationSender) value;
+                MessageLocationSender messageLocationMessageSender = (MessageLocationSender) value;
 
-                    if (timeNow > messageLocationMessageSender.LastSendOrRecvTime + MessageLocationSenderOneType.TIMEOUT_TIME)
-                    {
-                        list.Add(key);
-                    }
-                }
-
-                foreach (long id in list)
+                if (timeNow > messageLocationMessageSender.LastSendOrRecvTime + MessageLocationSenderOneType.TIMEOUT_TIME)
                 {
-                    self.Remove(id);
+                    list.Add(key);
                 }
             }
+
+            foreach (long id in list)
+            {
+                self.Remove(id);
+            }
         }
 
         private static MessageLocationSender GetOrCreate(this MessageLocationSenderOneType self, long id)