using System; using System.Collections; using System.Reflection; using UnityEngine; using GFGGame.Launcher; using System.Linq; namespace GFGGame { public class HotUpdateCodeLoader : SingletonMonoBase { public Type[] allTypes; public Type[] GetTypes() { return this.allTypes; } public void StartLoad() { StartCoroutine(StartLoadAssemblyHotfix()); } private System.Reflection.Assembly gameAss; IEnumerator StartLoadAssemblyHotfix() { LogServerHelperHttp.SendNodeLog((int)LogNode.StartLoadGameDll); //ET.Log.Debug("ILRuntimeLauncher StartLoadAssemblyHotfix"); yield return new WaitForSeconds(0.1f); #if !UNITY_EDITOR LoadAssemblyJustInTime(); #else gameAss = AppDomain.CurrentDomain.GetAssemblies().First(assembly => assembly.GetName().Name == "Game.HotUpdate"); #endif RunMain(); } private void LoadAssemblyJustInTime() { var dllPath = $"{LauncherConfig.DllDirHotfix}Game.HotUpdate.dll.bytes"; var asset = GFGAsset.Load(dllPath); byte[] assBytes = asset.bytes; gameAss = Assembly.Load(assBytes); GFGAsset.Release(dllPath); } public void RunMain() { if (gameAss == null) { UnityEngine.Debug.LogError("dll未加载"); return; } this.allTypes = gameAss.GetTypes(); var appType = gameAss.GetType("GFGGame.HotUpdate.HotUpdateEntry"); var mainMethod = appType.GetMethod("Start"); mainMethod.Invoke(null, null); } } }