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

1.一般协程都可以用cancelToken.IsCancel来判断协程是否取消,如果取消则需要return
2.优化EventSystem代码

tanghai 3 лет назад
Родитель
Сommit
46bd47ac2b
25 измененных файлов с 163 добавлено и 135 удалено
  1. 3 3
      Unity/Assets/Scripts/Codes/Hotfix/Client/Demo/AI/AI_Attack.cs
  2. 3 3
      Unity/Assets/Scripts/Codes/Hotfix/Client/Demo/AI/AI_XunLuo.cs
  3. 2 3
      Unity/Assets/Scripts/Codes/Hotfix/Client/Demo/Move/MoveHelper.cs
  4. 4 2
      Unity/Assets/Scripts/Codes/Hotfix/Server/Demo/Scenes/Map/Move/MoveHelper.cs
  5. 3 16
      Unity/Assets/Scripts/Codes/Hotfix/Share/Module/Move/MoveComponentSystem.cs
  6. 2 2
      Unity/Assets/Scripts/Codes/Model/Share/Module/ObjectWait/ObjectWait.cs
  7. 4 17
      Unity/Assets/Scripts/Core/Module/Entity/Entity.cs
  8. 2 18
      Unity/Assets/Scripts/Core/Module/Entity/Scene.cs
  9. 23 35
      Unity/Assets/Scripts/Core/Module/EventSystem/EventSystem.cs
  10. 5 0
      Unity/Assets/Scripts/Core/Module/EventSystem/IAddComponentSystem.cs
  11. 25 0
      Unity/Assets/Scripts/Core/Module/EventSystem/IAwakeSystem.cs
  12. 5 1
      Unity/Assets/Scripts/Core/Module/EventSystem/IDeserializeSystem.cs
  13. 5 0
      Unity/Assets/Scripts/Core/Module/EventSystem/IDestroySystem.cs
  14. 5 0
      Unity/Assets/Scripts/Core/Module/EventSystem/IGetComponentSystem.cs
  15. 5 0
      Unity/Assets/Scripts/Core/Module/EventSystem/ILateUpdateSystem.cs
  16. 5 0
      Unity/Assets/Scripts/Core/Module/EventSystem/ILoadSystem.cs
  17. 1 0
      Unity/Assets/Scripts/Core/Module/EventSystem/ISystemType.cs
  18. 5 0
      Unity/Assets/Scripts/Core/Module/EventSystem/IUpdateSystem.cs
  19. 11 0
      Unity/Assets/Scripts/Core/Module/EventSystem/InstanceQueueIndex.cs
  20. 11 0
      Unity/Assets/Scripts/Core/Module/EventSystem/InstanceQueueIndex.cs.meta
  21. 18 25
      Unity/Assets/Scripts/Core/Module/Timer/TimerComponent.cs
  22. 3 2
      Unity/Assets/Scripts/Core/MultiMap.cs
  23. 3 2
      Unity/Assets/Scripts/Core/MultiMapSet.cs
  24. 1 1
      Unity/Assets/Scripts/ThirdParty/ETTask/ETCancellationToken.cs
  25. 9 5
      Unity/Assets/Scripts/ThirdParty/ETTask/ETTaskHelper.cs

+ 3 - 3
Unity/Assets/Scripts/Codes/Hotfix/Client/Demo/AI/AI_Attack.cs

