Просмотр исходного кода

各种事件都用Flag的SceneType标记,根据Flag处理事件

tanghai 2 лет назад
Родитель
Сommit
1742a38ad6

+ 1 - 1
Unity/Assets/Scripts/Codes/Hotfix/Server/Demo/Scenes/Gate/C2G_LoginGateHandler.cs

@@ -21,7 +21,7 @@ namespace ET.Server
 
 			PlayerComponent playerComponent = scene.GetComponent<PlayerComponent>();
 			Player player = playerComponent.AddChild<Player, string>(account);
-			player.AddComponent<SessionInfoComponent>().Session = session;
+			player.AddComponent<PlayerSessionComponent>().Session = session;
 			player.AddComponent<MailBoxComponent, MailboxType>(MailboxType.GateSession);
 			await player.AddLocation(LocationType.Player);
 			

+ 1 - 1
Unity/Assets/Scripts/Codes/Hotfix/Server/Module/Actor/ActorHandleHelper.cs

@@ -128,7 +128,7 @@ namespace ET.Server
                 {
                     if (entity is Player player)
                     {
-                        player.GetComponent<SessionInfoComponent>()?.Session?.Send(iActorMessage);
+                        player.GetComponent<PlayerSessionComponent>()?.Session?.Send(iActorMessage);
                     }
                     break;
                 }

+ 1 - 1
Unity/Assets/Scripts/Codes/Hotfix/Server/Module/Actor/ActorMessageDispatcherComponentSystem.cs

@@ -104,7 +104,7 @@ namespace ET.Server
             SceneType sceneType = entity.DomainScene().SceneType;
             foreach (ActorMessageDispatcherInfo actorMessageDispatcherInfo in list)
             {
-                if (actorMessageDispatcherInfo.SceneType != sceneType)
+                if (!actorMessageDispatcherInfo.SceneType.HasSameFlag(sceneType))
                 {
                     continue;
                 }

+ 1 - 1
Unity/Assets/Scripts/Codes/Hotfix/Share/Module/Message/MessageDispatcherComponentSystem.cs

@@ -97,7 +97,7 @@ namespace ET
             SceneType sceneType = session.DomainScene().SceneType;
             foreach (MessageDispatcherInfo ev in actions)
             {
-                if (ev.SceneType != sceneType)
+                if (!ev.SceneType.HasSameFlag(sceneType))
                 {
                     continue;
                 }

+ 1 - 1
Unity/Assets/Scripts/Codes/Model/Server/Demo/Gate/SessionInfoComponent.cs → Unity/Assets/Scripts/Codes/Model/Server/Demo/Gate/PlayerSessionComponent.cs

@@ -1,7 +1,7 @@
 namespace ET.Server
 {
 	[ComponentOf(typeof(Player))]
-	public class SessionInfoComponent : Entity, IAwake
+	public class PlayerSessionComponent : Entity, IAwake
 	{
 		private long sessionInstanceId;
 

+ 1 - 1
Unity/Assets/Scripts/Codes/Model/Server/Demo/Gate/SessionInfoComponent.cs.meta → Unity/Assets/Scripts/Codes/Model/Server/Demo/Gate/PlayerSessionComponent.cs.meta

@@ -1,5 +1,5 @@
 fileFormatVersion: 2
-guid: a408bcdde79d9fb43a8418227d4297bc
+guid: 237648d5968a24ebb885807879f8382d
 MonoImporter:
   externalObjects: {}
   serializedVersion: 2

+ 4 - 1
Unity/Assets/Scripts/Codes/Model/Server/Module/Actor/ActorMessageHandlerAttribute.cs

@@ -1,5 +1,8 @@
-namespace ET.Server
+using System;
+
+namespace ET.Server
 {
+    [AttributeUsage(AttributeTargets.Class)]
     public class ActorMessageHandlerAttribute: BaseAttribute
     {
         public SceneType SceneType { get; }

+ 4 - 1
Unity/Assets/Scripts/Codes/Model/Share/Module/Message/MessageHandlerAttribute.cs

@@ -1,5 +1,8 @@
-namespace ET
+using System;
+
+namespace ET
 {
+    [AttributeUsage(AttributeTargets.Class)]
     public class MessageHandlerAttribute: BaseAttribute
     {
         public SceneType SceneType { get; }

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

@@ -1,5 +1,8 @@
-namespace ET
+using System;
+
+namespace ET
 {
+	[AttributeUsage(AttributeTargets.Class)]
 	public class NumericWatcherAttribute : BaseAttribute
 	{
 		public SceneType SceneType { get; }

+ 1 - 1
Unity/Assets/Scripts/Codes/Model/Share/Module/Numeric/NumericWatcherComponent.cs

@@ -59,7 +59,7 @@ namespace ET
             SceneType unitDomainSceneType = unit.DomainScene().SceneType;
             foreach (NumericWatcherInfo numericWatcher in list)
             {
-                if (numericWatcher.SceneType != unitDomainSceneType)
+                if (!numericWatcher.SceneType.HasSameFlag(unitDomainSceneType))
                 {
                     continue;
                 }

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

@@ -25,4 +25,16 @@ namespace ET
 		Current = 1ul << 31,
 		All = ulong.MaxValue,
 	}
+
+	public static class SceneTypeHelper
+	{
+		public static bool HasSameFlag(this SceneType a, SceneType b)
+		{
+			if (((ulong) a & (ulong) b) == 0)
+			{
+				return false;
+			}
+			return true;
+		}
+	}
 }

+ 2 - 2
Unity/Assets/Scripts/Core/Module/EventSystem/EventSystem.cs

@@ -609,7 +609,7 @@ namespace ET
             
             foreach (EventInfo eventInfo in iEvents)
             {
-                if (((ulong)scene.SceneType & (ulong)eventInfo.SceneType) == 0)
+                if (!scene.SceneType.HasSameFlag(eventInfo.SceneType))
                 {
                     continue;
                 }
@@ -644,7 +644,7 @@ namespace ET
             SceneType sceneType = scene.SceneType;
             foreach (EventInfo eventInfo in iEvents)
             {
-                if (((ulong)sceneType & (ulong)eventInfo.SceneType) == 0)
+                if (!sceneType.HasSameFlag(eventInfo.SceneType))
                 {
                     continue;
                 }

+ 1 - 1
Unity/Assets/Scripts/Core/Module/EventSystem/ObjectSystemAttribute.cs

@@ -2,7 +2,7 @@
 
 namespace ET
 {
-	[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
+	[AttributeUsage(AttributeTargets.Class)]
 	public class ObjectSystemAttribute: BaseAttribute
 	{
 	}