소스 검색

解决了Event跟NumericWatcher 服务端跟机器人同时订阅的问题

tanghai 3 년 전
부모
커밋
8d7e046b3c
43개의 변경된 파일213개의 추가작업 그리고 177개의 파일을 삭제
  1. 1 1
      Apps/App/Apps.App.csproj
  2. 1 1
      Apps/App/Program.cs
  3. 3 2
      Apps/Hotfix/AppStart_Init.cs
  4. 1 1
      Apps/Hotfix/Apps.Hotfix.csproj
  5. 2 2
      Apps/Hotfix/Server/AOI/AOIEntitySystem.cs
  6. 3 12
      Apps/Hotfix/Server/AOI/ChangePosition_NotifyAOI.cs
  7. 4 5
      Apps/Hotfix/Server/Unit/UnitEnterSightRange_NotifyClient.cs
  8. 4 5
      Apps/Hotfix/Server/Unit/UnitLeaveSightRange_NotifyClient.cs
  9. 1 1
      Apps/Model/Apps.Model.csproj
  10. 0 2
      Apps/Model/Server/EventType.cs
  11. 1 1
      Apps/ThirdParty/Apps.ThirdParty.csproj
  12. 1 1
      Apps/Tool/Apps.Tool.csproj
  13. 1 1
      Unity/Codes/Hotfix/Client/Login/EnterMapHelper.cs
  14. 1 1
      Unity/Codes/Hotfix/Client/Login/LoginHelper.cs
  15. 2 2
      Unity/Codes/Hotfix/Client/Scene/SceneChangeHelper.cs
  16. 2 2
      Unity/Codes/Hotfix/Client/Scene/SceneFactory.cs
  17. 1 1
      Unity/Codes/Hotfix/Client/Unit/UnitFactory.cs
  18. 5 3
      Unity/Codes/Hotfix/Module/Numeric/NumericChangeEvent_NotifyWatcher.cs
  19. 3 3
      Unity/Codes/Hotfix/Module/Numeric/NumericWatcher_Hp_ShowUI.cs
  20. 2 2
      Unity/Codes/Hotfix/Share/Move/MoveComponentSystem.cs
  21. 4 3
      Unity/Codes/HotfixView/AppStart_Init.cs
  22. 5 5
      Unity/Codes/HotfixView/Client/Scene/AfterCreateCurrentScene_AddComponent.cs
  23. 6 6
      Unity/Codes/HotfixView/Client/Scene/AfterCreateZoneScene_AddComponent.cs
  24. 4 3
      Unity/Codes/HotfixView/Client/Scene/SceneChangeStart_AddComponent.cs
  25. 4 3
      Unity/Codes/HotfixView/Client/UI/UIHelp/SceneChangeFinishEvent_CreateUIHelp.cs
  26. 4 3
      Unity/Codes/HotfixView/Client/UI/UILoading/LoadingBeginEvent_CreateLoadingUI.cs
  27. 4 3
      Unity/Codes/HotfixView/Client/UI/UILoading/LoadingFinishEvent_RemoveLoadingUI.cs
  28. 5 6
      Unity/Codes/HotfixView/Client/UI/UILobby/LoginFinish_CreateLobbyUI.cs
  29. 5 6
      Unity/Codes/HotfixView/Client/UI/UILogin/AppStartInitFinish_CreateLoginUI.cs
  30. 5 6
      Unity/Codes/HotfixView/Client/UI/UILogin/LoginFinish_RemoveLoginUI.cs
  31. 6 5
      Unity/Codes/HotfixView/Client/Unit/AfterUnitCreate_CreateUnitView.cs
  32. 5 4
      Unity/Codes/HotfixView/Client/Unit/ChangePosition_SyncGameObjectPos.cs
  33. 5 4
      Unity/Codes/HotfixView/Client/Unit/ChangeRotation_SyncGameObjectRotation.cs
  34. 6 0
      Unity/Codes/Model/Core/Event/EventAttribute.cs
  35. 4 5
      Unity/Codes/Model/Core/Event/IEvent.cs
  36. 66 32
      Unity/Codes/Model/Core/Object/EventSystem.cs
  37. 1 1
      Unity/Codes/Model/Module/Numeric/INumericWatcher.cs
  38. 1 2
      Unity/Codes/Model/Module/Numeric/NumericComponent.cs
  39. 4 1
      Unity/Codes/Model/Module/Numeric/NumericWatcherAttribute.cs
  40. 27 8
      Unity/Codes/Model/Module/Numeric/NumericWatcherComponent.cs
  41. 0 19
      Unity/Codes/Model/Share/EventType.cs
  42. 2 2
      Unity/Codes/Model/Share/Unit/Unit.cs
  43. 1 1
      Unity/Codes/ModelView/Client/Entry.cs

+ 1 - 1
Apps/App/Apps.App.csproj

@@ -4,7 +4,7 @@
     <OutputType>Exe</OutputType>
     <TargetFramework>net6.0</TargetFramework>
     <RootNamespace>ET</RootNamespace>
-    <LangVersion>8</LangVersion>
+    <LangVersion>9</LangVersion>
     <AssemblyName>App</AssemblyName>
   </PropertyGroup>
 

+ 1 - 1
Apps/App/Program.cs

@@ -40,7 +40,7 @@ namespace ET
 				
 				Log.Console($"app start: {Game.Scene.Id} options: {JsonHelper.ToJson(Game.Options)} ");
 
