tanghai 2 лет назад
Родитель
Сommit
0670a3f26a
17 измененных файлов с 227 добавлено и 25 удалено
  1. 12 0
      Unity/Assets/Config/Proto/OuterMessage_C_10001.proto
  2. 14 0
      Unity/Assets/Scripts/Codes/Hotfix/Server/Demo/Scenes/Map/C2M_TestRobotCase2Handler.cs
  3. 1 1
      Unity/Assets/Scripts/Codes/Hotfix/Server/Demo/Scenes/Map/C2M_TestRobotCase2Handler.cs.meta
  4. 0 8
      Unity/Assets/Scripts/Codes/Hotfix/Server/Demo/Scenes/Robot/Case/RobotCase_FirstCase.cs
  5. 37 0
      Unity/Assets/Scripts/Codes/Hotfix/Server/Demo/Scenes/Robot/Case/RobotCase_SecondCase.cs
  6. 11 0
      Unity/Assets/Scripts/Codes/Hotfix/Server/Demo/Scenes/Robot/Case/RobotCase_SecondCase.cs.meta
  7. 14 0
      Unity/Assets/Scripts/Codes/Hotfix/Server/Demo/Scenes/Robot/RobotCaseSystem.cs
  8. 11 0
      Unity/Assets/Scripts/Codes/Hotfix/Server/Demo/Scenes/Robot/RobotCaseSystem.cs.meta
  9. 2 2
      Unity/Assets/Scripts/Codes/Hotfix/Share/Module/Scene/ClientSceneManagerComponentSystem.cs
  10. 30 4
      Unity/Assets/Scripts/Codes/Model/Generate/Client/Message/OuterMessage_C_10001.cs
  11. 30 4
      Unity/Assets/Scripts/Codes/Model/Generate/ClientServer/Message/OuterMessage_C_10001.cs
  12. 30 4
      Unity/Assets/Scripts/Codes/Model/Generate/Server/Message/OuterMessage_C_10001.cs
  13. 8 0
      Unity/Assets/Scripts/Codes/Model/Server/Demo/Robot/Case.meta
  14. 9 0
      Unity/Assets/Scripts/Codes/Model/Server/Demo/Robot/Case/RobotCase_SecondCase.cs
  15. 11 0
      Unity/Assets/Scripts/Codes/Model/Server/Demo/Robot/Case/RobotCase_SecondCase.cs.meta
  16. 2 0
      Unity/Assets/Scripts/Codes/Model/Server/Demo/Robot/RobotCaseType.cs
  17. 5 2
      Unity/Assets/Scripts/Codes/Model/Server/Module/RobotCase/RobotCase.cs

+ 12 - 0
Unity/Assets/Config/Proto/OuterMessage_C_10001.proto

@@ -210,6 +210,18 @@ message M2C_TestRobotCase // IActorLocationResponse
 	int32 N = 4;
 }
 
