2025-11-03 17:46:28 +08:00
|
|
|
using Cysharp.Threading.Tasks;
|
2025-11-03 12:03:21 +08:00
|
|
|
using HybridCLR;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using YooAsset;
|
|
|
|
|
|
|
|
|
|
public class HotDllLoader : Singleton<HotDllLoader>
|
|
|
|
|
{
|
2025-11-03 17:46:28 +08:00
|
|
|
public List<string> DepDlls = new List<string>()
|
|
|
|
|
{
|
|
|
|
|
"mscorlib.dll",
|
|
|
|
|
"System.dll",
|
|
|
|
|
"System.Core.dll",
|
|
|
|
|
};
|
|
|
|
|
public async UniTask LoadDll(ResourcePackage package, string dll)
|
2025-11-03 12:03:21 +08:00
|
|
|
{
|
|
|
|
|
if (package.GetAssetInfo(dll).Error == string.Empty)
|
|
|
|
|
{
|
2025-11-03 17:46:28 +08:00
|
|
|
AssetHandle handle = package.LoadAssetAsync<TextAsset>(dll);
|
|
|
|
|
await handle.ToUniTask();
|
2025-11-03 12:03:21 +08:00
|
|
|
#if UNITY_EDITOR
|
|
|
|
|
Assembly hotUpdateAss = System.AppDomain.CurrentDomain.GetAssemblies().First(a => a.GetName().Name == dll.Replace(".dll", ""));
|
|
|
|
|
#else
|
|
|
|
|
Assembly hotUpdateAss = Assembly.Load((handle.AssetObject as TextAsset).bytes);
|
|
|
|
|
#endif
|
2025-11-03 17:46:28 +08:00
|
|
|
Debug.Log($"加载{dll}");
|
2025-11-03 12:03:21 +08:00
|
|
|
}
|
|
|
|
|
}
|
2025-11-03 17:46:28 +08:00
|
|
|
public async UniTask LoadDepDll(ResourcePackage package)
|
2025-11-03 12:03:21 +08:00
|
|
|
{
|
2025-11-03 17:46:28 +08:00
|
|
|
foreach (string dll in DepDlls)
|
2025-11-03 12:03:21 +08:00
|
|
|
{
|
|
|
|
|
if (package.GetAssetInfo(dll).Error == string.Empty)
|
|
|
|
|
{
|
2025-11-03 17:46:28 +08:00
|
|
|
AssetHandle handle = package.LoadAssetAsync<TextAsset>(dll);
|
|
|
|
|
await handle.ToUniTask();
|
2025-11-03 12:03:21 +08:00
|
|
|
RuntimeApi.LoadMetadataForAOTAssembly((handle.AssetObject as TextAsset).bytes, HomologousImageMode.SuperSet);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|