@@ -16,7 +16,7 @@ namespace ET.Client
         {
             Scene clientScene = aiComponent.DomainScene();
 
-            Unit myUnit = Client.UnitHelper.GetMyUnitFromClientScene(clientScene);
+            Unit myUnit = UnitHelper.GetMyUnitFromClientScene(clientScene);
             if (myUnit == null)
             {
                 return;
@@ -32,8 +32,8 @@ namespace ET.Client
                 Log.Debug($"攻击: {i}次");
 
                 // 因为协程可能被中断,任何协程都要传入cancellationToken,判断如果是中断则要返回
-                bool timeRet = await TimerComponent.Instance.WaitAsync(1000, cancellationToken);
-                if (!timeRet)
+                await TimerComponent.Instance.WaitAsync(1000, cancellationToken);
+                if (cancellationToken.IsCancel())
                 {
                     return;
                 }

+ 3 - 3
Unity/Assets/Scripts/Codes/Hotfix/Client/Demo/AI/AI_XunLuo.cs

@@ -18,7 +18,7 @@ namespace ET.Client
         {
             Scene clientScene = aiComponent.DomainScene();
 
-            Unit myUnit = Client.UnitHelper.GetMyUnitFromClientScene(clientScene);
+            Unit myUnit = UnitHelper.GetMyUnitFromClientScene(clientScene);
             if (myUnit == null)
             {
                 return;
@@ -30,8 +30,8 @@ namespace ET.Client
             {
                 XunLuoPathComponent xunLuoPathComponent = myUnit.GetComponent<XunLuoPathComponent>();
                 float3 nextTarget = xunLuoPathComponent.GetCurrent();
-                int ret = await myUnit.MoveToAsync(nextTarget, cancellationToken);
-                if (ret != 0)
+                await myUnit.MoveToAsync(nextTarget, cancellationToken);
+                if (cancellationToken.IsCancel())
                 {
                     return;
                 }

+ 2 - 3
Unity/Assets/Scripts/Codes/Hotfix/Client/Demo/Move/MoveHelper.cs

@@ -22,12 +22,11 @@ namespace ET.Client
             return waitUnitStop.Error;
         }
         
-        public static async ETTask<bool> MoveToAsync(this Unit unit, List<float3> path)
+        public static async ETTask MoveToAsync(this Unit unit, List<float3> path)
         {
             float speed = unit.GetComponent<NumericComponent>().GetAsFloat(NumericType.Speed);
             MoveComponent moveComponent = unit.GetComponent<MoveComponent>();
-            bool ret = await moveComponent.MoveToAsync(path, speed);
-            return ret;
+            await moveComponent.MoveToAsync(path, speed);
         }
     }
 }

+ 4 - 2
Unity/Assets/Scripts/Codes/Hotfix/Server/Demo/Scenes/Map/Move/MoveHelper.cs

@@ -6,7 +6,7 @@ namespace ET.Server
     public static class MoveHelper
     {
         // 可以多次调用,多次调用的话会取消上一次的协程
-        public static async ETTask FindPathMoveToAsync(this Unit unit, float3 target, ETCancellationToken cancellationToken = null)
+        public static async ETTask FindPathMoveToAsync(this Unit unit, float3 target)
         {
             float speed = unit.GetComponent<NumericComponent>().GetAsFloat(NumericType.Speed);
             if (speed < 0.01)
@@ -30,7 +30,9 @@ namespace ET.Server
             m2CPathfindingResult.Id = unit.Id;
             MessageHelper.Broadcast(unit, m2CPathfindingResult);
 
-            bool ret = await unit.GetComponent<MoveComponent>().MoveToAsync(list, speed);
+            MoveComponent moveComponent = unit.GetComponent<MoveComponent>();
+            
+            bool ret = await moveComponent.MoveToAsync(list, speed);
             if (ret) // 如果返回false,说明被其它移动取消了,这时候不需要通知客户端stop
             {
                 unit.SendStop(0);

+ 3 - 16
Unity/Assets/Scripts/Codes/Hotfix/Share/Module/Move/MoveComponentSystem.cs

@@ -81,7 +81,8 @@ namespace ET
             return true;
         }
 
-        public static async ETTask<bool> MoveToAsync(this MoveComponent self, List<float3> target, float speed, int turnTime = 100, ETCancellationToken cancellationToken = null)
+        // 该方法不需要用cancelToken的方式取消,因为即使不传入cancelToken,多次调用该方法也要取消之前的移动协程,上层可以stop取消
+        public static async ETTask<bool> MoveToAsync(this MoveComponent self, List<float3> target, float speed, int turnTime = 100)
         {
             self.Stop();
 
@@ -99,21 +100,7 @@ namespace ET
             
             self.StartMove();
             
-            void CancelAction()
-            {
-                self.Stop();
-            }
-            
-            bool moveRet;
-            try
-            {
-                cancellationToken?.Add(CancelAction);
-                moveRet = await self.tcs;
-            }
-            finally
-            {
-                cancellationToken?.Remove(CancelAction);
-            }
+            bool moveRet = await self.tcs;
 
             if (moveRet)
             {

+ 2 - 2
Unity/Assets/Scripts/Codes/Model/Share/Module/ObjectWait/ObjectWait.cs

@@ -113,8 +113,8 @@ namespace ET
             ResultCallback<T> tcs = new ResultCallback<T>();
             async ETTask WaitTimeout()
             {
-                bool retV = await TimerComponent.Instance.WaitAsync(timeout, cancellationToken);
-                if (!retV)
+                await TimerComponent.Instance.WaitAsync(timeout, cancellationToken);
+                if (cancellationToken.IsCancel())
                 {
                     return;
                 }

+ 4 - 17
Unity/Assets/Scripts/Core/Module/Entity/Entity.cs

@@ -340,11 +340,7 @@ namespace ET
         {
             get
             {
-                if (this.children == null)
-                {
-                    this.children = ObjectPool.Instance.Fetch<Dictionary<long, Entity>>();
-                }
-                return this.children;
+                return this.children ??= ObjectPool.Instance.Fetch<Dictionary<long, Entity>>();
             }
         }
 
@@ -379,7 +375,7 @@ namespace ET
                 return;
             }
 
-            this.childrenDB = this.childrenDB ?? ObjectPool.Instance.Fetch<HashSet<Entity>>();
+            this.childrenDB ??= ObjectPool.Instance.Fetch<HashSet<Entity>>();
 
             this.childrenDB.Add(entity);
         }
@@ -417,11 +413,7 @@ namespace ET
         {
             get
             {
-                if (this.components == null)
-                {
-                    this.components = ObjectPool.Instance.Fetch<Dictionary<Type, Entity>>();
-                }
-                return this.components;
+                return this.components ??= ObjectPool.Instance.Fetch<Dictionary<Type, Entity>>();
             }
         }
 
@@ -521,11 +513,7 @@ namespace ET
                 return;
             }
             
-            if (this.componentsDB == null)
-            {
-                this.componentsDB = ObjectPool.Instance.Fetch<HashSet<Entity>>();
-            }
-
+            this.componentsDB ??= ObjectPool.Instance.Fetch<HashSet<Entity>>();
             this.componentsDB.Add(component);
         }
 
@@ -634,7 +622,6 @@ namespace ET
                 return;
             }
 
-            Type type = component.GetType();
             Entity c = this.GetComponent(component.GetType());
             if (c == null)
             {

+ 2 - 18
Unity/Assets/Scripts/Core/Module/Entity/Scene.cs

@@ -20,7 +20,6 @@ namespace ET
         public string Name
         {
             get;
-            set;
         }
 
         public Scene(long instanceId, int zone, SceneType sceneType, string name, Entity parent)
@@ -60,25 +59,10 @@ namespace ET
             Log.Info($"scene dispose: {this.SceneType} {this.Name} {this.Id} {this.InstanceId} {this.Zone}");
         }
 
-        public Scene Get(long id)
-        {
-            if (this.Children == null)
-            {
-                return null;
-            }
-
-            if (!this.Children.TryGetValue(id, out Entity entity))
-            {
-                return null;
-            }
-
-            return entity as Scene;
-        }
-
         public new Entity Domain
         {
             get => this.domain;
-            set => this.domain = value;
+            private set => this.domain = value;
         }
 
         public new Entity Parent
@@ -87,7 +71,7 @@ namespace ET
             {
                 return this.parent;
             }
-            set
+            private set
             {
                 if (value == null)
                 {

+ 23 - 35
Unity/Assets/Scripts/Core/Module/EventSystem/EventSystem.cs

@@ -5,10 +5,15 @@ using System.Text;
 
 namespace ET
 {
-    using OneTypeSystems = UnOrderMultiMap<Type, object>;
-
     public class EventSystem: Singleton<EventSystem>, ISingletonUpdate, ISingletonLateUpdate
     {
+        private class OneTypeSystems
+        {
+            public readonly UnOrderMultiMap<Type, object> Map = new();
+            // 这里不用hash,数量比较少,直接for循环速度更快
+            public readonly bool[] QueueFlag = new bool[(int)InstanceQueueIndex.Max];
+        }
+        
         private class TypeSystems
         {
             private readonly Dictionary<Type, OneTypeSystems> typeSystemsMap = new();
@@ -42,7 +47,7 @@ namespace ET
                     return null;
                 }
 
-                if (!oneTypeSystems.TryGetValue(systemType, out List<object> systems))
+                if (!oneTypeSystems.Map.TryGetValue(systemType, out List<object> systems))
                 {
                     return null;
                 }
@@ -76,15 +81,7 @@ namespace ET
 
         private TypeSystems typeSystems = new();
 
-        private readonly Queue<long>[] queues = new Queue<long>[(int)QueueEnum.Max];
-
-        private enum QueueEnum
-        {
-            Update = 0,
-            LateUpdate = 1,
-            Load = 2,
-            Max = 3,
-        }
+        private readonly Queue<long>[] queues = new Queue<long>[(int)InstanceQueueIndex.Max];
 
         public EventSystem()
         {
@@ -151,7 +148,12 @@ namespace ET
                 if (obj is ISystemType iSystemType)
                 {
                     OneTypeSystems oneTypeSystems = this.typeSystems.GetOrCreateOneTypeSystems(iSystemType.Type());
-                    oneTypeSystems.Add(iSystemType.SystemType(), obj);
+                    oneTypeSystems.Map.Add(iSystemType.SystemType(), obj);
+                    InstanceQueueIndex index = iSystemType.GetInstanceQueueIndex();
+                    if (index > InstanceQueueIndex.None && index < InstanceQueueIndex.Max)
+                    {
+                        oneTypeSystems.QueueFlag[(int)index] = true;
+                    }
                 }
             }
 
@@ -252,27 +254,13 @@ namespace ET
             {
                 return;
             }
-            
-            if (component is ILoad)
+            for (int i = 0; i < oneTypeSystems.QueueFlag.Length; ++i)
             {
-                if (oneTypeSystems.ContainsKey(typeof (ILoadSystem)))
+                if (!oneTypeSystems.QueueFlag[i])
                 {
-                    this.queues[(int)QueueEnum.Load].Enqueue(component.InstanceId);
-                }
-            }
-            if (component is IUpdate)
-            {
-                if (oneTypeSystems.ContainsKey(typeof (IUpdateSystem)))
-                {
-                    this.queues[(int)QueueEnum.Update].Enqueue(component.InstanceId);
-                }
-            }
-            if (component is ILateUpdate)
-            {
-                if (oneTypeSystems.ContainsKey(typeof (ILateUpdateSystem)))
-                {
-                    this.queues[(int)QueueEnum.LateUpdate].Enqueue(component.InstanceId);
+                    continue;
                 }
+                this.queues[i].Enqueue(component.InstanceId);
             }
         }
 
@@ -505,7 +493,7 @@ namespace ET
 
         public void Load()
         {
-            Queue<long> queue = this.queues[(int)QueueEnum.Load];
+            Queue<long> queue = this.queues[(int)InstanceQueueIndex.Load];
             int count = queue.Count;
             while (count-- > 0)
             {
@@ -571,7 +559,7 @@ namespace ET
 
         public void Update()
         {
-            Queue<long> queue = this.queues[(int)QueueEnum.Update];
+            Queue<long> queue = this.queues[(int)InstanceQueueIndex.Update];
             int count = queue.Count;
             while (count-- > 0)
             {
@@ -611,7 +599,7 @@ namespace ET
 
         public void LateUpdate()
         {
-            Queue<long> queue = this.queues[(int)QueueEnum.LateUpdate];
+            Queue<long> queue = this.queues[(int)InstanceQueueIndex.LateUpdate];
             int count = queue.Count;
             while (count-- > 0)
             {
@@ -685,7 +673,7 @@ namespace ET
             }
         }
 
-        public void Publish<T>(Scene scene, T a)where T : struct
+        public void Publish<T>(Scene scene, T a) where T : struct
         {
             List<EventInfo> iEvents;
             if (!this.allEvents.TryGetValue(typeof (T), out iEvents))

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

@@ -24,6 +24,11 @@ namespace ET
 			return typeof(IAddComponentSystem);
 		}
 
+		public InstanceQueueIndex GetInstanceQueueIndex()
+		{
+			return InstanceQueueIndex.None;
+		}
+
 		public Type Type()
 		{
 			return typeof(T);

+ 25 - 0
Unity/Assets/Scripts/Core/Module/EventSystem/IAwakeSystem.cs

@@ -60,6 +60,11 @@ namespace ET
             return typeof(IAwakeSystem);
         }
 
+        public InstanceQueueIndex GetInstanceQueueIndex()
+        {
+            return InstanceQueueIndex.None;
+        }
+
         public void Run(object o)
         {
             this.Awake((T)o);
@@ -81,6 +86,11 @@ namespace ET
             return typeof(IAwakeSystem<A>);
         }
 
+        public InstanceQueueIndex GetInstanceQueueIndex()
+        {
+            return InstanceQueueIndex.None;
+        }
+
         public void Run(object o, A a)
         {
             this.Awake((T)o, a);
@@ -102,6 +112,11 @@ namespace ET
             return typeof(IAwakeSystem<A, B>);
         }
 
+        public InstanceQueueIndex GetInstanceQueueIndex()
+        {
+            return InstanceQueueIndex.None;
+        }
+
         public void Run(object o, A a, B b)
         {
             this.Awake((T)o, a, b);
@@ -123,6 +138,11 @@ namespace ET
             return typeof(IAwakeSystem<A, B, C>);
         }
 
+        public InstanceQueueIndex GetInstanceQueueIndex()
+        {
+            return InstanceQueueIndex.None;
+        }
+
         public void Run(object o, A a, B b, C c)
         {
             this.Awake((T)o, a, b, c);
@@ -144,6 +164,11 @@ namespace ET
             return typeof(IAwakeSystem<A, B, C, D>);
         }
 
+        public InstanceQueueIndex GetInstanceQueueIndex()
+        {
+            return InstanceQueueIndex.None;
+        }
+
         public void Run(object o, A a, B b, C c, D d)
         {
             this.Awake((T)o, a, b, c, d);

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

@@ -13,7 +13,6 @@ namespace ET
 
 	/// <summary>
 	/// 反序列化后执行的System
-	/// 要小心使用这个System,因为对象假如要保存到数据库,到dbserver也会进行反序列化,那么也会执行该System
 	/// </summary>
 	/// <typeparam name="T"></typeparam>
 	[ObjectSystem]
@@ -29,6 +28,11 @@ namespace ET
 			return typeof(IDeserializeSystem);
 		}
 
+		public InstanceQueueIndex GetInstanceQueueIndex()
+		{
+			return InstanceQueueIndex.None;
+		}
+
 		public Type Type()
 		{
 			return typeof(T);

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

@@ -25,6 +25,11 @@ namespace ET
 			return typeof(IDestroySystem);
 		}
 
+		public InstanceQueueIndex GetInstanceQueueIndex()
+		{
+			return InstanceQueueIndex.None;
+		}
+
 		public Type Type()
 		{
 			return typeof(T);

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

@@ -28,6 +28,11 @@ namespace ET
 			return typeof(IGetComponentSystem);
 		}
 
+		public InstanceQueueIndex GetInstanceQueueIndex()
+		{
+			return InstanceQueueIndex.None;
+		}
+
 		public Type Type()
 		{
 			return typeof(T);

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

@@ -29,6 +29,11 @@ namespace ET
 			return typeof(ILateUpdateSystem);
 		}
 
+		public InstanceQueueIndex GetInstanceQueueIndex()
+		{
+			return InstanceQueueIndex.LateUpdate;
+		}
+
 		protected abstract void LateUpdate(T self);
 	}
 }

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

@@ -29,6 +29,11 @@ namespace ET
 			return typeof(ILoadSystem);
 		}
 
+		public InstanceQueueIndex GetInstanceQueueIndex()
+		{
+			return InstanceQueueIndex.Load;
+		}
+
 		protected abstract void Load(T self);
 	}
 }

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

@@ -6,5 +6,6 @@ namespace ET
     {
         Type Type();
         Type SystemType();
+        InstanceQueueIndex GetInstanceQueueIndex();
     }
 }

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

@@ -29,6 +29,11 @@ namespace ET
 			return typeof(IUpdateSystem);
 		}
 
+		public InstanceQueueIndex GetInstanceQueueIndex()
+		{
+			return InstanceQueueIndex.Update;
+		}
+
 		protected abstract void Update(T self);
 	}
 }