-				Game.EventSystem.Publish(new EventType.AppStart());
+				Game.EventSystem.Publish(Game.Scene, new EventType.AppStart());
 				
 				while (true)
 				{

+ 3 - 2
Apps/Hotfix/AppStart_Init.cs

@@ -3,9 +3,10 @@ using System.Net;
 
 namespace ET.Server
 {
-    public class AppStart_Init: AEvent<ET.EventType.AppStart>
+    [Event(SceneType.Process)]
+    public class AppStart_Init: AEvent<Scene, ET.EventType.AppStart>
     {
-        protected override async ETTask Run(ET.EventType.AppStart args)
+        protected override async ETTask Run(Scene scene, ET.EventType.AppStart args)
         {
             Game.Scene.AddComponent<ConfigComponent>().ConfigLoader = new ConfigLoader();
             await ConfigComponent.Instance.LoadAsync();

+ 1 - 1
Apps/Hotfix/Apps.Hotfix.csproj

@@ -2,7 +2,7 @@
   <PropertyGroup>
     <TargetFramework>net6.0</TargetFramework>
     <RootNamespace>ET</RootNamespace>
-    <LangVersion>8</LangVersion>
+    <LangVersion>9</LangVersion>
     <AssemblyName>Hotfix</AssemblyName>
   </PropertyGroup>
   <PropertyGroup>

+ 2 - 2
Apps/Hotfix/Server/AOI/AOIEntitySystem.cs

@@ -136,7 +136,7 @@ namespace ET.Server
                     enter.BeSeeUnits.Add(self.Id, self);
                 }
             }
-            Game.EventSystem.Publish(new EventType.UnitEnterSightRange() {A = self, B = enter});
+            Game.EventSystem.Publish(self.Unit, new EventType.UnitEnterSightRange() { B = enter });
         }
 
         // leave离开self视野
@@ -164,7 +164,7 @@ namespace ET.Server
                 leave.BeSeePlayers.Remove(self.Id);
             }
 
-            Game.EventSystem.Publish(new EventType.UnitLeaveSightRange {A = self, B = leave});
+            Game.EventSystem.Publish(self, new EventType.UnitLeaveSightRange { B = leave });
         }
 
         /// <summary>

+ 3 - 12
Apps/Hotfix/Server/AOI/ChangePosition_NotifyAOI.cs

