Przeglądaj źródła

直接把BattleComponent作为BattleScene,这样减少了一层结构

tanghai 2 lat temu
rodzic
commit
6257643864
29 zmienionych plików z 90 dodań i 130 usunięć
  1. 3 3
      Unity/Assets/Scenes/Init.unity
  2. 0 1
      Unity/Assets/Scripts/Codes/Hotfix/Client/Demo/Scene/SceneFactory.cs
  3. 7 7
      Unity/Assets/Scripts/Codes/Hotfix/Client/LockStep/LSSceneChangeHelper.cs
  4. 0 15
      Unity/Assets/Scripts/Codes/Hotfix/Client/LockStep/LSSceneFactory.cs
  5. 0 11
      Unity/Assets/Scripts/Codes/Hotfix/Client/LockStep/LSSceneFactory.cs.meta
  6. 12 0
      Unity/Assets/Scripts/Codes/Hotfix/Client/LockStep/MyUnitHelper.cs
  7. 3 0
      Unity/Assets/Scripts/Codes/Hotfix/Client/LockStep/MyUnitHelper.cs.meta
  8. 0 8
      Unity/Assets/Scripts/Codes/Hotfix/Client/LockStep/Scene.meta
  9. 1 1
      Unity/Assets/Scripts/Codes/Hotfix/Server/LockStep/Map/C2Room_ChangeSceneFinishHandler.cs
  10. 2 2
      Unity/Assets/Scripts/Codes/Hotfix/Server/LockStep/Map/RoomManagerComponentSystem.cs
  11. 4 4
      Unity/Assets/Scripts/Codes/Hotfix/Share/LockStep/BattleSceneSystem.cs
  12. 0 0
      Unity/Assets/Scripts/Codes/Hotfix/Share/LockStep/BattleSceneSystem.cs.meta
  13. 2 2
      Unity/Assets/Scripts/Codes/HotfixView/Client/Demo/Camera/CameraComponentSystem.cs
  14. 2 2
      Unity/Assets/Scripts/Codes/HotfixView/Client/LockStep/LockStepAfterUnitCreate_CreateUnitFView.cs
  15. 4 8
      Unity/Assets/Scripts/Codes/HotfixView/Client/LockStep/LockStepSceneChangeStart_AddComponent.cs
  16. 16 0
      Unity/Assets/Scripts/Codes/HotfixView/Client/LockStep/LockStepSceneInitFinish_Finish.cs
  17. 3 0
      Unity/Assets/Scripts/Codes/HotfixView/Client/LockStep/LockStepSceneInitFinish_Finish.cs.meta
  18. 0 8
      Unity/Assets/Scripts/Codes/HotfixView/Client/LockStep/UnitView.meta
  19. 0 21
      Unity/Assets/Scripts/Codes/Model/Share/LockStep/BattleComponent.cs
  20. 25 0
      Unity/Assets/Scripts/Codes/Model/Share/LockStep/BattleScene.cs
  21. 0 0
      Unity/Assets/Scripts/Codes/Model/Share/LockStep/BattleScene.cs.meta
  22. 1 7
      Unity/Assets/Scripts/Codes/ModelView/Client/Demo/Camera/CameraComponent.cs
  23. 2 2
      Unity/Assets/Scripts/Codes/ModelView/Client/LockStep/LockStepOperaComponent.cs
  24. 0 7
      Unity/Assets/Scripts/Codes/ModelView/Client/LockStep/TrueSyncHelper.cs
  25. 0 11
      Unity/Assets/Scripts/Codes/ModelView/Client/LockStep/TrueSyncHelper.cs.meta
  26. 1 1
      Unity/Assets/Scripts/Codes/ModelView/Client/LockStep/UnitFView/UnitFViewComponent.cs
  27. 0 8
      Unity/Assets/Scripts/Codes/ModelView/Client/LockStep/UnitView.meta
  28. 1 1
      Unity/Assets/Scripts/Core/LockStep/LSScene.cs
  29. 1 0
      Unity/Assets/Scripts/Core/Module/Entity/SceneType.cs

+ 3 - 3
Unity/Assets/Scenes/Init.unity

@@ -959,14 +959,14 @@ Transform:
   m_PrefabInstance: {fileID: 0}
   m_PrefabAsset: {fileID: 0}
   m_GameObject: {fileID: 1984349696}