+ 11 - 0
Unity/Assets/Scripts/Core/Module/EventSystem/InstanceQueueIndex.cs

@@ -0,0 +1,11 @@
+namespace ET
+{
+    public enum InstanceQueueIndex
+    {
+        None = -1,
+        Update,
+        LateUpdate,
+        Load,
+        Max,
+    }
+}

+ 11 - 0
Unity/Assets/Scripts/Core/Module/EventSystem/InstanceQueueIndex.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 8b00c6109305e8948a15e02049c98a5a
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 18 - 25
Unity/Assets/Scripts/Core/Module/Timer/TimerComponent.cs

@@ -58,13 +58,13 @@ namespace ET
         /// <summary>
         /// key: time, value: timer id
         /// </summary>
-        private readonly MultiMap<long, long> TimeId = new MultiMap<long, long>();
+        private readonly MultiMap<long, long> TimeId = new();
 
-        private readonly Queue<long> timeOutTime = new Queue<long>();
+        private readonly Queue<long> timeOutTime = new();
 
-        private readonly Queue<long> timeOutTimerIds = new Queue<long>();
+        private readonly Queue<long> timeOutTimerIds = new();
 
-        private readonly Dictionary<long, TimerAction> timerActions = new Dictionary<long, TimerAction>();
+        private readonly Dictionary<long, TimerAction> timerActions = new();
 
         private long idGenerator;
 
