Przeglądaj źródła

SceneType做成Flag更加合适,监听事件可以[Event(SceneType.Map | SceneType.Current)]这样操作

tanghai 2 lat temu
rodzic
commit
9e72565cb7

+ 1 - 1
Unity/Assets/Scripts/Codes/Hotfix/Share/Module/Numeric/NumericChangeEvent_NotifyWatcher.cs

@@ -1,7 +1,7 @@
 namespace ET
 {
 	// 分发数值监听
-	[Event(SceneType.None)]  // 服务端Map需要分发, 客户端CurrentScene也要分发
+	[Event(SceneType.All)]  // 服务端Map需要分发, 客户端CurrentScene也要分发
 	public class NumericChangeEvent_NotifyWatcher: AEvent<EventType.NumbericChange>
 	{
 		protected override async ETTask Run(Scene scene, EventType.NumbericChange args)

+ 22 - 18
Unity/Assets/Scripts/Core/Module/Entity/SceneType.cs

@@ -1,24 +1,28 @@
-namespace ET
+using System;
+
+namespace ET
 {
-	public enum SceneType
+	[Flags]
+	public enum SceneType: ulong
 	{
-		None = -1,
-		Process = 0,
-		Manager = 1,
-		Realm = 2,
-		Gate = 3,
-		Http = 4,
-		Location = 5,
-		Map = 6,
-		Router = 7,
-		RouterManager = 8,
-		Robot = 9,
-		BenchmarkClient = 10,
-		BenchmarkServer = 11,
-		Benchmark = 12,
+		None = 0,
+		Process = 1,
+		Manager = 1 << 2,
+		Realm = 1 << 3,
+		Gate = 1 << 4,
+		Http = 1 << 5,
+		Location = 1 << 6,
+		Map = 1 << 7,
+		Router = 1 << 8,
+		RouterManager = 1 << 9,
+		Robot = 1 << 10,
+		BenchmarkClient = 1 << 11,
+		BenchmarkServer = 1 << 12,
+		Benchmark = 1 << 13,
 
 		// 客户端Model层
-		Client = 31,
-		Current = 34,
+		Client = 1 << 30,
+		Current = 1ul << 31,
+		All = ulong.MaxValue,
 	}
 }

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

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

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

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

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

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