Răsfoiți Sursa

消息基本调通,接下来就是实现帧同步逻辑

tanghai 2 ani în urmă
părinte
comite
6cffb876a9
37 a modificat fișierele cu 272 adăugiri și 154 ștergeri
  1. 1 2
      Unity/Assets/Config/Proto/LockStepOuter_C_11001.proto
  2. 0 2
      Unity/Assets/Scripts/Codes/Hotfix/Client/Demo/Scene/SceneFactory.cs
  3. 1 1
      Unity/Assets/Scripts/Codes/Hotfix/Client/LockStep/G2C_ChangeSceneHandler.cs
  4. 4 7
      Unity/Assets/Scripts/Codes/Hotfix/Client/LockStep/LSSceneChangeHelper.cs
  5. 1 1
      Unity/Assets/Scripts/Codes/Hotfix/Client/LockStep/LSSceneChangeHelper.cs.meta
  6. 15 0
      Unity/Assets/Scripts/Codes/Hotfix/Client/LockStep/LSSceneFactory.cs
  7. 1 1
      Unity/Assets/Scripts/Codes/Hotfix/Client/LockStep/LSSceneFactory.cs.meta
  8. 0 8
      Unity/Assets/Scripts/Codes/Hotfix/Client/LockStep/UnitF.meta
  9. 11 9
      Unity/Assets/Scripts/Codes/Hotfix/Server/LockStep/Map/C2Room_ChangeSceneFinishHandler.cs
  10. 1 2
      Unity/Assets/Scripts/Codes/Hotfix/Server/LockStep/Map/Match2Map_GetRoomHandler.cs
  11. 0 23
      Unity/Assets/Scripts/Codes/Hotfix/Server/LockStep/Map/RoomComponentSystem.cs
  12. 4 3
      Unity/Assets/Scripts/Codes/Hotfix/Server/LockStep/Map/RoomManagerComponentSystem.cs
  13. 5 3
      Unity/Assets/Scripts/Codes/Hotfix/Server/LockStep/Map/RoomMessageHelper.cs
  14. 20 0
      Unity/Assets/Scripts/Codes/Hotfix/Server/LockStep/Map/RoomServerComponentSystem.cs
  15. 1 1
      Unity/Assets/Scripts/Codes/Hotfix/Server/LockStep/Map/RoomServerComponentSystem.cs.meta
  16. 24 0
      Unity/Assets/Scripts/Codes/Hotfix/Share/LockStep/BattleComponentSystem.cs
  17. 11 0
      Unity/Assets/Scripts/Codes/Hotfix/Share/LockStep/BattleComponentSystem.cs.meta
  18. 4 6
      Unity/Assets/Scripts/Codes/Hotfix/Share/LockStep/UnitF/UnitFFactory.cs
  19. 0 0
      Unity/Assets/Scripts/Codes/Hotfix/Share/LockStep/UnitF/UnitFFactory.cs.meta
  20. 9 3
      Unity/Assets/Scripts/Codes/HotfixView/Client/LockStep/LockStepAfterUnitCreate_CreateUnitFView.cs
  21. 1 1
      Unity/Assets/Scripts/Codes/Model/Client/LockStep/EventType.cs
  22. 7 0
      Unity/Assets/Scripts/Codes/Model/Client/LockStep/RoomClientComponent.cs
  23. 11 0
      Unity/Assets/Scripts/Codes/Model/Client/LockStep/RoomClientComponent.cs.meta
  24. 1 4
      Unity/Assets/Scripts/Codes/Model/Generate/Client/Message/LockStepOuter_C_11001.cs
  25. 1 4
      Unity/Assets/Scripts/Codes/Model/Generate/ClientServer/Message/LockStepOuter_C_11001.cs
  26. 1 4
      Unity/Assets/Scripts/Codes/Model/Generate/Server/Message/LockStepOuter_C_11001.cs
  27. 1 1
      Unity/Assets/Scripts/Codes/Model/Server/LockStep/Map/RoomPlayer.cs
  28. 10 0
      Unity/Assets/Scripts/Codes/Model/Server/LockStep/Map/RoomServerComponent.cs
  29. 11 0
      Unity/Assets/Scripts/Codes/Model/Server/LockStep/Map/RoomServerComponent.cs.meta
  30. 3 7
      Unity/Assets/Scripts/Codes/Model/Share/LockStep/BattleComponent.cs
  31. 11 0
      Unity/Assets/Scripts/Codes/Model/Share/LockStep/BattleComponent.cs.meta
  32. 57 9
      Unity/Assets/Scripts/Core/LockStep/LSScene.cs
  33. 2 4
      Unity/Assets/Scripts/Core/Module/Entity/EntitySceneFactory.cs
  34. 26 19
      Unity/Assets/Scripts/Core/Module/Entity/Scene.cs
  35. 2 1
      Unity/Assets/Scripts/Core/Module/Entity/SceneType.cs
  36. 13 27
      Unity/Assets/Scripts/ThirdParty/TrueSync/TSRandom.cs
  37. 1 1
      Unity/ProjectSettings/ProjectSettings.asset