@@ -144,8 +144,8 @@ namespace ET
                 }
                 case TimerClass.OnceWaitTimer:
                 {
-                    ETTask<bool> tcs = timerAction.Object as ETTask<bool>;
-                    tcs.SetResult(true);
+                    ETTask tcs = timerAction.Object as ETTask;
+                    tcs.SetResult();
                     timerAction.Recycle();
                     break;
                 }
@@ -193,15 +193,15 @@ namespace ET
             return true;
         }
 
-        public async ETTask<bool> WaitTillAsync(long tillTime, ETCancellationToken cancellationToken = null)
+        public async ETTask WaitTillAsync(long tillTime, ETCancellationToken cancellationToken = null)
         {
             long timeNow = GetNow();
             if (timeNow >= tillTime)
             {
-                return true;
+                return;
             }
 
-            ETTask<bool> tcs = ETTask<bool>.Create(true);
+            ETTask tcs = ETTask.Create(true);
             TimerAction timer = TimerAction.Create(this.GetId(), TimerClass.OnceWaitTimer, timeNow, tillTime - timeNow, 0, tcs);
             this.AddTimer(timer);
             long timerId = timer.Id;
@@ -210,40 +210,36 @@ namespace ET
             {
                 if (this.Remove(timerId))
                 {
-                    tcs.SetResult(false);
+                    tcs.SetResult();
                 }
             }
 
-            bool ret;
             try
             {
                 cancellationToken?.Add(CancelAction);
-                ret = await tcs;
+                await tcs;
             }
             finally
             {
                 cancellationToken?.Remove(CancelAction);
             }
-
-            return ret;
         }
 
