Prechádzať zdrojové kódy

【优化】计时器为0的话,minTime要设置为long.MaxValue

johnclot69 1 rok pred
rodič
commit
22fcb8cbfd

+ 10 - 5
Unity/Assets/Scripts/Core/Module/Timer/TimerComponent.cs

@@ -25,7 +25,7 @@ namespace ET
         }
 
         public long Id;
-        
+
         public TimerClass TimerClass;
 
         public object Object;
@@ -35,7 +35,7 @@ namespace ET
         public long Time;
 
         public int Type;
-        
+
         public void Recycle()
         {
             this.Id = 0;
@@ -119,6 +119,11 @@ namespace ET
                 this.TimeId.Remove(time);
             }
 
+            if (this.TimeId.Count == 0)
+            {
+                this.minTime = long.MaxValue;
+            }
+
             while (this.timeOutTimerIds.Count > 0)
             {
                 long timerId = this.timeOutTimerIds.Dequeue();
@@ -127,7 +132,7 @@ namespace ET
                 {
                     continue;
                 }
-                
+
                 this.Run(timerAction);
             }
         }
@@ -150,7 +155,7 @@ namespace ET
                     break;
                 }
                 case TimerClass.RepeatedTimer:
-                {                    
+                {
                     long timeNow = GetNow();
                     timerAction.StartTime = timeNow;
                     this.AddTimer(timerAction);
@@ -299,7 +304,7 @@ namespace ET
                 throw new Exception($"repeated timer < 100, timerType: time: {time}");
             }
 #endif
-            
+
             long timeNow = GetNow();
             TimerAction timer = TimerAction.Create(this.GetId(), TimerClass.RepeatedTimer, timeNow, time, type, args);