+message C2M_TestRobotCase2 // IActorLocationMessage
+{
+	int32 RpcId = 1;
+	int32 N = 2;
+}
+
+message M2C_TestRobotCase2 // IActorMessage
+{
+	int32 RpcId = 1;
+	int32 N = 2;
+}
+
 //ResponseType M2C_TransferMap
 message C2M_TransferMap // IActorLocationRequest
 {

+ 14 - 0
Unity/Assets/Scripts/Codes/Hotfix/Server/Demo/Scenes/Map/C2M_TestRobotCase2Handler.cs

@@ -0,0 +1,14 @@
+using System;
+
+namespace ET.Server
+{
+	[ActorMessageHandler(SceneType.Map)]
+	public class C2M_TestRobotCase2Handler : AMActorLocationHandler<Unit, C2M_TestRobotCase2>
+	{
+		protected override async ETTask Run(Unit unit, C2M_TestRobotCase2 message)
+		{
+			MessageHelper.SendToClient(unit, new M2C_TestRobotCase2() {N = message.N});
+			await ETTask.CompletedTask;
+		}
+	}
+}

+ 1 - 1
Unity/Assets/Scripts/Codes/Hotfix/Server/Demo/Scenes/Robot/RobotCaseHelper.cs.meta → Unity/Assets/Scripts/Codes/Hotfix/Server/Demo/Scenes/Map/C2M_TestRobotCase2Handler.cs.meta

@@ -1,5 +1,5 @@
 fileFormatVersion: 2
-guid: 77268c3bdbb837a4d96bdd50497d5b8c
+guid: d0e52442c1b6c4c54b3dbdba68700e05
 MonoImporter:
   externalObjects: {}
   serializedVersion: 2

+ 0 - 8
Unity/Assets/Scripts/Codes/Hotfix/Server/Demo/Scenes/Robot/Case/RobotCase_FirstCase.cs

@@ -12,14 +12,6 @@ namespace ET.Server
             // 创建了两个机器人,生命周期是RobotCase,RobotCase_FirstCase.Run执行结束,机器人就会删除
             await robotCase.NewRobot(2, robots);
 
-            using ListComponent<ETTask> robotsTasks = ListComponent<ETTask>.Create();
-            for (int i = 0; i < 50; ++i)
-            {
-                robotsTasks.Add(robotCase.NewRobot(i, robots));
-            }
-
-            await ETTaskHelper.WaitAll(robotsTasks);
-
             foreach (Scene robotScene in robots)
             {
                 M2C_TestRobotCase response = await robotScene.GetComponent<Client.SessionComponent>().Session.Call(new C2M_TestRobotCase() {N = robotScene.Zone}) as M2C_TestRobotCase;

+ 37 - 0
Unity/Assets/Scripts/Codes/Hotfix/Server/Demo/Scenes/Robot/Case/RobotCase_SecondCase.cs

@@ -0,0 +1,37 @@
+using System;
+
+namespace ET.Server
+{
+    [MessageHandler(SceneType.Client)]
+    public class M2C_TestRobotCase2Handler: AMHandler<M2C_TestRobotCase2>
+    {
+        protected override async ETTask Run(Session session, M2C_TestRobotCase2 message)
+        {
+            ObjectWait objectWait = session.ClientScene().GetComponent<ObjectWait>();
+            if (objectWait == null)
+            {
+                return;
+            }
+            objectWait.Notify(new RobotCase_SecondCaseWait {Error = WaitTypeError.Success, M2CTestRobotCase2 = message});
+            await ETTask.CompletedTask;
+        }
+    }
+
+    [Invoke(RobotCaseType.SecondCase)]
+    public class RobotCase_SecondCase: ARobotCase
+    {
+        protected override async ETTask Run(RobotCase robotCase)
+        {
+            // 创建了1个机器人,生命周期是RobotCase
+            Scene robotScene = await robotCase.NewRobot(1);
+
+            ObjectWait objectWait = robotScene.GetComponent<ObjectWait>();
+            robotScene.GetComponent<Client.SessionComponent>().Session.Send(new C2M_TestRobotCase2() {N = robotScene.Zone});
+            RobotCase_SecondCaseWait robotCaseSecondCaseWait = await objectWait.Wait<RobotCase_SecondCaseWait>();
+            if (robotCaseSecondCaseWait.M2CTestRobotCase2.N != robotScene.Zone)
+            {
+                throw new Exception($"robot case: {RobotCaseType.SecondCase} run fail!");
+            }
+        }
+    }
+}

+ 11 - 0
Unity/Assets/Scripts/Codes/Hotfix/Server/Demo/Scenes/Robot/Case/RobotCase_SecondCase.cs.meta

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

+ 14 - 0
Unity/Assets/Scripts/Codes/Hotfix/Server/Demo/Scenes/Robot/RobotCaseHelper.cs → Unity/Assets/Scripts/Codes/Hotfix/Server/Demo/Scenes/Robot/RobotCaseSystem.cs

@@ -5,6 +5,18 @@ namespace ET.Server
 {
     public static class RobotCaseSystem
     {
+        [ObjectSystem]
+        public class RobotCaseDestroySystem: DestroySystem<RobotCase>
+        {
+            protected override void Destroy(RobotCase self)
+            {
+                foreach (long id in self.Scenes)
+                {
+                    ClientSceneManagerComponent.Instance.Remove(id);
+                }
+            }
+        }
+        
         // 创建机器人,生命周期是RobotCase
         public static async ETTask NewRobot(this RobotCase self, int count, List<Scene> scenes)
         {
@@ -68,6 +80,7 @@ namespace ET.Server
                 await Client.LoginHelper.Login(clientScene, zone.ToString(), zone.ToString());
                 await Client.EnterMapHelper.EnterMapAsync(clientScene);
                 Log.Debug($"create robot ok: {zone}");
+                self.Scenes.Add(clientScene.Id);
                 return clientScene;
             }
             catch (Exception e)
@@ -88,6 +101,7 @@ namespace ET.Server
                 await Client.LoginHelper.Login(clientScene, zone.ToString(), zone.ToString());
                 await Client.EnterMapHelper.EnterMapAsync(clientScene);
                 Log.Debug($"create robot ok: {zone}");
+                self.Scenes.Add(clientScene.Id);
                 return clientScene;
             }
             catch (Exception e)

+ 11 - 0
Unity/Assets/Scripts/Codes/Hotfix/Server/Demo/Scenes/Robot/RobotCaseSystem.cs.meta

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

+ 2 - 2
Unity/Assets/Scripts/Codes/Hotfix/Share/Module/Scene/ClientSceneManagerComponentSystem.cs

@@ -26,13 +26,13 @@
             return ClientSceneManagerComponent.Instance.Get(entity.DomainZone());
         }
         
-        public static Scene Get(this ClientSceneManagerComponent self, int id)
+        public static Scene Get(this ClientSceneManagerComponent self, long id)
         {
             Scene scene = self.GetChild<Scene>(id);
             return scene;
         }
         
-        public static void Remove(this ClientSceneManagerComponent self, int id)
+        public static void Remove(this ClientSceneManagerComponent self, long id)
         {
             self.RemoveChild(id);
         }

+ 30 - 4
Unity/Assets/Scripts/Codes/Model/Generate/Client/Message/OuterMessage_C_10001.cs

@@ -429,6 +429,30 @@ namespace ET
 
 	}
 
+	[Message(OuterMessage.C2M_TestRobotCase2)]
+	[ProtoContract]
+	public partial class C2M_TestRobotCase2: ProtoObject, IActorLocationMessage
+	{
+		[ProtoMember(1)]
+		public int RpcId { get; set; }
+
+		[ProtoMember(2)]
+		public int N { get; set; }
+
+	}
+
+	[Message(OuterMessage.M2C_TestRobotCase2)]
+	[ProtoContract]
+	public partial class M2C_TestRobotCase2: ProtoObject, IActorMessage
+	{
+		[ProtoMember(1)]
+		public int RpcId { get; set; }
+
+		[ProtoMember(2)]
+		public int N { get; set; }
+
+	}
+
 	[ResponseType(nameof(M2C_TransferMap))]
 	[Message(OuterMessage.C2M_TransferMap)]
 	[ProtoContract]
@@ -511,9 +535,11 @@ namespace ET
 		 public const ushort G2C_TestHotfixMessage = 10029;
 		 public const ushort C2M_TestRobotCase = 10030;
 		 public const ushort M2C_TestRobotCase = 10031;
-		 public const ushort C2M_TransferMap = 10032;
-		 public const ushort M2C_TransferMap = 10033;
-		 public const ushort C2G_Benchmark = 10034;
-		 public const ushort G2C_Benchmark = 10035;
+		 public const ushort C2M_TestRobotCase2 = 10032;
+		 public const ushort M2C_TestRobotCase2 = 10033;
+		 public const ushort C2M_TransferMap = 10034;
+		 public const ushort M2C_TransferMap = 10035;
+		 public const ushort C2G_Benchmark = 10036;
+		 public const ushort G2C_Benchmark = 10037;
 	}
 }