-        public async ETTask<bool> WaitFrameAsync(ETCancellationToken cancellationToken = null)
+        public async ETTask WaitFrameAsync(ETCancellationToken cancellationToken = null)
         {
-            bool ret = await this.WaitAsync(1, cancellationToken);
-            return ret;
+            await this.WaitAsync(1, cancellationToken);
         }
 
-        public async ETTask<bool> WaitAsync(long time, ETCancellationToken cancellationToken = null)
+        public async ETTask WaitAsync(long time, ETCancellationToken cancellationToken = null)
         {
             if (time == 0)
             {
-                return true;
+                return;
             }
 
             long timeNow = GetNow();
 
-            ETTask<bool> tcs = ETTask<bool>.Create(true);
+            ETTask tcs = ETTask.Create(true);
             TimerAction timer = TimerAction.Create(this.GetId(), TimerClass.OnceWaitTimer, timeNow, time, 0, tcs);
             this.AddTimer(timer);
             long timerId = timer.Id;
@@ -252,22 +248,19 @@ namespace ET
             {
                 if (this.Remove(timerId))
                 {
-                    tcs.SetResult(false);
+                    tcs.SetResult();
                 }
             }
 
-            bool ret;
             try
             {
                 cancellationToken?.Add(CancelAction);
-                ret = await tcs;
+                await tcs;
             }
             finally
             {
                 cancellationToken?.Remove(CancelAction);
             }
-
-            return ret;
         }
 
         // 用这个优点是可以热更,缺点是回调式的写法,逻辑不连贯。WaitTillAsync不能热更,优点是逻辑连贯。

