using System; using System.Collections; using System.Reflection; using UnityEngine; using GFGGame.Launcher; using System.Collections.Generic; using System.Linq; using YooAsset; namespace GFGGame { public class HotUpdateCodeLoader : SingletonMonoBase { public Type[] allTypes; public Type[] GetTypes() { return this.allTypes; } private void Awake() { DontDestroyOnLoad(this.gameObject); } public void StartLoad() { StartCoroutine(StartLoadAssemblyHotfix()); } IEnumerator StartLoadAssemblyHotfix() { yield return new WaitForSeconds(0.1f); var dllPath = $"{LauncherConfig.DllDirHotfix}Game.HotUpdate.dll.bytes"; var handle = YooAssets.LoadAssetAsync(dllPath); yield return handle; var asset = handle.AssetObject as TextAsset; // WebGL平台特殊处理 LoadAssemblyForWebGL(asset.bytes); handle.Release(); // 加载热更新场景 YooAssets.LoadSceneAsync("Assets/ResIn/Scene/HotUpdate.unity"); } void LoadAssemblyForWebGL(byte[] dllBytes) { // WebGL平台下需要使用JavaScript互操作来加载程序集 // 这里需要实现一个JavaScript插件来实际加载程序集 // 示例代码,实际实现可能需要与你的JavaScript插件配合 string dllContent = Convert.ToBase64String(dllBytes); Application.ExternalCall("LoadHotUpdateAssembly", dllContent); // 注意:在WebGL下可能无法直接获取所有类型,需要根据实际情况调整 this.allTypes = new Type[0]; // 可能需要从JS端获取类型信息 Debug.Log($"调试 LoadAssemblyForWebGL :{this.allTypes.Length}"); } void LoadAssemblyJustInTime(Assembly assembly) { // 常规平台加载方式 this.allTypes = assembly.GetTypes(); } } }