@@ -2,20 +2,11 @@
 
 namespace ET.Server
 {
-    [Event]
-    public class ChangePosition_NotifyAOI: AEvent<ET.EventType.ChangePosition>
+    [Event(SceneType.Map)]
+    public class ChangePosition_NotifyAOI: AEvent<Unit, ET.EventType.ChangePosition>
     {
-        protected override async ETTask Run(ET.EventType.ChangePosition args)
+        protected override async ETTask Run(Unit unit, ET.EventType.ChangePosition args)
         {
-            Unit unit = args.Unit;
-
-            // 机器人也有Unit,机器人的Unit在Current Scene
-            
-            if (unit.DomainScene().SceneType != SceneType.Map)
-            {
-                return;
-            }
-            
             Vector3 oldPos = args.OldPos;
             
             int oldCellX = (int) (oldPos.x * 1000) / AOIManagerComponent.CellSize;

+ 4 - 5
Apps/Hotfix/Server/Unit/UnitEnterSightRange_NotifyClient.cs

@@ -1,13 +1,12 @@
 namespace ET.Server
 {
     // 进入视野通知
-    [Event]
-    public class UnitEnterSightRange_NotifyClient: AEvent<EventType.UnitEnterSightRange>
+    [Event(SceneType.Map)]
+    public class UnitEnterSightRange_NotifyClient: AEvent<AOIEntity, EventType.UnitEnterSightRange>
     {
-        protected override async ETTask Run(EventType.UnitEnterSightRange args)
+        protected override async ETTask Run(AOIEntity a, EventType.UnitEnterSightRange args)
         {
             await ETTask.CompletedTask;
-            AOIEntity a = args.A;
             AOIEntity b = args.B;
             if (a.Id == b.Id)
             {
@@ -22,7 +21,7 @@
 
             Unit ub = b.GetParent<Unit>();
 
-            Server.UnitHelper.NoticeUnitAdd(ua, ub);
+            UnitHelper.NoticeUnitAdd(ua, ub);
         }
     }
 }

+ 4 - 5
Apps/Hotfix/Server/Unit/UnitLeaveSightRange_NotifyClient.cs

@@ -1,20 +1,19 @@
 namespace ET.Server
 {
     // 离开视野
-    [Event]
-    public class UnitLeaveSightRange_NotifyClient: AEvent<EventType.UnitLeaveSightRange>
+    [Event(SceneType.Map)]
+    public class UnitLeaveSightRange_NotifyClient: AEvent<AOIEntity, EventType.UnitLeaveSightRange>
     {
-        protected override async ETTask Run(EventType.UnitLeaveSightRange args)
+        protected override async ETTask Run(AOIEntity a, EventType.UnitLeaveSightRange args)
         {
             await ETTask.CompletedTask;
-            AOIEntity a = args.A;
             AOIEntity b = args.B;
             if (a.Unit.Type != UnitType.Player)
             {
                 return;
             }
 
-            Server.UnitHelper.NoticeUnitRemove(a.GetParent<Unit>(), b.GetParent<Unit>());
+            UnitHelper.NoticeUnitRemove(a.GetParent<Unit>(), b.GetParent<Unit>());
         }
     }
 }

+ 1 - 1
Apps/Model/Apps.Model.csproj

@@ -2,7 +2,7 @@
   <PropertyGroup>
     <TargetFramework>net6.0</TargetFramework>
     <RootNamespace>ET</RootNamespace>
-    <LangVersion>8</LangVersion>
+    <LangVersion>9</LangVersion>
     <AssemblyName>Model</AssemblyName>
   </PropertyGroup>
   <PropertyGroup>

+ 0 - 2
Apps/Model/Server/EventType.cs

@@ -4,13 +4,11 @@
 	{
 		public struct UnitEnterSightRange
 		{
-			public AOIEntity A;
 			public AOIEntity B;
 		}
 
 		public struct UnitLeaveSightRange
 		{
-			public AOIEntity A;
 			public AOIEntity B;
 		}
 	}

+ 1 - 1
Apps/ThirdParty/Apps.ThirdParty.csproj

@@ -3,7 +3,7 @@
     <PropertyGroup>
         <TargetFramework>net6.0</TargetFramework>
         <Nullable>disable</Nullable>
-        <LangVersion>8</LangVersion>
+        <LangVersion>9</LangVersion>
         <RootNamespace>ETTask</RootNamespace>
         <AssemblyName>ThirdParty</AssemblyName>
     </PropertyGroup>

+ 1 - 1
Apps/Tool/Apps.Tool.csproj

@@ -6,7 +6,7 @@
         <ImplicitUsings>false</ImplicitUsings>
         <Nullable>disable</Nullable>
         <RootNamespace>ET</RootNamespace>
-        <LangVersion>8</LangVersion>
+        <LangVersion>9</LangVersion>
         <PackageId>Apps.Tool</PackageId>
         <AssemblyName>Tool</AssemblyName>
     </PropertyGroup>

+ 1 - 1
Unity/Codes/Hotfix/Client/Login/EnterMapHelper.cs

@@ -15,7 +15,7 @@ namespace ET.Client
                 // 等待场景切换完成
                 await zoneScene.GetComponent<ObjectWait>().Wait<WaitType.Wait_SceneChangeFinish>();
                 
-                Game.EventSystem.Publish(new EventType.EnterMapFinish() {ZoneScene = zoneScene});
+                Game.EventSystem.Publish(zoneScene, new EventType.EnterMapFinish());
             }
             catch (Exception e)
             {

+ 1 - 1
Unity/Codes/Hotfix/Client/Login/LoginHelper.cs

@@ -42,7 +42,7 @@ namespace ET.Client
 
                 Log.Debug("登陆gate成功!");
 
-                await Game.EventSystem.PublishAsync(new EventType.LoginFinish() {ZoneScene = zoneScene});
+                await Game.EventSystem.PublishAsync(zoneScene, new EventType.LoginFinish());
             }
             catch (Exception e)
             {

+ 2 - 2
Unity/Codes/Hotfix/Client/Scene/SceneChangeHelper.cs

@@ -13,7 +13,7 @@
             UnitComponent unitComponent = currentScene.AddComponent<UnitComponent>();
          
             // 可以订阅这个事件中创建Loading界面
-            Game.EventSystem.Publish(new EventType.SceneChangeStart() {ZoneScene = zoneScene});
+            Game.EventSystem.Publish(zoneScene, new EventType.SceneChangeStart());
 
             // 等待CreateMyUnit的消息
             WaitType.Wait_CreateMyUnit waitCreateMyUnit = await zoneScene.GetComponent<ObjectWait>().Wait<WaitType.Wait_CreateMyUnit>();
@@ -23,7 +23,7 @@
             
             zoneScene.RemoveComponent<AIComponent>();
             
-            Game.EventSystem.Publish(new EventType.SceneChangeFinish() {ZoneScene = zoneScene, CurrentScene = currentScene});
+            Game.EventSystem.Publish(currentScene, new EventType.SceneChangeFinish());
 
             // 通知等待场景切换的协程
             zoneScene.GetComponent<ObjectWait>().Notify(new WaitType.Wait_SceneChangeFinish());

+ 2 - 2
Unity/Codes/Hotfix/Client/Scene/SceneFactory.cs

@@ -11,7 +11,7 @@ namespace ET.Client
             zoneScene.AddComponent<ObjectWait>();
             zoneScene.AddComponent<PlayerComponent>();
             
-            Game.EventSystem.Publish(new EventType.AfterCreateZoneScene() {ZoneScene = zoneScene});
+            Game.EventSystem.Publish(zoneScene, new EventType.AfterCreateZoneScene());
             return zoneScene;
         }
         
@@ -20,7 +20,7 @@ namespace ET.Client
             Scene currentScene = EntitySceneFactory.CreateScene(id, IdGenerater.Instance.GenerateInstanceId(), zone, SceneType.Current, name, currentScenesComponent);
             currentScenesComponent.Scene = currentScene;
             
-            Game.EventSystem.Publish(new EventType.AfterCreateCurrentScene() {CurrentScene = currentScene});
+            Game.EventSystem.Publish(currentScene, new EventType.AfterCreateCurrentScene());
             return currentScene;
         }
         

+ 1 - 1
Unity/Codes/Hotfix/Client/Unit/UnitFactory.cs

@@ -41,7 +41,7 @@ namespace ET.Client
 
 	        unit.AddComponent<XunLuoPathComponent>();
 	        
-	        Game.EventSystem.Publish(new EventType.AfterUnitCreate() {Unit = unit});
+	        Game.EventSystem.Publish(unit, new EventType.AfterUnitCreate());
             return unit;
         }
     }

+ 5 - 3
Unity/Codes/Hotfix/Module/Numeric/NumericChangeEvent_NotifyWatcher.cs