+ 1 - 2
Unity/Assets/Config/Proto/LockStepOuter_C_11001.proto

@@ -36,9 +36,8 @@ message LockStepUnitInfo
 }
 
 // 房间通知客户端进入战斗
-message Room2C_EnterMap // IActorLocationMessage
+message Room2C_EnterMap // IActorMessage
 {
-	int32 RpcId = 1;
 	repeated LockStepUnitInfo UnitInfo = 2;
 }
 

+ 0 - 2
Unity/Assets/Scripts/Codes/Hotfix/Client/Demo/Scene/SceneFactory.cs

@@ -25,7 +25,5 @@ namespace ET.Client
             EventSystem.Instance.Publish(currentScene, new EventType.AfterCreateCurrentScene());
             return currentScene;
         }
-        
-        
     }
 }

+ 1 - 1
Unity/Assets/Scripts/Codes/Hotfix/Client/LockStep/G2C_ChangeSceneHandler.cs

@@ -6,7 +6,7 @@ namespace ET.Client
     {
         protected override async ETTask Run(Session session, Match2G_NotifyMatchSuccess message)
         {
-            await LockStepSceneChangeHelper.SceneChangeTo(session.DomainScene(), "Map1", message.InstanceId);
+            await LSSceneChangeHelper.SceneChangeTo(session.DomainScene(), "Map1", message.InstanceId);
         }
     }
 }

+ 4 - 7
Unity/Assets/Scripts/Codes/Hotfix/Client/LockStep/LockStepSceneChangeHelper.cs → Unity/Assets/Scripts/Codes/Hotfix/Client/LockStep/LSSceneChangeHelper.cs

