Parcourir la source

修改EventSystem Publish bug (#229)

* EventSystem Publish Bug

修改EventSystem Publish 里面关于WaitAll的bug

* Update ETTaskHelper.cs

修改WaitAny当传入tasks长度为0卡住问题

* Update ResourcesComponent.cs

修改异步加载依赖资源为WaitAll,提升加载速度
肖红 il y a 4 ans
Parent
commit
9a4113ba03

+ 10 - 0
Unity/Assets/Model/Core/Async/ETTaskHelper.cs

@@ -43,6 +43,11 @@ namespace ET
 
         public static async ETTask WaitAny<T>(ETTask<T>[] tasks)
         {
+            if (tasks?.Length == 0)
+            {
+                return;
+            }
+            
             CoroutineBlocker coroutineBlocker = new CoroutineBlocker(2);
             foreach (ETTask<T> task in tasks)
             {
@@ -60,6 +65,11 @@ namespace ET
 
         public static async ETTask WaitAny(ETTask[] tasks)
         {
+            if (tasks?.Length == 0)
+            {
+                return;
+            }
+            
             CoroutineBlocker coroutineBlocker = new CoroutineBlocker(2);
             foreach (ETTask task in tasks)
             {

+ 14 - 16
Unity/Assets/Model/Core/Object/EventSystem.cs

@@ -613,26 +613,24 @@ namespace ET
 			{
 				return;
 			}
+			using var list = ListComponent<ETTask>.Create();
+
 			foreach (object obj in iEvents)
 			{
-				try
-				{
-					using var list = ListComponent<ETTask>.Create();
-					
-					if (!(obj is AEvent<T> aEvent))
-					{
-						Log.Error($"event error: {obj.GetType().Name}");
-						continue;
-					}
-
-					list.List.Add(aEvent.Handle(a));
-
-					await ETTaskHelper.WaitAll(list.List);
-				}
-				catch (Exception e)
+				if (!(obj is AEvent<T> aEvent))
 				{
-					Log.Error(e);
+					Log.Error($"event error: {obj.GetType().Name}");
+					continue;
 				}
+				list.List.Add(aEvent.Handle(a));
+			}
+			try
+			{
+				await ETTaskHelper.WaitAll(list.List);
+			}
+			catch (Exception e)
+			{
+				Log.Error(e);
 			}
 		}
 

+ 10 - 5
Unity/Assets/Model/Module/Resource/ResourcesComponent.cs

@@ -455,18 +455,23 @@ namespace ET
             
             string[] dependencies = GetSortedDependencies(assetBundleName);
             //Log.Debug($"-----------dep load async start {assetBundleName} dep: {dependencies.ToList().ListToString()}");
+            using var tasts = ListComponent<ETTask>.Create();
+            async ETTask loadDependency(string dependency)
+            {
+                using (await CoroutineLockComponent.Instance.Wait(CoroutineLockType.Resources, dependency.GetHashCode()))
+                {
+                    await this.LoadOneBundleAsync(dependency, isScene);
+                }
+            }
             foreach (string dependency in dependencies)
             {
                 if (string.IsNullOrEmpty(dependency))
                 {
                     continue;
                 }
-
-                using (await CoroutineLockComponent.Instance.Wait(CoroutineLockType.Resources, dependency.GetHashCode()))
-                {
-                    await this.LoadOneBundleAsync(dependency, isScene);
-                }
+                tasts.List.Add(loadDependency(dependency));
             }
+            await ETTaskHelper.WaitAll(tasts.List);
         }
         
         private async ETTask LoadOneBundleAsync(string assetBundleName, bool isScene)