-  m_LocalRotation: {x: 0.48865515, y: -0, z: -0, w: 0.87247705}
-  m_LocalPosition: {x: 2.1579952, y: 35.460117, z: -32.150215}
+  m_LocalRotation: {x: 0.12186928, y: 0, z: 0, w: 0.9925462}
+  m_LocalPosition: {x: 10, y: 6, z: 0}
   m_LocalScale: {x: 1, y: 1, z: 1}
   m_ConstrainProportionsScale: 0
   m_Children: []
   m_Father: {fileID: 575235020}
   m_RootOrder: 0
-  m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
+  m_LocalEulerAnglesHint: {x: 14, y: 0, z: 0}
 --- !u!114 &1984349698
 MonoBehaviour:
   m_ObjectHideFlags: 0

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

@@ -9,7 +9,6 @@ namespace ET.Client
             await ETTask.CompletedTask;
             
             Scene clientScene = EntitySceneFactory.CreateScene(zone, SceneType.Client, name, ClientSceneManagerComponent.Instance);
-            clientScene.AddComponent<CurrentScenesComponent>();
             clientScene.AddComponent<ObjectWait>();
             clientScene.AddComponent<PlayerComponent>();
             

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

@@ -6,12 +6,10 @@ namespace ET.Client
         // 场景切换协程
         public static async ETTask SceneChangeTo(Scene clientScene, string sceneName, long sceneInstanceId)
         {
-            clientScene.RemoveComponent<AIComponent>();
+            clientScene.RemoveComponent<BattleScene>();
 
-            CurrentScenesComponent currentScenesComponent = clientScene.GetComponent<CurrentScenesComponent>();
-            currentScenesComponent.Scene?.Dispose(); // 删除之前的CurrentScene,创建新的
-
-            Scene currentScene = LSSceneFactory.CreateClientRoomScene(sceneInstanceId, clientScene.Zone, sceneName, currentScenesComponent);
+            BattleScene battleScene = clientScene.AddComponent<BattleScene>();
+            battleScene.Name = sceneName;
 
             // 等待表现层订阅的事件完成
             await EventSystem.Instance.PublishAsync(clientScene, new EventType.LockStepSceneChangeStart());
@@ -21,9 +19,11 @@ namespace ET.Client
             // 等待Room2C_EnterMap消息
             WaitType.Wait_Room2C_EnterMap waitRoom2CEnterMap = await clientScene.GetComponent<ObjectWait>().Wait<WaitType.Wait_Room2C_EnterMap>();
 
-            currentScene.GetComponent<BattleComponent>().InitUnit(waitRoom2CEnterMap.Message.UnitInfo);
+            battleScene.LSScene = new LSScene(SceneType.LockStepClient);
+            battleScene.InitUnit(waitRoom2CEnterMap.Message.UnitInfo);
 
-            EventSystem.Instance.Publish(currentScene, new EventType.LockStepSceneInitFinish());
+            // 这个事件中可以订阅取消loading
+            EventSystem.Instance.Publish(clientScene, new EventType.LockStepSceneInitFinish());
         }
     }
 }

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

@@ -1,15 +0,0 @@
-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(SceneType.LockStepClient);
-            EventSystem.Instance.Publish(currentScene, new EventType.AfterCreateCurrentScene());
-            return currentScene;
-        }
-    }
-}

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

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

+ 12 - 0
Unity/Assets/Scripts/Codes/Hotfix/Client/LockStep/MyUnitHelper.cs

@@ -0,0 +1,12 @@
+namespace ET.Client
+{
+    public static class MyUnitHelper
+    {
+        public static UnitF GetMyUnitF(this BattleScene scene)
+        {
+            PlayerComponent playerComponent = scene.GetParent<Scene>().GetComponent<PlayerComponent>();
+            long myId = playerComponent.MyId;
+            return scene.LSScene.Get(myId) as UnitF;
+        }
+    }
+}

+ 3 - 0
Unity/Assets/Scripts/Codes/Hotfix/Client/LockStep/MyUnitHelper.cs.meta

@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: ee3848bb84284c0e8b5b159d8e70cc54
+timeCreated: 1681708021

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

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

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

@@ -34,7 +34,7 @@ namespace ET.Server
                     });
                 }
                 
-                roomScene.GetComponent<BattleComponent>().InitUnit(room2CEnterMap.UnitInfo);
+                roomScene.GetComponent<BattleScene>().InitUnit(room2CEnterMap.UnitInfo);
 
                 RoomMessageHelper.BroadCast(roomScene, room2CEnterMap);
             }

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

