Parcourir la source

LSEntity有个RegisterSystem用到了LSWorld,而LSWorld又继承LSEntity,这样产生了循环依赖了,很不优美,
改成LSEntity.RegisterSystem调用IRegisterLSEntitySystem,LSWorld继承IRegisterLSEntitySystem接口

tanghai il y a 2 ans
Parent
commit
830f90c224

+ 7 - 2
Unity/Assets/Scripts/Model/Share/LockStep/LSEntity.cs

@@ -2,6 +2,11 @@ using System;
 
 namespace ET
 {
+    public interface IRegisterLSEntitySystem
+    {
+        void RegisterSystem(LSEntity entity);
+    }
+    
     [EnableMethod]
     public class LSEntity: Entity
     {
@@ -51,7 +56,7 @@ namespace ET
 
         protected override void RegisterSystem()
         {
-            LSWorld lsWorld = this.LSWorld();
+            IRegisterLSEntitySystem iRegisterLsEntitySystem = (IRegisterLSEntitySystem)this.IScene;
             TypeSystems.OneTypeSystems oneTypeSystems = LSEntitySystemSingleton.Instance.GetOneTypeSystems(this.GetType());
             if (oneTypeSystems == null)
             {
@@ -60,7 +65,7 @@ namespace ET
 
             if (oneTypeSystems.QueueFlag[LSQueneUpdateIndex.LSUpdate])
             {
-                lsWorld.AddToUpdater(this);
+                iRegisterLsEntitySystem.RegisterSystem(this);
             }
         }
     }

+ 6 - 6
Unity/Assets/Scripts/Model/Share/LockStep/LSWorld.cs

@@ -26,7 +26,7 @@ namespace ET
     [EnableMethod]
     [ChildOf]
     [ComponentOf]
-    public class LSWorld: LSEntity, IAwake, IScene
+    public class LSWorld: LSEntity, IAwake, IScene, IRegisterLSEntitySystem
     {
         public LSWorld()
         {
@@ -61,15 +61,15 @@ namespace ET
         
         public int Frame { get; set; }
 
-        public void AddToUpdater(LSEntity lsEntity)
-        {
-            this.updater.Add(lsEntity);
-        }
-
         public void Update()
         {
             this.updater.Update();
             ++this.Frame;
         }
+
+        public void RegisterSystem(LSEntity entity)
+        {
+            this.updater.Add(entity);
+        }
     }
 }