+ 3 - 2
Unity/Assets/Scripts/Core/MultiMap.cs

@@ -1,4 +1,5 @@
-using System.Collections.Generic;
+using System;
+using System.Collections.Generic;
 
 namespace ET
 {
@@ -48,7 +49,7 @@ namespace ET
             this.TryGetValue(t, out list);
             if (list == null)
             {
-                return new K[0];
+                return Array.Empty<K>();
             }
             return list.ToArray();
         }

+ 3 - 2
Unity/Assets/Scripts/Core/MultiMapSet.cs

@@ -1,4 +1,5 @@
-using System.Collections.Generic;
+using System;
+using System.Collections.Generic;
 using System.Linq;
 
 namespace ET
@@ -49,7 +50,7 @@ namespace ET
             this.TryGetValue(t, out list);
             if (list == null)
             {
-                return new K[0];
+                return Array.Empty<K>();
             }
             return list.ToArray();
         }

+ 1 - 1
Unity/Assets/Scripts/ThirdParty/ETTask/ETCancellationToken.cs

@@ -18,7 +18,7 @@ namespace ET
             this.actions?.Remove(callback);
         }
 
-        public bool IsCancel()
+        public bool IsDispose()
         {
             return this.actions == null;
         }

+ 9 - 5
Unity/Assets/Scripts/ThirdParty/ETTask/ETTaskHelper.cs

@@ -5,6 +5,15 @@ namespace ET
 {
     public static class ETTaskHelper
     {
+        public static bool IsCancel(this ETCancellationToken self)
+        {
+            if (self == null)
+            {
+                return false;
+            }
+            return self.IsDispose();
+        }
+        
         private class CoroutineBlocker
         {
             private int count;
@@ -213,11 +222,6 @@ namespace ET
                 await coroutineBlocker.WaitAsync();
             }
 
-            if (cancellationToken == null)
-            {
-                return true;
-            }
-
             return !cancellationToken.IsCancel();
         }
     }