@@ -13,8 +13,8 @@ namespace ET.Server
                 self.DomainZone(), "Room", SceneType.Room);
             
             scene.AddComponent<RoomServerComponent, Match2Map_GetRoom>(request);
-            BattleComponent battleComponent = scene.AddComponent<BattleComponent>();
-            battleComponent.LSScene = new LSScene(SceneType.LockStepClient);
+            BattleScene battleScene = scene.AddComponent<BattleScene>();
+            battleScene.LSScene = new LSScene(SceneType.LockStepClient);
             return scene;
         }
     }

+ 4 - 4
Unity/Assets/Scripts/Codes/Hotfix/Share/LockStep/BattleComponentSystem.cs → Unity/Assets/Scripts/Codes/Hotfix/Share/LockStep/BattleSceneSystem.cs

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

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


+ 2 - 2
Unity/Assets/Scripts/Codes/HotfixView/Client/Demo/Camera/CameraComponentSystem.cs

@@ -36,13 +36,13 @@ namespace ET.Client
 			{
 				Vector3 pos = unit.Position.ToVector();
 				Vector3 cameraPos = self.Transform.position;
-				self.Transform.position = new Vector3(pos.x, cameraPos.y, pos.z - 1);
+				self.Transform.position = new Vector3(pos.x, cameraPos.y, pos.z - 10);
 			}
 		}
 		
 		private static UnitF GetMyUnit(this CameraComponent self)
 		{
-			return self.DomainScene().GetComponent<BattleComponent>().LSScene.Get(self.MyId) as UnitF;
+			return self.GetParent<BattleScene>().GetMyUnitF();
 		}
 	}
 }

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

