From 33223dc02e1c2b5734933e4f6aa5ab66fb4ad4ff Mon Sep 17 00:00:00 2001 From: ALEXTANG <574809918@qq.com> Date: Thu, 17 Aug 2023 21:38:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=84=E7=90=86DotNet=E7=BD=91=E7=BB=9C?= =?UTF-8?q?=E5=B1=82=E5=AF=B9WebGL=E5=AF=BC=E5=87=BA=E7=9A=84=E5=85=BC?= =?UTF-8?q?=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DotNet/Core/Singleton/SingletonSystem.cs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/Assets/GameScripts/DotNet/Core/Singleton/SingletonSystem.cs b/Assets/GameScripts/DotNet/Core/Singleton/SingletonSystem.cs index 29021ae9..c95a21b8 100644 --- a/Assets/GameScripts/DotNet/Core/Singleton/SingletonSystem.cs +++ b/Assets/GameScripts/DotNet/Core/Singleton/SingletonSystem.cs @@ -3,7 +3,11 @@ using System; using System.Collections.Generic; using System.Reflection; +#if UNITY_WEBGL +using Cysharp.Threading.Tasks; +#else using System.Threading.Tasks; +#endif using TEngine.DataStructure; #pragma warning disable CS8601 #pragma warning disable CS8604 @@ -25,10 +29,10 @@ namespace TEngine.Core private static void Load(int assemblyName) { var count = 0; - var task = new List(); - +#if !UNITY_WEBGL + var task = new List(); +#endif UnLoad(assemblyName); - foreach (var singletonType in AssemblyManager.ForEach(assemblyName, typeof(ISingleton))) { var instance = (ISingleton) Activator.CreateInstance(singletonType); @@ -38,7 +42,11 @@ namespace TEngine.Core if (initializeMethodInfo != null) { +#if !UNITY_WEBGL task.Add((Task) initializeMethodInfo.Invoke(instance, null)); +#else + initializeMethodInfo.Invoke(instance, null); +#endif } registerMethodInfo?.Invoke(instance, new object[] {instance}); @@ -58,7 +66,9 @@ namespace TEngine.Core Singletons.Enqueue(assemblyName, instance); } +#if !UNITY_WEBGL Task.WaitAll(task.ToArray()); +#endif Log.Info($"assembly:{assemblyName} load Singleton count:{count}"); }