@@ -1,11 +1,13 @@
 namespace ET
 {
 	// 分发数值监听
-	public class NumericChangeEvent_NotifyWatcher: AEvent<EventType.NumbericChange>
+	[Event(SceneType.Map)]  // 服务端Map需要分发
+	[Event(SceneType.Current)] // 客户端CurrentScene也要分发
+	public class NumericChangeEvent_NotifyWatcher: AEvent<Unit, EventType.NumbericChange>
 	{
-		protected override async ETTask Run(EventType.NumbericChange args)
+		protected override async ETTask Run(Unit unit, EventType.NumbericChange args)
 		{
-			NumericWatcherComponent.Instance.Run(args);
+			NumericWatcherComponent.Instance.Run(unit, args);
 			await ETTask.CompletedTask;
 		}
 	}

+ 3 - 3
Unity/Codes/Hotfix/Module/Numeric/NumericWatcher_Hp_ShowUI.cs

@@ -1,12 +1,12 @@
 namespace ET
 {
 	/// <summary>
-	/// 监视hp数值变化,改变血条值
+	/// 客户端监视hp数值变化,改变血条值
 	/// </summary>
-	[NumericWatcher(NumericType.Hp)]
+	[NumericWatcher(SceneType.Current, NumericType.Hp)]
 	public class NumericWatcher_Hp_ShowUI : INumericWatcher
 	{
-		public void Run(EventType.NumbericChange args)
+		public void Run(Unit unit, EventType.NumbericChange args)
 		{
 		}
 	}

+ 2 - 2
Unity/Codes/Hotfix/Share/Move/MoveComponentSystem.cs

@@ -97,7 +97,7 @@ namespace ET
             ETTask<bool> tcs = ETTask<bool>.Create(true);
             self.Callback = (ret) => { tcs.SetResult(ret); };
 
-            Game.EventSystem.Publish(new EventType.MoveStart(){Unit = self.GetParent<Unit>()});
+            Game.EventSystem.Publish(self.GetParent<Unit>(), new EventType.MoveStart());
             
             self.StartMove();
             
@@ -119,7 +119,7 @@ namespace ET
 
             if (moveRet)
             {
-                Game.EventSystem.Publish(new EventType.MoveStop(){Unit = self.GetParent<Unit>()});
+                Game.EventSystem.Publish(self.GetParent<Unit>(), new EventType.MoveStop());
             }
             return moveRet;
         }

+ 4 - 3
Unity/Codes/HotfixView/AppStart_Init.cs

@@ -1,8 +1,9 @@
 namespace ET.Client
 {
-    public class AppStart_Init: AEvent<ET.EventType.AppStart>
+    [Event(SceneType.Process)]
+    public class AppStart_Init: AEvent<Scene, EventType.AppStart>
     {
-        protected override async ETTask Run(ET.EventType.AppStart args)
+        protected override async ETTask Run(Scene scene, EventType.AppStart args)
         {
             Game.Scene.AddComponent<TimerComponent>();
             Game.Scene.AddComponent<CoroutineLockComponent>();
@@ -28,7 +29,7 @@ namespace ET.Client
             
             Scene zoneScene = Client.SceneFactory.CreateZoneScene(1, "Game", Game.Scene);
             
-            await Game.EventSystem.PublishAsync(new EventType.AppStartInitFinish() { ZoneScene = zoneScene });
+            await Game.EventSystem.PublishAsync(zoneScene, new EventType.AppStartInitFinish());
         }
     }
 }

+ 5 - 5
Unity/Codes/HotfixView/Client/Scene/AfterCreateCurrentScene_AddComponent.cs

@@ -1,12 +1,12 @@
 namespace ET.Client
 {
-    public class AfterCreateCurrentScene_AddComponent: AEvent<EventType.AfterCreateCurrentScene>
+    [Event(SceneType.Current)]
+    public class AfterCreateCurrentScene_AddComponent: AEvent<Scene, EventType.AfterCreateCurrentScene>
     {
-        protected override async ETTask Run(EventType.AfterCreateCurrentScene args)
+        protected override async ETTask Run(Scene scene, EventType.AfterCreateCurrentScene args)
         {
-            Scene currentScene = args.CurrentScene;
-            currentScene.AddComponent<UIComponent>();
-            currentScene.AddComponent<ResourcesLoaderComponent>();
+            scene.AddComponent<UIComponent>();
+            scene.AddComponent<ResourcesLoaderComponent>();
             await ETTask.CompletedTask;
         }
     }

+ 6 - 6
Unity/Codes/HotfixView/Client/Scene/AfterCreateZoneScene_AddComponent.cs

@@ -1,13 +1,13 @@
 namespace ET.Client
 {
-    public class AfterCreateZoneScene_AddComponent: AEvent<EventType.AfterCreateZoneScene>
+    [Event(SceneType.Zone)]
+    public class AfterCreateZoneScene_AddComponent: AEvent<Scene, EventType.AfterCreateZoneScene>
     {
-        protected override async ETTask Run(EventType.AfterCreateZoneScene args)
+        protected override async ETTask Run(Scene scene, EventType.AfterCreateZoneScene args)
         {
-            Scene zoneScene = args.ZoneScene;
-            zoneScene.AddComponent<UIEventComponent>();
-            zoneScene.AddComponent<UIComponent>();
-            zoneScene.AddComponent<ResourcesLoaderComponent>();
+            scene.AddComponent<UIEventComponent>();
+            scene.AddComponent<UIComponent>();
+            scene.AddComponent<ResourcesLoaderComponent>();
             await ETTask.CompletedTask;
         }
     }

+ 4 - 3
Unity/Codes/HotfixView/Client/Scene/SceneChangeStart_AddComponent.cs

@@ -1,10 +1,11 @@
 namespace ET.Client
 {
-    public class SceneChangeStart_AddComponent: AEvent<EventType.SceneChangeStart>
+    [Event(SceneType.Zone)]
+    public class SceneChangeStart_AddComponent: AEvent<Scene, EventType.SceneChangeStart>
     {
-        protected override async ETTask Run(EventType.SceneChangeStart args)
+        protected override async ETTask Run(Scene scene, EventType.SceneChangeStart args)
         {
-            Scene currentScene = args.ZoneScene.CurrentScene();
+            Scene currentScene = scene.CurrentScene();
             
             // 加载场景资源
             await ResourcesComponent.Instance.LoadBundleAsync($"{currentScene.Name}.unity3d");

+ 4 - 3
Unity/Codes/HotfixView/Client/UI/UIHelp/SceneChangeFinishEvent_CreateUIHelp.cs

@@ -1,10 +1,11 @@
 namespace ET.Client
 {
-    public class SceneChangeFinishEvent_CreateUIHelp : AEvent<EventType.SceneChangeFinish>
+    [Event(SceneType.Current)]
+    public class SceneChangeFinishEvent_CreateUIHelp : AEvent<Scene, EventType.SceneChangeFinish>
     {
-        protected override async ETTask Run(EventType.SceneChangeFinish args)
+        protected override async ETTask Run(Scene scene, EventType.SceneChangeFinish args)
         {
-            await UIHelper.Create(args.CurrentScene, UIType.UIHelp, UILayer.Mid);
+            await UIHelper.Create(scene, UIType.UIHelp, UILayer.Mid);
         }
     }
 }

+ 4 - 3
Unity/Codes/HotfixView/Client/UI/UILoading/LoadingBeginEvent_CreateLoadingUI.cs

@@ -2,11 +2,12 @@
 
 namespace ET.Client
 {
-    public class LoadingBeginEvent_CreateLoadingUI : AEvent<EventType.LoadingBegin>
+    [Event(SceneType.Zone)]
+    public class LoadingBeginEvent_CreateLoadingUI : AEvent<Scene, EventType.LoadingBegin>
     {
-        protected override async ETTask Run(EventType.LoadingBegin args)
+        protected override async ETTask Run(Scene scene, EventType.LoadingBegin args)
         {
-            await UIHelper.Create(args.Scene, UIType.UILoading, UILayer.Mid);
+            await UIHelper.Create(scene, UIType.UILoading, UILayer.Mid);
         }
     }
 }

+ 4 - 3
Unity/Codes/HotfixView/Client/UI/UILoading/LoadingFinishEvent_RemoveLoadingUI.cs

@@ -1,10 +1,11 @@
 namespace ET.Client
 {
-    public class LoadingFinishEvent_RemoveLoadingUI : AEvent<EventType.LoadingFinish>
+    [Event(SceneType.Zone)]
+    public class LoadingFinishEvent_RemoveLoadingUI : AEvent<Scene, EventType.LoadingFinish>
     {
-        protected override async ETTask Run(EventType.LoadingFinish args)
+        protected override async ETTask Run(Scene scene, EventType.LoadingFinish args)
         {
-            await UIHelper.Create(args.Scene, UIType.UILoading, UILayer.Mid);
+            await UIHelper.Create(scene, UIType.UILoading, UILayer.Mid);
         }
     }
 }

+ 5 - 6
Unity/Codes/HotfixView/Client/UI/UILobby/LoginFinish_CreateLobbyUI.cs

@@ -1,12 +1,11 @@
-
-
-namespace ET.Client
+namespace ET.Client
 {
-	public class LoginFinish_CreateLobbyUI: AEvent<EventType.LoginFinish>
+	[Event(SceneType.Zone)]
+	public class LoginFinish_CreateLobbyUI: AEvent<Scene, EventType.LoginFinish>
 	{
-		protected override async ETTask Run(EventType.LoginFinish args)
+		protected override async ETTask Run(Scene scene, EventType.LoginFinish args)
 		{
-			await UIHelper.Create(args.ZoneScene, UIType.UILobby, UILayer.Mid);
+			await UIHelper.Create(scene, UIType.UILobby, UILayer.Mid);
 		}
 	}
 }

+ 5 - 6
Unity/Codes/HotfixView/Client/UI/UILogin/AppStartInitFinish_CreateLoginUI.cs

@@ -1,12 +1,11 @@
-
-
-namespace ET.Client
+namespace ET.Client
 {
-	public class AppStartInitFinish_CreateLoginUI: AEvent<EventType.AppStartInitFinish>
+	[Event(SceneType.Zone)]
+	public class AppStartInitFinish_CreateLoginUI: AEvent<Scene, EventType.AppStartInitFinish>
 	{
-		protected override async ETTask Run(EventType.AppStartInitFinish args)
+		protected override async ETTask Run(Scene scene, EventType.AppStartInitFinish args)
 		{
-			await UIHelper.Create(args.ZoneScene, UIType.UILogin, UILayer.Mid);
+			await UIHelper.Create(scene, UIType.UILogin, UILayer.Mid);
 		}
 	}
 }

+ 5 - 6
Unity/Codes/HotfixView/Client/UI/UILogin/LoginFinish_RemoveLoginUI.cs

@@ -1,12 +1,11 @@
-
-
-namespace ET.Client
+namespace ET.Client
 {
-	public class LoginFinish_RemoveLoginUI: AEvent<EventType.LoginFinish>
+	[Event(SceneType.Zone)]
+	public class LoginFinish_RemoveLoginUI: AEvent<Scene, EventType.LoginFinish>
 	{
-		protected override async ETTask Run(EventType.LoginFinish args)
+		protected override async ETTask Run(Scene scene, EventType.LoginFinish args)
 		{
-			await UIHelper.Remove(args.ZoneScene, UIType.UILogin);
+			await UIHelper.Remove(scene, UIType.UILogin);
 		}
 	}
 }

+ 6 - 5
Unity/Codes/HotfixView/Client/Unit/AfterUnitCreate_CreateUnitView.cs

@@ -2,9 +2,10 @@
 
 namespace ET.Client
 {
-    public class AfterUnitCreate_CreateUnitView: AEvent<EventType.AfterUnitCreate>
+    [Event(SceneType.Current)]
+    public class AfterUnitCreate_CreateUnitView: AEvent<Unit, EventType.AfterUnitCreate>
     {
-        protected override async ETTask Run(EventType.AfterUnitCreate args)
+        protected override async ETTask Run(Unit unit, EventType.AfterUnitCreate args)
         {
             // Unit View层
             // 这里可以改成异步加载,demo就不搞了
@@ -12,9 +13,9 @@ namespace ET.Client
             GameObject prefab = bundleGameObject.Get<GameObject>("Skeleton");
 	        
             GameObject go = UnityEngine.Object.Instantiate(prefab, GlobalComponent.Instance.Unit, true);
-            go.transform.position = args.Unit.Position;
-            args.Unit.AddComponent<GameObjectComponent>().GameObject = go;
-            args.Unit.AddComponent<AnimatorComponent>();
+            go.transform.position = unit.Position;
+            unit.AddComponent<GameObjectComponent>().GameObject = go;
+            unit.AddComponent<AnimatorComponent>();
             await ETTask.CompletedTask;
         }
     }

+ 5 - 4
Unity/Codes/HotfixView/Client/Unit/ChangePosition_SyncGameObjectPos.cs

@@ -2,17 +2,18 @@
 
 namespace ET.Client
 {
-    public class ChangePosition_SyncGameObjectPos: AEvent<EventType.ChangePosition>
+    [Event(SceneType.Current)]
+    public class ChangePosition_SyncGameObjectPos: AEvent<Unit, EventType.ChangePosition>
     {
-        protected override async ETTask Run(EventType.ChangePosition args)
+        protected override async ETTask Run(Unit unit, EventType.ChangePosition args)
         {
-            GameObjectComponent gameObjectComponent = args.Unit.GetComponent<GameObjectComponent>();
+            GameObjectComponent gameObjectComponent = unit.GetComponent<GameObjectComponent>();
             if (gameObjectComponent == null)
             {
                 return;
             }
             Transform transform = gameObjectComponent.GameObject.transform;
-            transform.position = args.Unit.Position;
+            transform.position = unit.Position;
             await ETTask.CompletedTask;
         }
     }

+ 5 - 4
Unity/Codes/HotfixView/Client/Unit/ChangeRotation_SyncGameObjectRotation.cs

@@ -2,17 +2,18 @@ using UnityEngine;
 
 namespace ET.Client
 {
-    public class ChangeRotation_SyncGameObjectRotation: AEvent<EventType.ChangeRotation>
+    [Event(SceneType.Current)]
+    public class ChangeRotation_SyncGameObjectRotation: AEvent<Unit, EventType.ChangeRotation>
     {
-        protected override async ETTask Run(EventType.ChangeRotation args)
+        protected override async ETTask Run(Unit unit, EventType.ChangeRotation args)
         {
-            GameObjectComponent gameObjectComponent = args.Unit.GetComponent<GameObjectComponent>();
+            GameObjectComponent gameObjectComponent = unit.GetComponent<GameObjectComponent>();
             if (gameObjectComponent == null)
             {
                 return;
             }
             Transform transform = gameObjectComponent.GameObject.transform;
-            transform.rotation = args.Unit.Rotation;
+            transform.rotation = unit.Rotation;
             await ETTask.CompletedTask;
         }
     }

+ 6 - 0
Unity/Codes/Model/Core/Event/EventAttribute.cs

@@ -5,5 +5,11 @@ namespace ET
 	[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
 	public class EventAttribute: BaseAttribute
 	{
+		public SceneType SceneType { get; }
+
+		public EventAttribute(SceneType sceneType)
+		{
+			this.SceneType = sceneType;
+		}
 	}
 }

+ 4 - 5
Unity/Codes/Model/Core/Event/IEvent.cs

@@ -7,21 +7,20 @@ namespace ET
 		Type GetEventType();
 	}
 	
-	[Event]
-	public abstract class AEvent<A>: IEvent where A: struct
+	public abstract class AEvent<E, A>: IEvent where E: Entity where A: struct
 	{
 		public Type GetEventType()
 		{
 			return typeof (A);
 		}
 
-		protected abstract ETTask Run(A a);
+		protected abstract ETTask Run(E entity, A a);
 
-		public async ETTask Handle(A a)
+		public async ETTask Handle(E entity, A a)
 		{
 			try
 			{
-				await Run(a);
+				await Run(entity, a);
 			}
 			catch (Exception e)
 			{

+ 66 - 32
Unity/Codes/Model/Core/Object/EventSystem.cs

@@ -12,7 +12,7 @@ namespace ET
     {
         private class TypeSystems
         {
-            private readonly Dictionary<Type, OneTypeSystems> typeSystemsMap = new Dictionary<Type, OneTypeSystems>();
+            private readonly Dictionary<Type, OneTypeSystems> typeSystemsMap = new();
 
             public OneTypeSystems GetOrCreateOneTypeSystems(Type type)
             {
@@ -52,6 +52,19 @@ namespace ET
             }
         }
 
+        private class EventInfo
+        {
+            public IEvent IEvent { get; }
+            
+            public SceneType SceneType {get; }
+
+            public EventInfo(IEvent iEvent, SceneType sceneType)
+            {
+                this.IEvent = iEvent;
+                this.SceneType = sceneType;
+            }
+        }
+
         private static EventSystem instance;
 
         public static EventSystem Instance
@@ -67,26 +80,26 @@ namespace ET
             }
         }
 
-        private readonly Dictionary<long, Entity> allEntities = new Dictionary<long, Entity>();
+        private readonly Dictionary<long, Entity> allEntities = new();
 
-        private readonly Dictionary<string, Assembly> assemblies = new Dictionary<string, Assembly>();
+        private readonly Dictionary<string, Assembly> assemblies = new();
 
-        private readonly Dictionary<string, Type> allTypes = new Dictionary<string, Type>();
+        private readonly Dictionary<string, Type> allTypes = new();
 
-        private readonly UnOrderMultiMapSet<Type, Type> types = new UnOrderMultiMapSet<Type, Type>();
+        private readonly UnOrderMultiMapSet<Type, Type> types = new();
 
-        private readonly Dictionary<Type, List<object>> allEvents = new Dictionary<Type, List<object>>();
+        private readonly Dictionary<Type, List<EventInfo>> allEvents = new();
 
-        private TypeSystems typeSystems = new TypeSystems();
+        private TypeSystems typeSystems = new();
 
-        private Queue<long> updates = new Queue<long>();
-        private Queue<long> updates2 = new Queue<long>();
+        private Queue<long> updates = new();
+        private Queue<long> updates2 = new();
 
-        private Queue<long> loaders = new Queue<long>();
-        private Queue<long> loaders2 = new Queue<long>();
+        private Queue<long> loaders = new();
+        private Queue<long> loaders2 = new();
 
-        private Queue<long> lateUpdates = new Queue<long>();
-        private Queue<long> lateUpdates2 = new Queue<long>();
+        private Queue<long> lateUpdates = new();
+        private Queue<long> lateUpdates2 = new();
 
         private EventSystem()
         {
@@ -161,14 +174,22 @@ namespace ET
                 {
                     throw new Exception($"type not is AEvent: {type.Name}");
                 }
-
-                Type eventType = obj.GetEventType();
-                if (!this.allEvents.ContainsKey(eventType))
+                
+                object[] attrs = type.GetCustomAttributes(typeof(EventAttribute), false);
+                foreach (object attr in attrs)
                 {
-                    this.allEvents.Add(eventType, new List<object>());
-                }
+                    EventAttribute eventAttribute = attr as EventAttribute;
+
+                    Type eventType = obj.GetEventType();
+
+                    EventInfo eventInfo = new(obj, eventAttribute.SceneType);
 
-                this.allEvents[eventType].Add(obj);
+                    if (!this.allEvents.ContainsKey(eventType))
+                    {
+                        this.allEvents.Add(eventType, new List<EventInfo>());
+                    }
+                    this.allEvents[eventType].Add(eventInfo);
+                }
             }
         }
 
@@ -617,9 +638,9 @@ namespace ET
             ObjectHelper.Swap(ref this.lateUpdates, ref this.lateUpdates2);
         }
 
-        public async ETTask PublishAsync<T>(T a) where T : struct
+        public async ETTask PublishAsync<E, T>(E entity, T a) where E: Entity where T : struct
         {
-            List<object> iEvents;
+            List<EventInfo> iEvents;
             if (!this.allEvents.TryGetValue(typeof(T), out iEvents))
             {
                 return;
@@ -627,15 +648,20 @@ namespace ET
 
             using (ListComponent<ETTask> list = ListComponent<ETTask>.Create())
             {
-                foreach (object obj in iEvents)
+                foreach (EventInfo eventInfo in iEvents)
                 {
-                    if (!(obj is AEvent<T> aEvent))
+                    if (entity.DomainScene().SceneType != eventInfo.SceneType)
+                    {
+                        continue;
+                    }
+                    
+                    if (!(eventInfo.IEvent is AEvent<E, T> aEvent))
                     {
-                        Log.Error($"event error: {obj.GetType().Name}");
+                        Log.Error($"event error: {eventInfo.IEvent.GetType().Name}");
                         continue;
                     }
 
-                    list.Add(aEvent.Handle(a));
+                    list.Add(aEvent.Handle(entity, a));
                 }
 
                 try
@@ -649,28 +675,36 @@ namespace ET
             }
         }
 
-        public void Publish<T>(T a) where T : struct
+        public void Publish<E, T>(E entity, T a) where E: Entity where T : struct
         {
-            List<object> iEvents;
+            List<EventInfo> iEvents;
             if (!this.allEvents.TryGetValue(typeof (T), out iEvents))
             {
                 return;
             }
 
-            foreach (object obj in iEvents)
+            SceneType sceneType = entity.DomainScene().SceneType;
+            foreach (EventInfo eventInfo in iEvents)
             {
-                if (!(obj is AEvent<T> aEvent))
+                if (sceneType != eventInfo.SceneType)
+                {
+                    continue;
+                }
+
+                
+                if (!(eventInfo.IEvent is AEvent<E, T> aEvent))
                 {
-                    Log.Error($"event error: {obj.GetType().Name}");
+                    Log.Error($"event error: {eventInfo.IEvent.GetType().Name}");
                     continue;
                 }
-                aEvent.Handle(a).Coroutine();
+                
+                aEvent.Handle(entity, a).Coroutine();
             }
         }
 
         public override string ToString()
         {
-            StringBuilder sb = new StringBuilder();
+            StringBuilder sb = new();
             HashSet<Type> noParent = new HashSet<Type>();
             Dictionary<Type, int> typeCount = new Dictionary<Type, int>();
 

+ 1 - 1
Unity/Codes/Model/Module/Numeric/INumericWatcher.cs

@@ -2,6 +2,6 @@
 {
 	public interface INumericWatcher
 	{
-		void Run(EventType.NumbericChange args);
+		void Run(Unit unit, EventType.NumbericChange args);
 	}
 }

+ 1 - 2
Unity/Codes/Model/Module/Numeric/NumericComponent.cs

@@ -9,7 +9,6 @@ namespace ET
 	{
 		public struct NumbericChange
 		{
-			public Entity Parent;
 			public int NumericType;
 			public long Old;
 			public long New;
@@ -72,7 +71,7 @@ namespace ET
 
 			if (isPublicEvent)
 			{
-				Game.EventSystem.Publish(new NumbericChange() {New = value, Old = oldValue, Parent = self.Parent, NumericType = numericType});
+				Game.EventSystem.Publish(self.GetParent<Unit>(), new NumbericChange() {New = value, Old = oldValue, NumericType = numericType});
 			}
 		}
 		

+ 4 - 1
Unity/Codes/Model/Module/Numeric/NumericWatcherAttribute.cs

@@ -2,10 +2,13 @@
 {
 	public class NumericWatcherAttribute : BaseAttribute
 	{
+		public SceneType SceneType { get; }
+		
 		public int NumericType { get; }
 
-		public NumericWatcherAttribute(int type)
+		public NumericWatcherAttribute(SceneType sceneType, int type)
 		{
+			this.SceneType = sceneType;
 			this.NumericType = type;
 		}
 	}

+ 27 - 8
Unity/Codes/Model/Module/Numeric/NumericWatcherComponent.cs

@@ -27,7 +27,7 @@ namespace ET
 
         private static void Init(this NumericWatcherComponent self)
         {
-            self.allWatchers = new Dictionary<int, List<INumericWatcher>>();
+            self.allWatchers = new Dictionary<int, List<NumericWatcherInfo>>();
 
             HashSet<Type> types = Game.EventSystem.GetTypes(typeof(NumericWatcherAttribute));
             foreach (Type type in types)
@@ -38,28 +38,47 @@ namespace ET
                 {
                     NumericWatcherAttribute numericWatcherAttribute = (NumericWatcherAttribute)attr;
                     INumericWatcher obj = (INumericWatcher)Activator.CreateInstance(type);
+                    NumericWatcherInfo numericWatcherInfo = new NumericWatcherInfo(numericWatcherAttribute.SceneType, obj);
                     if (!self.allWatchers.ContainsKey(numericWatcherAttribute.NumericType))
                     {
-                        self.allWatchers.Add(numericWatcherAttribute.NumericType, new List<INumericWatcher>());
+                        self.allWatchers.Add(numericWatcherAttribute.NumericType, new List<NumericWatcherInfo>());
                     }
-                    self.allWatchers[numericWatcherAttribute.NumericType].Add(obj);
+                    self.allWatchers[numericWatcherAttribute.NumericType].Add(numericWatcherInfo);
                 }
             }
         }
 
-        public static void Run(this NumericWatcherComponent self, EventType.NumbericChange args)
+        public static void Run(this NumericWatcherComponent self, Unit unit, EventType.NumbericChange args)
         {
-            List<INumericWatcher> list;
+            List<NumericWatcherInfo> list;
             if (!self.allWatchers.TryGetValue(args.NumericType, out list))
             {
                 return;
             }
-            foreach (INumericWatcher numericWatcher in list)
+
+            SceneType unitDomainSceneType = unit.DomainScene().SceneType;
+            foreach (NumericWatcherInfo numericWatcher in list)
             {
-                numericWatcher.Run(args);
+                if (numericWatcher.SceneType != unitDomainSceneType)
+                {
+                    continue;
+                }
+                numericWatcher.INumericWatcher.Run(unit, args);
             }
         }
     }
+
+    public class NumericWatcherInfo
+    {
+        public SceneType SceneType { get; }
+        public INumericWatcher INumericWatcher { get; }
+
+        public NumericWatcherInfo(SceneType sceneType, INumericWatcher numericWatcher)
+        {
+            this.SceneType = sceneType;
+            this.INumericWatcher = numericWatcher;
+        }
+    }
     
     
     /// <summary>
@@ -69,6 +88,6 @@ namespace ET
     {
         public static NumericWatcherComponent Instance { get; set; }
 		
-        public Dictionary<int, List<INumericWatcher>> allWatchers;
+        public Dictionary<int, List<NumericWatcherInfo>> allWatchers;
     }
 }

+ 0 - 19
Unity/Codes/Model/Share/EventType.cs

@@ -10,88 +10,69 @@ namespace ET
 		
         public struct MoveStart
         {
-            public Unit Unit;
         }
 
         public struct MoveStop
         {
-            public Unit Unit;
         }
         
         public struct SceneChangeStart
         {
-            public Scene ZoneScene;
         }
         
         
         public struct SceneChangeFinish
         {
-            public Scene ZoneScene;
-            public Scene CurrentScene;
         }
 
         public struct ChangePosition
         {
-            public Unit Unit;
             public Vector3 OldPos;
         }
 
         public struct ChangeRotation
         {
-            public Unit Unit;
         }
 
         public struct PingChange
         {
-            public Scene ZoneScene;
             public long Ping;
         }
         
         public struct AfterCreateZoneScene
         {
-            public Scene ZoneScene;
         }
         
         public struct AfterCreateCurrentScene
         {
-            public Scene CurrentScene;
         }
         
         public struct AfterCreateLoginScene
         {
-            public Scene LoginScene;
         }
 
         public struct AppStartInitFinish
         {
-            public Scene ZoneScene;
         }
 
         public struct LoginFinish
         {
-            public Scene ZoneScene;
         }
 
         public struct LoadingBegin
         {
-            public Scene Scene;
         }
 
         public struct LoadingFinish
         {
-            public Scene Scene;
         }
 
         public struct EnterMapFinish
         {
-            public Scene ZoneScene;
         }
 
         public struct AfterUnitCreate
         {
-            public Unit Unit;
         }
-        
-
     }
 }

+ 2 - 2
Unity/Codes/Model/Share/Unit/Unit.cs

@@ -23,7 +23,7 @@ namespace ET
             {
                 Vector3 oldPos = this.position;
                 this.position = value;
-                Game.EventSystem.Publish(new EventType.ChangePosition() { Unit = this, OldPos = oldPos });
+                Game.EventSystem.Publish(this, new EventType.ChangePosition() { OldPos = oldPos });
             }
         }
 
@@ -44,7 +44,7 @@ namespace ET
             set
             {
                 this.rotation = value;
-                Game.EventSystem.Publish(new EventType.ChangeRotation() {Unit = this});
+                Game.EventSystem.Publish(this, new EventType.ChangeRotation());
             }
         }
     }

+ 1 - 1
Unity/Codes/ModelView/Client/Entry.cs

@@ -16,7 +16,7 @@ namespace ET.Client
 				Game.EventSystem.Add(CodeLoader.Instance.GetTypes());
 
 				
-				Game.EventSystem.Publish(new EventType.AppStart());
+				Game.EventSystem.Publish(Game.Scene, new EventType.AppStart());
 			}
 			catch (Exception e)
 			{