@@ -8,8 +8,8 @@ namespace ET.Client
     {
         protected override async ETTask Run(LSScene lsScene, LSAfterUnitCreate args)
         {
-            Scene currentScene = lsScene.Parent.DomainScene();
-            UnitFViewComponent unitFViewComponent = currentScene.GetComponent<UnitFViewComponent>();
+            BattleScene battleScene = lsScene.GetParent<BattleScene>();
+            UnitFViewComponent unitFViewComponent = battleScene.GetComponent<UnitFViewComponent>();
 
             if (unitFViewComponent == null)
             {

+ 4 - 8
Unity/Assets/Scripts/Codes/HotfixView/Client/LockStep/LockStepSceneChangeStart_AddComponent.cs

@@ -7,7 +7,7 @@ namespace ET.Client
     {
         protected override async ETTask Run(Scene clientScene, EventType.LockStepSceneChangeStart args)
         {
-            Scene currentScene = clientScene.CurrentScene();
+            BattleScene battleScene = clientScene.GetComponent<BattleScene>();
             
             // 创建loading界面
             
@@ -15,16 +15,12 @@ namespace ET.Client
             await UIHelper.Remove(clientScene, UIType.UILobby);
             
             // 加载场景资源
-            await ResourcesComponent.Instance.LoadBundleAsync($"{currentScene.Name}.unity3d");
+            await ResourcesComponent.Instance.LoadBundleAsync($"{battleScene.Name}.unity3d");
             // 切换到map场景
 
-            await SceneManager.LoadSceneAsync(currentScene.Name);
+            await SceneManager.LoadSceneAsync(battleScene.Name);
 
-            currentScene.AddComponent<UnitFViewComponent>();
-
-            currentScene.AddComponent<OperaComponent>();
-
-            currentScene.AddComponent<CameraComponent>();
+            battleScene.AddComponent<UnitFViewComponent>();
         }
     }
 }

+ 16 - 0
Unity/Assets/Scripts/Codes/HotfixView/Client/LockStep/LockStepSceneInitFinish_Finish.cs

@@ -0,0 +1,16 @@
+namespace ET.Client
+{
+    [Event(SceneType.Client)]
+    public class LockStepSceneInitFinish_Finish: AEvent<Scene, EventType.LockStepSceneInitFinish>
+    {
+        protected override async ETTask Run(Scene clientScene, EventType.LockStepSceneInitFinish args)
+        {
+            BattleScene battleScene = clientScene.GetComponent<BattleScene>();
+            
+            battleScene.AddComponent<CameraComponent>();
+            
+            battleScene.AddComponent<LockStepOperaComponent>();
+            await ETTask.CompletedTask;
+        }
+    }
+}

+ 3 - 0
Unity/Assets/Scripts/Codes/HotfixView/Client/LockStep/LockStepSceneInitFinish_Finish.cs.meta

@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: f15b18dfd9a74576bd11f41018782308
+timeCreated: 1681704784

+ 0 - 8
Unity/Assets/Scripts/Codes/HotfixView/Client/LockStep/UnitView.meta

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

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

@@ -1,21 +0,0 @@
-namespace ET
-{
-    [ComponentOf(typeof(Scene))]
-    public class BattleComponent: Entity, IAwake
-    {
-        private long sceneInstanceId;
-        
-        public LSScene LSScene
-        {
-            get
-            {
-                return Root.Instance.Get(this.sceneInstanceId) as LSScene;
-            }
-            set
-            {
-                this.AddChild(value);
-                this.sceneInstanceId = value.InstanceId;
-            }
-        }
-    }
-}

+ 25 - 0
Unity/Assets/Scripts/Codes/Model/Share/LockStep/BattleScene.cs

@@ -0,0 +1,25 @@
+namespace ET
+{
+    [ComponentOf(typeof(Scene))]
+    public class BattleScene: Entity, IScene, IAwake
+    {
+        private long lsSceneInstanceId;
+        
+        public LSScene LSScene
+        {
+            get
+            {
+                return Root.Instance.Get(this.lsSceneInstanceId) as LSScene;
+            }
+            set
+            {
+                this.AddChild(value);
+                this.lsSceneInstanceId = value.InstanceId;
+            }
+        }
+
+        public SceneType SceneType { get; set; } = SceneType.Battle;
+        
+        public string Name { get; set; }
+    }
+}

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


+ 1 - 7
Unity/Assets/Scripts/Codes/ModelView/Client/Demo/Camera/CameraComponent.cs

@@ -2,7 +2,7 @@
 
 namespace ET.Client
 {
-	[ComponentOf(typeof(Scene))]
+	[ComponentOf(typeof(BattleScene))]
 	public class CameraComponent : Entity, IAwake, ILateUpdate
 	{
 		// 战斗摄像机
@@ -10,12 +10,6 @@ namespace ET.Client
 
 		public Transform Transform;
 
-		public long MyId
-		{
-			get;
-			set;
-		}
-
 		public Camera Camera
 		{
 			get

+ 2 - 2
Unity/Assets/Scripts/Codes/ModelView/Client/LockStep/LockStepOperaComponent.cs

@@ -1,7 +1,7 @@
 namespace ET
 {
-    [ComponentOf(typeof(Scene))]
-    public class LockStepOperaComponent: Entity, IUpdate
+    [ComponentOf(typeof(BattleScene))]
+    public class LockStepOperaComponent: Entity, IAwake, IUpdate
     {
     }
 }

+ 0 - 7
Unity/Assets/Scripts/Codes/ModelView/Client/LockStep/TrueSyncHelper.cs

@@ -1,7 +0,0 @@
-namespace ET
-{
-    public static class TrueSyncHelper
-    {
-        
-    }
-}

+ 0 - 11
Unity/Assets/Scripts/Codes/ModelView/Client/LockStep/TrueSyncHelper.cs.meta

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

+ 1 - 1
Unity/Assets/Scripts/Codes/ModelView/Client/LockStep/UnitFView/UnitFViewComponent.cs

@@ -1,6 +1,6 @@
 namespace ET
 {
-	[ComponentOf(typeof(Scene))]
+	[ComponentOf(typeof(BattleScene))]
 	public class UnitFViewComponent: Entity, IAwake, IDestroy
 	{
 	}

+ 0 - 8
Unity/Assets/Scripts/Codes/ModelView/Client/LockStep/UnitView.meta

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

+ 1 - 1
Unity/Assets/Scripts/Core/LockStep/LSScene.cs

@@ -75,7 +75,7 @@ namespace ET
             this.allLSEntities.Remove(id);
         }
 
-        public void RegisterSystem(LSEntity entity)
+        public void RegisterSystem(LSEntity entity) 
         {
             this.allLSEntities.Add(entity.Id, entity);
 

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

@@ -23,6 +23,7 @@ namespace ET
 		Room = 1 << 15,
 		LockStepClient = 1 << 16,
 		LockStepServer = 1 << 17,
+		Battle = 1 << 18,
 
 		// 客户端Model层
 		Client = 1 << 30,