+ 30 - 4
Unity/Assets/Scripts/Codes/Model/Generate/ClientServer/Message/OuterMessage_C_10001.cs

@@ -429,6 +429,30 @@ namespace ET
 
 	}
 
+	[Message(OuterMessage.C2M_TestRobotCase2)]
+	[ProtoContract]
+	public partial class C2M_TestRobotCase2: ProtoObject, IActorLocationMessage
+	{
+		[ProtoMember(1)]
+		public int RpcId { get; set; }
+
+		[ProtoMember(2)]
+		public int N { get; set; }
+
+	}
+
+	[Message(OuterMessage.M2C_TestRobotCase2)]
+	[ProtoContract]
+	public partial class M2C_TestRobotCase2: ProtoObject, IActorMessage
+	{
+		[ProtoMember(1)]
+		public int RpcId { get; set; }
+
+		[ProtoMember(2)]
+		public int N { get; set; }
+
+	}
+
 	[ResponseType(nameof(M2C_TransferMap))]
 	[Message(OuterMessage.C2M_TransferMap)]
 	[ProtoContract]
@@ -511,9 +535,11 @@ namespace ET
 		 public const ushort G2C_TestHotfixMessage = 10029;
 		 public const ushort C2M_TestRobotCase = 10030;
 		 public const ushort M2C_TestRobotCase = 10031;
