tanghai 2 rokov pred
rodič
commit
9f48ca6164

+ 5 - 5
Unity/Assets/Scripts/Core/World/Module/EventSystem/EventSystem.cs

@@ -21,7 +21,7 @@ namespace ET
         
         private readonly Dictionary<Type, List<EventInfo>> allEvents = new();
         
-        private Dictionary<Type, Dictionary<long, object>> allInvokes = new(); 
+        private readonly Dictionary<Type, Dictionary<long, object>> allInvokers = new(); 
         
         public void Awake()
         {
@@ -63,10 +63,10 @@ namespace ET
                 object[] attrs = type.GetCustomAttributes(typeof(InvokeAttribute), false);
                 foreach (object attr in attrs)
                 {
-                    if (!this.allInvokes.TryGetValue(iInvoke.Type, out var dict))
+                    if (!this.allInvokers.TryGetValue(iInvoke.Type, out var dict))
                     {
                         dict = new Dictionary<long, object>();
-                        this.allInvokes.Add(iInvoke.Type, dict);
+                        this.allInvokers.Add(iInvoke.Type, dict);
                     }
                     
                     InvokeAttribute invokeAttribute = attr as InvokeAttribute;
@@ -153,7 +153,7 @@ namespace ET
         // publish是事件,抛出去可以没人订阅,调用者跟被调用者属于两个模块,比如任务系统需要知道道具使用的信息,则订阅道具使用事件
         public void Invoke<A>(long type, A args) where A: struct
         {
-            if (!this.allInvokes.TryGetValue(typeof(A), out var invokeHandlers))
+            if (!this.allInvokers.TryGetValue(typeof(A), out var invokeHandlers))
             {
                 throw new Exception($"Invoke error1: {type} {typeof(A).FullName}");
             }
@@ -173,7 +173,7 @@ namespace ET
         
         public T Invoke<A, T>(long type, A args) where A: struct
         {
-            if (!this.allInvokes.TryGetValue(typeof(A), out var invokeHandlers))
+            if (!this.allInvokers.TryGetValue(typeof(A), out var invokeHandlers))
             {
                 throw new Exception($"Invoke error4: {type} {typeof(A).FullName}");
             }

+ 22 - 13
Unity/Assets/Scripts/Core/World/Module/Log/FiberLog.cs

@@ -10,19 +10,11 @@ namespace ET
         private const int InfoLevel = 3;
         private const int WarningLevel = 4;
         
-        private static bool CheckLogLevel(int level)
-        {
-            if (Options.Instance == null)
-            {
-                return true;
-            }
-            return Options.Instance.LogLevel <= level;
-        }
         
         [Conditional("DEBUG")]
         public static void Debug(this Fiber self, string msg)
         {
-            if (!CheckLogLevel(DebugLevel))
+            if (Options.Instance.LogLevel > DebugLevel)
             {
                 return;
             }
@@ -32,7 +24,7 @@ namespace ET
         [Conditional("DEBUG")]
         public static void Trace(this Fiber self, string msg)
         {
-            if (!CheckLogLevel(TraceLevel))
+            if (Options.Instance.LogLevel > TraceLevel)
             {
                 return;
             }
@@ -42,7 +34,7 @@ namespace ET
 
         public static void Info(this Fiber self, string msg)
         {
-            if (!CheckLogLevel(InfoLevel))
+            if (Options.Instance.LogLevel > InfoLevel)
             {
                 return;
             }
@@ -51,7 +43,7 @@ namespace ET
 
         public static void TraceInfo(this Fiber self, string msg)
         {
-            if (!CheckLogLevel(InfoLevel))
+            if (Options.Instance.LogLevel > InfoLevel)
             {
                 return;
             }
@@ -60,7 +52,7 @@ namespace ET
 
         public static void Warning(this Fiber self, string msg)
         {
-            if (!CheckLogLevel(WarningLevel))
+            if (Options.Instance.LogLevel > WarningLevel)
             {
                 return;
             }
@@ -91,21 +83,38 @@ namespace ET
         [Conditional("DEBUG")]
         public static void Trace(this Fiber self, ref System.Runtime.CompilerServices.DefaultInterpolatedStringHandler message)
         {
+            if (Options.Instance.LogLevel > TraceLevel)
+            {
+                return;
+            }
             self.Log.Trace(ref message);
         }
         [Conditional("DEBUG")]
         public static void Warning(this Fiber self, ref System.Runtime.CompilerServices.DefaultInterpolatedStringHandler message)
         {
+            if (Options.Instance.LogLevel > WarningLevel)
+            {
+                return;
+            }
             self.Log.Warning(ref message);
         }
 
         public static void Info(this Fiber self, ref System.Runtime.CompilerServices.DefaultInterpolatedStringHandler message)
         {
+            if (Options.Instance.LogLevel > InfoLevel)
+            {
+                return;
+            }
             self.Log.Info(ref message);
         }
+        
         [Conditional("DEBUG")]
         public static void Debug(this Fiber self, ref System.Runtime.CompilerServices.DefaultInterpolatedStringHandler message)
         {
+            if (Options.Instance.LogLevel > DebugLevel)
+            {
+                return;
+            }
             self.Log.Debug(ref message);
         }
 

+ 21 - 14
Unity/Assets/Scripts/Core/World/Module/Log/Log.cs

@@ -10,19 +10,11 @@ namespace ET
         private const int InfoLevel = 3;
         private const int WarningLevel = 4;
         
-        private static bool CheckLogLevel(int level)
-        {
-            if (Options.Instance == null)
-            {
-                return true;
-            }
-            return Options.Instance.LogLevel <= level;
-        }
         
         [Conditional("DEBUG")]
         public static void Debug(string msg)
         {
-            if (!CheckLogLevel(DebugLevel))
+            if (Options.Instance.LogLevel > DebugLevel)
             {
                 return;
             }
@@ -32,7 +24,7 @@ namespace ET
         [Conditional("DEBUG")]
         public static void Trace(string msg)
         {
-            if (!CheckLogLevel(TraceLevel))
+            if (Options.Instance.LogLevel > TraceLevel)
             {
                 return;
             }
@@ -42,7 +34,7 @@ namespace ET
 
         public static void Info(string msg)
         {
-            if (!CheckLogLevel(InfoLevel))
+            if (Options.Instance.LogLevel > InfoLevel)
             {
                 return;
             }
@@ -51,7 +43,7 @@ namespace ET
 
         public static void TraceInfo(string msg)
         {
-            if (!CheckLogLevel(InfoLevel))
+            if (Options.Instance.LogLevel > InfoLevel)
             {
                 return;
             }
@@ -61,11 +53,10 @@ namespace ET
 
         public static void Warning(string msg)
         {
-            if (!CheckLogLevel(WarningLevel))
+            if (Options.Instance.LogLevel > WarningLevel)
             {
                 return;
             }
-
             Logger.Instance.Log.Warning(msg);
         }
 
@@ -93,21 +84,37 @@ namespace ET
         [Conditional("DEBUG")]
         public static void Trace(ref System.Runtime.CompilerServices.DefaultInterpolatedStringHandler message)
         {
+            if (Options.Instance.LogLevel > TraceLevel)
+            {
+                return;
+            }
             Logger.Instance.Log.Trace(ref message);
         }
         [Conditional("DEBUG")]
         public static void Warning(ref System.Runtime.CompilerServices.DefaultInterpolatedStringHandler message)
         {
+            if (Options.Instance.LogLevel > WarningLevel)
+            {
+                return;
+            }
             Logger.Instance.Log.Warning(ref message);
         }
 
         public static void Info(ref System.Runtime.CompilerServices.DefaultInterpolatedStringHandler message)
         {
+            if (Options.Instance.LogLevel > InfoLevel)
+            {
+                return;
+            }
             Logger.Instance.Log.Info(ref message);
         }
         [Conditional("DEBUG")]
         public static void Debug(ref System.Runtime.CompilerServices.DefaultInterpolatedStringHandler message)
         {
+            if (Options.Instance.LogLevel > DebugLevel)
+            {
+                return;
+            }
             Logger.Instance.Log.Debug(ref message);
         }