Преглед изворни кода

LSWorld改new的方式,因为LSWorld比较特殊,它的Id必须是自己设置的,导致不能用AddChild泛型方法

tanghai пре 2 година
родитељ
комит
0bd92f3ff1

+ 1 - 1
Unity/Assets/Scripts/Core/Entity/Entity.cs

@@ -285,7 +285,7 @@ namespace ET
         [BsonDefaultValue(0L)]
         [BsonElement]
         [BsonId]
-        public long Id { get; set; }
+        public long Id { get; protected set; }
 
         [BsonIgnore]
         protected IScene iScene;

+ 3 - 3
Unity/Assets/Scripts/Hotfix/Client/LockStep/LSSceneChangeHelper.cs

@@ -19,7 +19,7 @@ namespace ET.Client
             // 等待Room2C_EnterMap消息
             WaitType.Wait_Room2C_Start waitRoom2CStart = await root.GetComponent<ObjectWait>().Wait<WaitType.Wait_Room2C_Start>();
 
-            room.LSWorld = room.AddChild<LSWorld, SceneType>(SceneType.LockStepClient);
+            room.LSWorld = new LSWorld(SceneType.LockStepClient);
             room.Init(waitRoom2CStart.Message.UnitInfo, waitRoom2CStart.Message.StartTime);
             
             room.AddComponent<LSClientUpdater>();
@@ -37,7 +37,7 @@ namespace ET.Client
             room.Name = "Map1";
             room.IsReplay = true;
             room.Replay = replay;
-            room.LSWorld = room.AddChild<LSWorld, SceneType>(SceneType.LockStepClient);
+            room.LSWorld = new LSWorld(SceneType.LockStepClient);
             room.Init(replay.UnitInfos, TimeInfo.Instance.ServerFrameTime());
             
             // 等待表现层订阅的事件完成
@@ -57,7 +57,7 @@ namespace ET.Client
             Room room = root.AddComponent<Room>();
             room.Name = "Map1";
             
-            room.LSWorld = room.AddChild<LSWorld, SceneType>(SceneType.LockStepClient);
+            room.LSWorld = new LSWorld(SceneType.LockStepClient);
             room.Init(message.UnitInfos, message.StartTime, message.Frame);
             
             // 等待表现层订阅的事件完成

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Server/LockStep/Room/RoomManager2Room_InitHandler.cs

@@ -11,7 +11,7 @@ namespace ET.Server
             
             room.AddComponent<RoomServerComponent, List<long>>(request.PlayerIds);
 
-            room.LSWorld = room.AddChild<LSWorld, SceneType>(SceneType.LockStepServer);
+            room.LSWorld = new LSWorld(SceneType.LockStepServer);
             await ETTask.CompletedTask;
         }
     }

+ 3 - 3
Unity/Assets/Scripts/Model/Share/LockStep/LSEntitySystemSingleton.cs

@@ -14,9 +14,9 @@ namespace ET
     [Code]
     public class LSEntitySystemSingleton: Singleton<LSEntitySystemSingleton>, ISingletonAwake
     {
-        public TypeSystems TypeSystems { get; private set; }
+        private TypeSystems TypeSystems { get; set; }
         
-        private readonly DoubleMap<Type, long> lsEntityTypeLongHashCode = new();
+        private readonly Dictionary<Type, long> lsEntityTypeLongHashCode = new();
         
         public void Awake()
         {
@@ -51,7 +51,7 @@ namespace ET
         
         public long GetLongHashCode(Type type)
         {
-            return this.lsEntityTypeLongHashCode.GetValueByKey(type);
+            return this.lsEntityTypeLongHashCode[type];
         }
         
         public TypeSystems.OneTypeSystems GetOneTypeSystems(Type type)

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

@@ -5,19 +5,8 @@ using TrueSync;
 
 namespace ET
 {
-    [EntitySystemOf(typeof(LSWorld))]
-    public static partial class LSWorldSystem
+    public static class LSWorldSystem
     {
-        [EntitySystem]
-        private static void Awake(this LSWorld self, SceneType sceneType)
-        {
-            self.Id = self.GetId();
-
-            self.SceneType = sceneType;
-            
-            self.Fiber().Info($"LSScene create: {self.Id} {self.InstanceId}");
-        }
-        
         public static LSWorld LSWorld(this LSEntity entity)
         {
             return entity.IScene as LSWorld;
@@ -27,19 +16,29 @@ namespace ET
         {
             return entity.LSWorld().GetId();
         }
-
+        
         public static TSRandom GetRandom(this LSEntity entity)
         {
             return entity.LSWorld().Random;
         }
-
     }
 
     [EnableMethod]
     [ChildOf]
     [ComponentOf]
-    public class LSWorld: Entity, IAwake<SceneType>, IScene
+    public class LSWorld: Entity, IAwake, IScene
     {
+        public LSWorld()
+        {
+        }
+        
+        public LSWorld(SceneType sceneType)
+        {
+            this.Id = this.GetId();
+
+            this.SceneType = sceneType;
+        }
+
         private readonly LSUpdater updater = new();
         
         [BsonIgnore]

+ 1 - 0
Unity/Assets/Scripts/Model/Share/LockStep/Room.cs

@@ -41,6 +41,7 @@ namespace ET
             }
             set
             {
+                this.AddChild(value);
                 this.lsWorld = value;
             }
         }