@@ -1,7 +1,7 @@
 namespace ET.Client
 {
 
-    public static class LockStepSceneChangeHelper
+    public static class LSSceneChangeHelper
     {
         // 场景切换协程
         public static async ETTask SceneChangeTo(Scene clientScene, string sceneName, long sceneInstanceId)
@@ -10,8 +10,8 @@ namespace ET.Client
 
             CurrentScenesComponent currentScenesComponent = clientScene.GetComponent<CurrentScenesComponent>();
             currentScenesComponent.Scene?.Dispose(); // 删除之前的CurrentScene,创建新的
-            Scene currentScene = SceneFactory.CreateCurrentScene(sceneInstanceId, clientScene.Zone, sceneName, currentScenesComponent);
-            UnitFComponent unitComponent = currentScene.AddComponent<UnitFComponent>();
+
+            Scene currentScene = LSSceneFactory.CreateClientRoomScene(sceneInstanceId, clientScene.Zone, sceneName, currentScenesComponent);
 
             // 等待表现层订阅的事件完成
             await EventSystem.Instance.PublishAsync(clientScene, new EventType.LockStepSceneChangeStart());
@@ -21,10 +21,7 @@ namespace ET.Client
             // 等待Room2C_EnterMap消息
             WaitType.Wait_Room2C_EnterMap waitRoom2CEnterMap = await clientScene.GetComponent<ObjectWait>().Wait<WaitType.Wait_Room2C_EnterMap>();
 
-            foreach (LockStepUnitInfo lockStepUnitInfo in waitRoom2CEnterMap.Message.UnitInfo)
-            {
-                UnitFFactory.Create(currentScene, lockStepUnitInfo);
-            }
+            currentScene.GetComponent<BattleComponent>().InitUnit(waitRoom2CEnterMap.Message.UnitInfo);
 
             EventSystem.Instance.Publish(currentScene, new EventType.LockStepSceneInitFinish());
         }

+ 1 - 1
Unity/Assets/Scripts/Codes/Hotfix/Server/LockStep/Map/RoomComponentSystem.cs.meta → Unity/Assets/Scripts/Codes/Hotfix/Client/LockStep/LSSceneChangeHelper.cs.meta

@@ -1,5 +1,5 @@
 fileFormatVersion: 2
-guid: 6ea8b984794ae4cb592d5d55b5cb653b
+guid: 6b38bd6590f604a9e9bc0360a81fe2b3
 MonoImporter:
   externalObjects: {}
   serializedVersion: 2

+ 15 - 0
Unity/Assets/Scripts/Codes/Hotfix/Client/LockStep/LSSceneFactory.cs

@@ -0,0 +1,15 @@
+namespace ET.Client
+{
+    public static class LSSceneFactory
+    {
+        public static Scene CreateClientRoomScene(long id, int zone, string name, CurrentScenesComponent currentScenesComponent)
+        {
+            Scene currentScene = EntitySceneFactory.CreateScene(id, IdGenerater.Instance.GenerateInstanceId(), zone, SceneType.Current, name, currentScenesComponent);
+            currentScenesComponent.Scene = currentScene;
+            BattleComponent battleComponent = currentScene.AddComponent<BattleComponent>();
+            battleComponent.LSScene = new LSScene(1, currentScene.DomainZone(), SceneType.LockStepClient, "LockStepClient");
+            EventSystem.Instance.Publish(currentScene, new EventType.AfterCreateCurrentScene());
+            return currentScene;
+        }
+    }
+}

+ 1 - 1
Unity/Assets/Scripts/Codes/Hotfix/Client/LockStep/LockStepSceneChangeHelper.cs.meta → Unity/Assets/Scripts/Codes/Hotfix/Client/LockStep/LSSceneFactory.cs.meta

@@ -1,5 +1,5 @@
 fileFormatVersion: 2
-guid: 99d8193254d784805a06909230f31b6a
+guid: 1aef3ff3a4bbb4fb6bda510f8364d827
 MonoImporter:
   externalObjects: {}
   serializedVersion: 2

+ 0 - 8
Unity/Assets/Scripts/Codes/Hotfix/Client/LockStep/UnitF.meta

@@ -1,8 +0,0 @@
-fileFormatVersion: 2
-guid: 115ef175801cd43f4889b774581e6201
-folderAsset: yes
-DefaultImporter:
-  externalObjects: {}
-  userData: 
-  assetBundleName: 
-  assetBundleVariant: 

+ 11 - 9
Unity/Assets/Scripts/Codes/Hotfix/Server/LockStep/Map/C2Room_ChangeSceneFinishHandler.cs

@@ -4,27 +4,27 @@ using TrueSync;
 namespace ET.Server
 {
     [ActorMessageHandler(SceneType.Room)]
-    [FriendOf(typeof (RoomComponent))]
+    [FriendOf(typeof (RoomServerComponent))]
     public class C2Room_ChangeSceneFinishHandler: AMActorHandler<Scene, C2Room_ChangeSceneFinish>
     {
-        protected override async ETTask Run(Scene room, C2Room_ChangeSceneFinish message)
+        protected override async ETTask Run(Scene roomScene, C2Room_ChangeSceneFinish message)
         {
-            RoomComponent roomComponent = room.GetComponent<RoomComponent>();
-            RoomPlayer roomPlayer = room.GetComponent<RoomComponent>().GetChild<RoomPlayer>(message.PlayerId);
+            RoomServerComponent roomServerComponent = roomScene.GetComponent<RoomServerComponent>();
+            RoomPlayer roomPlayer = roomScene.GetComponent<RoomServerComponent>().GetChild<RoomPlayer>(message.PlayerId);
             roomPlayer.IsJoinRoom = true;
-            roomComponent.AlreadyJoinRoomCount++;
+            roomServerComponent.AlreadyJoinRoomCount++;
 
-            if (roomComponent.AlreadyJoinRoomCount <= ConstValue.MatchCount)
+            if (roomServerComponent.AlreadyJoinRoomCount <= ConstValue.MatchCount)
             {
                 // 通知给已加进来的客户端每个玩家的进度
             }
 
-            if (roomComponent.AlreadyJoinRoomCount == ConstValue.MatchCount)
+            if (roomServerComponent.AlreadyJoinRoomCount == ConstValue.MatchCount)
             {
                 await TimerComponent.Instance.WaitAsync(1000);
 
                 Room2C_EnterMap room2CEnterMap = new Room2C_EnterMap() {UnitInfo = new List<LockStepUnitInfo>()};
-                foreach (var kv in roomComponent.Children)
+                foreach (var kv in roomServerComponent.Children)
                 {
                     room2CEnterMap.UnitInfo.Add(new LockStepUnitInfo()
                     {
@@ -33,8 +33,10 @@ namespace ET.Server
                         Rotation = TSQuaternion.identity
                     });
                 }
+                
+                roomScene.GetComponent<BattleComponent>().InitUnit(room2CEnterMap.UnitInfo);
 
-                RoomMessageHelper.BroadCast(room, room2CEnterMap);
+                RoomMessageHelper.BroadCast(roomScene, room2CEnterMap);
             }
 
             await ETTask.CompletedTask;

+ 1 - 2
Unity/Assets/Scripts/Codes/Hotfix/Server/LockStep/Map/Match2Map_GetRoomHandler.cs

@@ -10,8 +10,7 @@ namespace ET.Server
 		{
 			RoomManagerComponent roomManagerComponent = scene.GetComponent<RoomManagerComponent>();
 			Scene roomScene = await roomManagerComponent.CreateRoom(request);
-			roomScene.AddComponent<RoomComponent, Match2Map_GetRoom>(request);
-			response.InstanceId = scene.InstanceId;
+			response.InstanceId = roomScene.InstanceId;
 			await ETTask.CompletedTask;
 		}
 	}

+ 0 - 23
Unity/Assets/Scripts/Codes/Hotfix/Server/LockStep/Map/RoomComponentSystem.cs

@@ -1,23 +0,0 @@
-using System;
-
-namespace ET.Server
-{
-    [FriendOf(typeof(RoomComponent))]
-    public static class RoomComponentSystem
-    {
-        [ObjectSystem]
-        public class RoomComponentAwakeSystem: AwakeSystem<RoomComponent, Match2Map_GetRoom>
-        {
-            protected override void Awake(RoomComponent self, Match2Map_GetRoom match2MapGetRoom)
-            {
-                foreach (long id in match2MapGetRoom.PlayerIds)
-                {
-                    RoomPlayer roomPlayer = self.AddChildWithId<RoomPlayer>(id);
-                }
-                
-                // 创建LockStep场景
-                self.LsScene = new LSScene(IdGenerater.Instance.GenerateId());
-            }
-        }
-    }
-}

+ 4 - 3
Unity/Assets/Scripts/Codes/Hotfix/Server/LockStep/Map/RoomManagerComponentSystem.cs

@@ -5,15 +5,16 @@ namespace ET.Server
 
     public static class RoomManagerComponentSystem
     {
-        public static async ETTask<Scene> CreateRoom(this RoomManagerComponent self, Match2Map_GetRoom match2MapGetRoom)
+        public static async ETTask<Scene> CreateRoom(this RoomManagerComponent self, Match2Map_GetRoom request)
         {
             long instanceId = IdGenerater.Instance.GenerateInstanceId();
             Scene scene = await SceneFactory.CreateServerScene(
                 self, instanceId, instanceId, 
                 self.DomainZone(), "Room", SceneType.Room);
-
-            scene.AddComponent<RoomComponent, Match2Map_GetRoom>(match2MapGetRoom);
             
+            scene.AddComponent<RoomServerComponent, Match2Map_GetRoom>(request);
+            BattleComponent battleComponent = scene.AddComponent<BattleComponent>();
+            battleComponent.LSScene = new LSScene(1, scene.DomainZone(), SceneType.LockStepClient, "LockStepServer");
             return scene;
         }
     }

+ 5 - 3
Unity/Assets/Scripts/Codes/Hotfix/Server/LockStep/Map/RoomMessageHelper.cs

@@ -3,12 +3,14 @@ namespace ET.Server
 
     public static class RoomMessageHelper
     {
-        public static void BroadCast(Scene room, IActorLocationMessage message)
+        public static void BroadCast(Scene roomScene, IActorMessage message)
         {
-            RoomComponent roomComponent = room.GetComponent<RoomComponent>();
-            foreach (var kv in roomComponent.Children)
+            RoomServerComponent roomServerComponent = roomScene.GetComponent<RoomServerComponent>();
+            
+            foreach (var kv in roomServerComponent.Children)
             {
                 RoomPlayer roomPlayer = kv.Value as RoomPlayer;
+                
                 ActorLocationSenderComponent.Instance.Get(LocationType.GateSession).Send(roomPlayer.Id, message);
             }
         }

+ 20 - 0
Unity/Assets/Scripts/Codes/Hotfix/Server/LockStep/Map/RoomServerComponentSystem.cs

@@ -0,0 +1,20 @@
+using System;
+
+namespace ET.Server
+{
+    [FriendOf(typeof(RoomServerComponent))]
+    public static class RoomServerComponentSystem
+    {
+        [ObjectSystem]
+        public class RoomServerComponentAwakeSystem: AwakeSystem<RoomServerComponent, Match2Map_GetRoom>
+        {
+            protected override void Awake(RoomServerComponent self, Match2Map_GetRoom match2MapGetRoom)
+            {
+                foreach (long id in match2MapGetRoom.PlayerIds)
+                {
+                    RoomPlayer roomPlayer = self.AddChildWithId<RoomPlayer>(id);
+                }
+            }
+        }
+    }
+}

+ 1 - 1
Unity/Assets/Scripts/Codes/Model/Server/LockStep/Map/RoomComponent.cs.meta → Unity/Assets/Scripts/Codes/Hotfix/Server/LockStep/Map/RoomServerComponentSystem.cs.meta

@@ -1,5 +1,5 @@
 fileFormatVersion: 2
-guid: ef440982f04a0472a95a52bf4cd4e3a3
+guid: 6d671f754d680422caba612a77dfdb63
 MonoImporter:
   externalObjects: {}
   serializedVersion: 2

+ 24 - 0
Unity/Assets/Scripts/Codes/Hotfix/Share/LockStep/BattleComponentSystem.cs

@@ -0,0 +1,24 @@
+using System;
+using System.Collections.Generic;
+
+namespace ET
+{
+    public static class BattleComponentSystem
+    {
+        [ObjectSystem]
+        public class AwakeSystem: AwakeSystem<BattleComponent>
+        {
+            protected override void Awake(BattleComponent self)
+            {
+            }
+        }
+
+        public static void InitUnit(this BattleComponent self, List<LockStepUnitInfo> unitInfos)
+        {
+            foreach (LockStepUnitInfo lockStepUnitInfo in unitInfos)
+            {
+                UnitFFactory.Init(self.LSScene, lockStepUnitInfo);
+            }
+        }
+    }
+}

+ 11 - 0
Unity/Assets/Scripts/Codes/Hotfix/Share/LockStep/BattleComponentSystem.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 4a0ef11394d28492caa3959412027a17
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 4 - 6
Unity/Assets/Scripts/Codes/Hotfix/Client/LockStep/UnitF/UnitFFactory.cs → Unity/Assets/Scripts/Codes/Hotfix/Share/LockStep/UnitF/UnitFFactory.cs

@@ -1,18 +1,16 @@
-using Unity.Mathematics;
-
-namespace ET.Client
+namespace ET
 {
     public static class UnitFFactory
     {
-        public static UnitF Create(Scene currentScene, LockStepUnitInfo unitInfo)
+        public static UnitF Init(Scene lsScene, LockStepUnitInfo unitInfo)
         {
-	        UnitFComponent unitComponent = currentScene.GetComponent<UnitFComponent>();
+	        UnitFComponent unitComponent = lsScene.AddComponent<UnitFComponent>();
 	        UnitF unit = unitComponent.AddChildWithId<UnitF>(unitInfo.PlayerId);
 	        
 	        unit.Position = unitInfo.Position;
 	        unit.Rotation = unitInfo.Rotation;
 	        
-	        EventSystem.Instance.Publish(unit.DomainScene(), new EventType.LockStepAfterUnitCreate() {UnitF = unit});
+	        EventSystem.Instance.Publish(unit.DomainScene(), new EventType.LSAfterUnitCreate() {UnitF = unit});
             return unit;
         }
     }

+ 0 - 0
Unity/Assets/Scripts/Codes/Hotfix/Client/LockStep/UnitF/UnitFFactory.cs.meta → Unity/Assets/Scripts/Codes/Hotfix/Share/LockStep/UnitF/UnitFFactory.cs.meta


+ 9 - 3
Unity/Assets/Scripts/Codes/HotfixView/Client/LockStep/LockStepAfterUnitCreate_CreateUnitFView.cs

@@ -3,12 +3,18 @@ using UnityEngine;
 
 namespace ET.Client
 {
-    [Event(SceneType.Current)]
-    public class LockStepAfterUnitCreate_CreateUnitFView: AEvent<LockStepAfterUnitCreate>
+    [Event(SceneType.LockStepClient)]
+    public class LockStepAfterUnitCreate_CreateUnitFView: AEvent<LSAfterUnitCreate>
     {
-        protected override async ETTask Run(Scene currentScene, LockStepAfterUnitCreate args)
+        protected override async ETTask Run(Scene lsScene, LSAfterUnitCreate args)
         {
+            Scene currentScene = lsScene.Parent.DomainScene();
             UnitFViewComponent unitFViewComponent = currentScene.GetComponent<UnitFViewComponent>();
+
+            if (unitFViewComponent == null)
+            {
+                return;
+            }
             
             GameObject bundleGameObject = (GameObject)ResourcesComponent.Instance.GetAsset("Unit.unity3d", "Unit");
             GameObject prefab = bundleGameObject.Get<GameObject>("Skeleton");

+ 1 - 1
Unity/Assets/Scripts/Codes/Model/Client/LockStep/EventType.cs

@@ -10,7 +10,7 @@
         {
         }
 
-        public struct LockStepAfterUnitCreate
+        public struct LSAfterUnitCreate
         {
             public UnitF UnitF;
         }

+ 7 - 0
Unity/Assets/Scripts/Codes/Model/Client/LockStep/RoomClientComponent.cs

@@ -0,0 +1,7 @@
+namespace ET
+{
+    [ComponentOf(typeof(Scene))]
+    public class RoomClientComponent: Entity
+    {
+    }
+}

+ 11 - 0
Unity/Assets/Scripts/Codes/Model/Client/LockStep/RoomClientComponent.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 9288867c277cf46d2b8c7f9cb4dadf78
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 1 - 4
Unity/Assets/Scripts/Codes/Model/Generate/Client/Message/LockStepOuter_C_11001.cs

@@ -70,11 +70,8 @@ namespace ET
 // 房间通知客户端进入战斗
 	[Message(LockStepOuter.Room2C_EnterMap)]
 	[ProtoContract]
-	public partial class Room2C_EnterMap: ProtoObject, IActorLocationMessage
+	public partial class Room2C_EnterMap: ProtoObject, IActorMessage
 	{
-		[ProtoMember(1)]
-		public int RpcId { get; set; }
-
 		[ProtoMember(2)]
 		public List<LockStepUnitInfo> UnitInfo { get; set; }
 

+ 1 - 4
Unity/Assets/Scripts/Codes/Model/Generate/ClientServer/Message/LockStepOuter_C_11001.cs

@@ -70,11 +70,8 @@ namespace ET
 // 房间通知客户端进入战斗
 	[Message(LockStepOuter.Room2C_EnterMap)]
 	[ProtoContract]
-	public partial class Room2C_EnterMap: ProtoObject, IActorLocationMessage
+	public partial class Room2C_EnterMap: ProtoObject, IActorMessage
 	{
-		[ProtoMember(1)]
-		public int RpcId { get; set; }
-
 		[ProtoMember(2)]
 		public List<LockStepUnitInfo> UnitInfo { get; set; }
 

+ 1 - 4
Unity/Assets/Scripts/Codes/Model/Generate/Server/Message/LockStepOuter_C_11001.cs

@@ -70,11 +70,8 @@ namespace ET
 // 房间通知客户端进入战斗
 	[Message(LockStepOuter.Room2C_EnterMap)]
 	[ProtoContract]
-	public partial class Room2C_EnterMap: ProtoObject, IActorLocationMessage
+	public partial class Room2C_EnterMap: ProtoObject, IActorMessage
 	{
-		[ProtoMember(1)]
-		public int RpcId { get; set; }
-
 		[ProtoMember(2)]
 		public List<LockStepUnitInfo> UnitInfo { get; set; }
 

+ 1 - 1
Unity/Assets/Scripts/Codes/Model/Server/LockStep/Map/RoomPlayer.cs

@@ -1,7 +1,7 @@
 namespace ET.Server
 {
 
-    [ChildOf(typeof (RoomComponent))]
+    [ChildOf(typeof (RoomServerComponent))]
     public class RoomPlayer: Entity, IAwake
     {
         public bool IsJoinRoom { get; set; }

+ 10 - 0
Unity/Assets/Scripts/Codes/Model/Server/LockStep/Map/RoomServerComponent.cs

@@ -0,0 +1,10 @@
+using System.Collections.Generic;
+
+namespace ET.Server
+{
+    [ComponentOf(typeof(Scene))]
+    public class RoomServerComponent: Entity, IAwake<Match2Map_GetRoom>
+    {
+        public int AlreadyJoinRoomCount;
+    }
+}

+ 11 - 0
Unity/Assets/Scripts/Codes/Model/Server/LockStep/Map/RoomServerComponent.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 1ab5631e2c7734968b6ac758ce81dd13
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 3 - 7
Unity/Assets/Scripts/Codes/Model/Server/LockStep/Map/RoomComponent.cs → Unity/Assets/Scripts/Codes/Model/Share/LockStep/BattleComponent.cs

@@ -1,15 +1,11 @@
-using System.Collections.Generic;
-
-namespace ET.Server
+namespace ET
 {
     [ComponentOf(typeof(Scene))]
-    public class RoomComponent: Entity, IAwake<Match2Map_GetRoom>
+    public class BattleComponent: Entity, IAwake
     {
-        public int AlreadyJoinRoomCount;
-
         private long sceneInstanceId;
         
-        public LSScene LsScene
+        public LSScene LSScene
         {
             get
             {

+ 11 - 0
Unity/Assets/Scripts/Codes/Model/Share/LockStep/BattleComponent.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 51fde8d44ce33433b9523076002f8831
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 57 - 9
Unity/Assets/Scripts/Core/LockStep/LSScene.cs

@@ -1,6 +1,7 @@
 using MongoDB.Bson.Serialization.Attributes;
 using System;
 using System.Collections.Generic;
+using TrueSync;
 
 namespace ET
 {
@@ -23,22 +24,68 @@ namespace ET
         {
             return entity.DomainScene().GetId();
         }
+        
+        public static TSRandom GetRandom(this LSEntity entity)
+        {
+            return entity.DomainScene().Random;
+        }
     }
 
     [EnableMethod]
     [ChildOf]
-    public class LSScene: LSEntity, IDeserialize
+    public class LSScene: Scene, IDeserialize
     {
-        public LSScene(long id)
+        public LSScene()
+        {
+        }
+        
+        public LSScene(long id, int zone, SceneType sceneType, string name): base(id, IdGenerater.Instance.GenerateInstanceId(), zone, sceneType, name, null)
         {
-            this.Id = id;
-            this.InstanceId = IdGenerater.Instance.GenerateInstanceId();
-            this.IsCreated = true;
-            this.IsNew = true;
-            this.IsRegister = true;
+            this.Updater.Parent = this;
+            
             Log.Info($"LSScene create: {this.Id} {this.InstanceId}");
         }
         
+        public new K AddComponent<K>(bool isFromPool = false) where K : LSEntity, IAwake, new()
+        {
+            return this.AddComponentWithId<K>(this.GetId(), isFromPool);
+        }
+
+        public new K AddComponent<K, P1>(P1 p1, bool isFromPool = false) where K : LSEntity, IAwake<P1>, new()
+        {
+            return this.AddComponentWithId<K, P1>(this.GetId(), p1, isFromPool);
+        }
+
+        public new K AddComponent<K, P1, P2>(P1 p1, P2 p2, bool isFromPool = false) where K : LSEntity, IAwake<P1, P2>, new()
+        {
+            return this.AddComponentWithId<K, P1, P2>(this.GetId(), p1, p2, isFromPool);
+        }
+
+        public new K AddComponent<K, P1, P2, P3>(P1 p1, P2 p2, P3 p3, bool isFromPool = false) where K : LSEntity, IAwake<P1, P2, P3>, new()
+        {
+            return this.AddComponentWithId<K, P1, P2, P3>(this.GetId(), p1, p2, p3, isFromPool);
+        }
+
+        public new T AddChild<T>(bool isFromPool = false) where T : LSEntity, IAwake
+        {
+            return this.AddChildWithId<T>(this.GetId(), isFromPool);
+        }
+
+        public new T AddChild<T, A>(A a, bool isFromPool = false) where T : LSEntity, IAwake<A>
+        {
+            return this.AddChildWithId<T, A>(this.GetId(), a, isFromPool);
+        }
+
+        public new T AddChild<T, A, B>(A a, B b, bool isFromPool = false) where T : LSEntity, IAwake<A, B>
+        {
+            return this.AddChildWithId<T, A, B>(this.GetId(), a, b, isFromPool);
+        }
+
+        public new T AddChild<T, A, B, C>(A a, B b, C c, bool isFromPool = false) where T : LSEntity, IAwake<A, B, C>
+        {
+            return this.AddChildWithId<T, A, B, C>(this.GetId(), a, b, c, isFromPool);
+        }
+        
         [BsonIgnore]
         public new Entity Parent
         {
@@ -48,8 +95,7 @@ namespace ET
             }
             set
             {
-                value?.AddChild(this);
-                this.Domain = this;
+                base.Parent = value;
             }
         }
 
@@ -94,5 +140,7 @@ namespace ET
         {
             return ++this.idGenerator;
         }
+
+        public TSRandom Random { get; set; }
     }
 }

+ 2 - 4
Unity/Assets/Scripts/Core/Module/Entity/EntitySceneFactory.cs

@@ -4,16 +4,14 @@
     {
         public static Scene CreateScene(long id, long instanceId, int zone, SceneType sceneType, string name, Entity parent = null)
         {
-            Scene scene = new Scene(id, instanceId, zone, sceneType, name);
-            scene.Parent = parent;
+            Scene scene = new Scene(id, instanceId, zone, sceneType, name, parent);
             return scene;
         }
 
         public static Scene CreateScene(int zone, SceneType sceneType, string name, Entity parent = null)
         {
             long instanceId = IdGenerater.Instance.GenerateInstanceId();
-            Scene scene = new Scene(zone, instanceId, zone, sceneType, name);
-            scene.Parent = parent;
+            Scene scene = new Scene(zone, instanceId, zone, sceneType, name, parent);
             return scene;
         }
     }

+ 26 - 19
Unity/Assets/Scripts/Core/Module/Entity/Scene.cs

@@ -1,10 +1,6 @@
-using System.Diagnostics;
-using MongoDB.Bson.Serialization.Attributes;
-
-namespace ET
+namespace ET
 {
     [EnableMethod]
-    [DebuggerDisplay("ViewName,nq")]
     [ChildOf]
     public class Scene: Entity
     {
@@ -23,7 +19,12 @@ namespace ET
             get;
         }
 
-        public Scene(long instanceId, int zone, SceneType sceneType, string name)
+        public Scene()
+        {
+            
+        }
+
+        public Scene(long instanceId, int zone, SceneType sceneType, string name, Entity parent)
         {
             this.Id = instanceId;
             this.InstanceId = instanceId;
@@ -32,11 +33,13 @@ namespace ET
             this.Name = name;
             this.IsCreated = true;
             this.IsNew = true;
+            this.Parent = parent;
+            this.Domain = this;
             this.IsRegister = true;
             Log.Info($"scene create: {this.SceneType} {this.Name} {this.Id} {this.InstanceId} {this.Zone}");
         }
 
-        public Scene(long id, long instanceId, int zone, SceneType sceneType, string name)
+        public Scene(long id, long instanceId, int zone, SceneType sceneType, string name, Entity parent)
         {
             this.Id = id;
             this.InstanceId = instanceId;
@@ -45,6 +48,8 @@ namespace ET
             this.Name = name;
             this.IsCreated = true;
             this.IsNew = true;
+            this.Parent = parent;
+            this.Domain = this;
             this.IsRegister = true;
             Log.Info($"scene create: {this.SceneType} {this.Name} {this.Id} {this.InstanceId} {this.Zone}");
         }
@@ -56,25 +61,27 @@ namespace ET
             Log.Info($"scene dispose: {this.SceneType} {this.Name} {this.Id} {this.InstanceId} {this.Zone}");
         }
 
-        [BsonIgnore]
+        public new Entity Domain
+        {
+            get => this.domain;
+            private set => this.domain = value;
+        }
+
         public new Entity Parent
         {
             get
             {
                 return this.parent;
             }
-            set
+            protected set
             {
-                value?.AddChild(this);
-                this.Domain = this;
-            }
-        }
-        
-        protected override string ViewName
-        {
-            get
-            {
-                return $"{this.GetType().Name} ({this.SceneType})";    
+                if (value == null)
+                {
+                    return;
+                }
+
+                this.parent = value;
+                this.parent.Children.Add(this.Id, this);
             }
         }
     }

+ 2 - 1
Unity/Assets/Scripts/Core/Module/Entity/SceneType.cs

@@ -21,7 +21,8 @@ namespace ET
 		Benchmark = 1 << 13,
 		Match = 1 << 14,
 		Room = 1 << 15,
-		LockStep = 1 << 16,
+		LockStepClient = 1 << 16,
+		LockStepServer = 1 << 17,
 
 		// 客户端Model层
 		Client = 1 << 30,

+ 13 - 27
Unity/Assets/Scripts/ThirdParty/TrueSync/TSRandom.cs

@@ -1,4 +1,5 @@
 using System;
+using MongoDB.Bson.Serialization.Attributes;
 
 namespace TrueSync {
 
@@ -16,29 +17,14 @@ namespace TrueSync {
         private const uint UPPER_MASK = 0x80000000U;
         private const uint LOWER_MASK = 0x7fffffffU;
         private const int MAX_RAND_INT = 0x7fffffff;
+        [BsonElement]
         private uint[] mag01 = { 0x0U, MATRIX_A };
+        [BsonElement]
         private uint[] mt = new uint[N];
+        [BsonElement]
         private int mti = N + 1;
 
-        /**
-         *  @brief Static instance of {@link TSRandom} with seed 1.
-         **/
-        public static TSRandom instance;
-
-        internal static void Init() {
-            instance = New(1);
-        }
-
-        /**
-         *  @brief Generates a new instance based on a given seed.
-         **/
-        public static TSRandom New(int seed) {
-            TSRandom r = new TSRandom(seed);
-            return r;
-        }
-
         private TSRandom() {
-            init_genrand((uint)DateTime.Now.Millisecond);
         }
 
         private TSRandom(int seed) {
@@ -64,8 +50,8 @@ namespace TrueSync {
         /**
          *  @brief Returns a random integer.
          **/
-        public static int CallNext() {
-            return instance.Next();
+        public int CallNext() {
+            return this.Next();
         }
 
         /**
@@ -102,15 +88,15 @@ namespace TrueSync {
         /**
          *  @brief Returns a integer between a min value [inclusive] and a max value [exclusive].
          **/
-        public static int Range(int minValue, int maxValue) {
-            return instance.Next(minValue, maxValue);
+        public int Range(int minValue, int maxValue) {
+            return this.Next(minValue, maxValue);
         }
 
         /**
          *  @brief Returns a {@link FP} between a min value [inclusive] and a max value [inclusive].
          **/
-        public static FP Range(float minValue, float maxValue) {
-            return instance.Next(minValue, maxValue);
+        public FP Range(float minValue, float maxValue) {
+            return this.Next(minValue, maxValue);
         }
 
         /**
@@ -123,16 +109,16 @@ namespace TrueSync {
         /**
          *  @brief Returns a {@link FP} between 0.0 [inclusive] and 1.0 [inclusive].
          **/
-        public static FP value {
+        public FP value {
             get {
-                return instance.NextFP();
+                return this.NextFP();
             }
         }
 
         /**
          *  @brief Returns a random {@link TSVector} representing a point inside a sphere with radius 1.
          **/
-        public static TSVector insideUnitSphere {
+        public TSVector insideUnitSphere {
             get {
                 return new TSVector(value, value, value);
             }

+ 1 - 1
Unity/ProjectSettings/ProjectSettings.asset

@@ -841,7 +841,7 @@ PlayerSettings:
   scriptingDefineSymbols:
     Android: NETSTANDARD2_0;UNITY
     Server: NETSTANDARD2_0;UNITY
-    Standalone: NETSTANDARD2_0;UNITY
+    Standalone: NETSTANDARD2_0;UNITY;ENABLE_CODES
     WebGL: NETSTANDARD2_0;UNITY
     iPhone: NETSTANDARD2_0;UNITY
   additionalCompilerArguments: {}