-		 public const ushort C2M_TransferMap = 10032;
-		 public const ushort M2C_TransferMap = 10033;
-		 public const ushort C2G_Benchmark = 10034;
-		 public const ushort G2C_Benchmark = 10035;
+		 public const ushort C2M_TestRobotCase2 = 10032;
+		 public const ushort M2C_TestRobotCase2 = 10033;
+		 public const ushort C2M_TransferMap = 10034;
+		 public const ushort M2C_TransferMap = 10035;
+		 public const ushort C2G_Benchmark = 10036;
+		 public const ushort G2C_Benchmark = 10037;
 	}
 }

+ 30 - 4
Unity/Assets/Scripts/Codes/Model/Generate/Server/Message/OuterMessage_C_10001.cs

@@ -429,6 +429,30 @@ namespace ET
 
 	}
 
+	[Message(OuterMessage.C2M_TestRobotCase2)]
+	[ProtoContract]
+	public partial class C2M_TestRobotCase2: ProtoObject, IActorLocationMessage
+	{
+		[ProtoMember(1)]
+		public int RpcId { get; set; }
+
+		[ProtoMember(2)]
+		public int N { get; set; }
+
+	}
+
+	[Message(OuterMessage.M2C_TestRobotCase2)]
+	[ProtoContract]
+	public partial class M2C_TestRobotCase2: ProtoObject, IActorMessage
+	{
+		[ProtoMember(1)]
+		public int RpcId { get; set; }
+
+		[ProtoMember(2)]
+		public int N { get; set; }
+
+	}
+
 	[ResponseType(nameof(M2C_TransferMap))]
 	[Message(OuterMessage.C2M_TransferMap)]
 	[ProtoContract]
@@ -511,9 +535,11 @@ namespace ET
 		 public const ushort G2C_TestHotfixMessage = 10029;
 		 public const ushort C2M_TestRobotCase = 10030;
 		 public const ushort M2C_TestRobotCase = 10031;
-		 public const ushort C2M_TransferMap = 10032;
-		 public const ushort M2C_TransferMap = 10033;
-		 public const ushort C2G_Benchmark = 10034;
-		 public const ushort G2C_Benchmark = 10035;
+		 public const ushort C2M_TestRobotCase2 = 10032;
+		 public const ushort M2C_TestRobotCase2 = 10033;
+		 public const ushort C2M_TransferMap = 10034;
+		 public const ushort M2C_TransferMap = 10035;
+		 public const ushort C2G_Benchmark = 10036;
+		 public const ushort G2C_Benchmark = 10037;
 	}
 }

+ 8 - 0
Unity/Assets/Scripts/Codes/Model/Server/Demo/Robot/Case.meta

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

+ 9 - 0
Unity/Assets/Scripts/Codes/Model/Server/Demo/Robot/Case/RobotCase_SecondCase.cs

@@ -0,0 +1,9 @@
+namespace ET
+{
+    public struct RobotCase_SecondCaseWait: IWaitType
+    {
+        public int Error { get; set; }
+
+        public M2C_TestRobotCase2 M2CTestRobotCase2;
+    }
+}

+ 11 - 0
Unity/Assets/Scripts/Codes/Model/Server/Demo/Robot/Case/RobotCase_SecondCase.cs.meta

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

+ 2 - 0
Unity/Assets/Scripts/Codes/Model/Server/Demo/Robot/RobotCaseType.cs

@@ -5,6 +5,8 @@ namespace ET.Server
     {
         public const int FirstCase = 1;
 
+        public const int SecondCase = 2;
+
         public const int MaxCaseType = 10000;
     }
 }

+ 5 - 2
Unity/Assets/Scripts/Codes/Model/Server/Module/RobotCase/RobotCase.cs

@@ -1,9 +1,12 @@
-namespace ET.Server
+using System.Collections.Generic;
+
+namespace ET.Server
 {
     [ChildOf(typeof(RobotCaseComponent))]
-    public class RobotCase: Entity, IAwake
+    public class RobotCase: Entity, IAwake, IDestroy
     {
         public ETCancellationToken CancellationToken;
         public string CommandLine;
+        public HashSet<long> Scenes { get; } = new HashSet<long>();
     }
 }