[fix] 修复 externalHotUpdateAssembliyDirs 无法正确工作的bug

main
walon 2022-12-13 11:40:18 +08:00
parent 8afdcb985d
commit c8acfef61d
7 changed files with 40 additions and 34 deletions

View File

@ -1,4 +1,5 @@
using System;
using HybridCLR.Editor.Meta;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@ -35,10 +36,12 @@ namespace HybridCLR.Editor.BuildProcessors
}
}
var assResolver = MetaUtil.CreateHotUpdateAssemblyResolver(EditorUserBuildSettings.activeBuildTarget);
// 检查是否填写了正确的dll名称
foreach (var hotUpdateDll in allHotUpdateDllFiles)
{
if (assemblies.All(ass => !ass.EndsWith(hotUpdateDll)))
string hotUpdateAssName = hotUpdateDll.Substring(0, hotUpdateDll.Length - 4);
if (assemblies.All(ass => !ass.EndsWith(hotUpdateDll)) && string.IsNullOrEmpty(assResolver.ResolveAssembly(hotUpdateAssName, false)))
{
throw new Exception($"热更新 assembly:{hotUpdateDll} 不存在,请检查拼写错误");
}

View File

@ -26,29 +26,12 @@ namespace HybridCLR.Editor.Commands
var ls = SettingsUtil.HybridCLRSettings;
var allAssByNames = new Dictionary<string, Assembly>();
foreach (var ass in AppDomain.CurrentDomain.GetAssemblies())
{
allAssByNames[ass.GetName().Name] = ass;
}
var hotfixAssembles = new List<Assembly>();
foreach(var assName in SettingsUtil.HotUpdateAssemblyNames)
{
if (allAssByNames.TryGetValue(assName, out var ass))
{
hotfixAssembles.Add(ass);
}
else
{
throw new Exception($"assembly:{assName} 不存在");
}
}
List<string> hotfixAssemblies = SettingsUtil.HotUpdateAssemblyNames;
var analyzer = new Analyzer(Meta.MetaUtil.CreateBuildTargetAssemblyResolver(EditorUserBuildSettings.activeBuildTarget), HybridCLRSettings.Instance.collectAssetReferenceTypes);
var refTypes = analyzer.CollectRefs(hotfixAssembles);
var refTypes = analyzer.CollectRefs(hotfixAssemblies);
Debug.Log($"[LinkGeneratorCommand] hotfix assembly count:{hotfixAssembles.Count}, ref type count:{refTypes.Count} output:{Application.dataPath}/{ls.outputLinkFile}");
Debug.Log($"[LinkGeneratorCommand] hotfix assembly count:{hotfixAssemblies.Count}, ref type count:{refTypes.Count} output:{Application.dataPath}/{ls.outputLinkFile}");
var linkXmlWriter = new LinkXmlWriter();
linkXmlWriter.Write($"{Application.dataPath}/{ls.outputLinkFile}", refTypes);
AssetDatabase.Refresh();

View File

@ -52,12 +52,9 @@ namespace HybridCLR.Editor.Commands
static IAssemblyResolver CreateBuildTargetAssemblyResolver(BuildTarget target)
{
return new CombinedAssemblyResolver(new PathAssemblyResolver(
SettingsUtil.GetAssembliesPostIl2CppStripDir(target),
SettingsUtil.GetHotUpdateDllsOutputDirByTarget(target)),
new UnityPluginAssemblyResolver(),
new UnityDotNetAOTAssemblyResolver(),
new UnityEditorAssemblyResolver()
return new CombinedAssemblyResolver(
new PathAssemblyResolver(SettingsUtil.GetAssembliesPostIl2CppStripDir(target)),
MetaUtil.CreateHotUpdateAssemblyResolver(target)
);
}

View File

@ -22,23 +22,23 @@ namespace HybridCLR.Editor.Link
_analyzeAssetType = analyzeAssetType;
}
public HashSet<TypeRef> CollectRefs(List<Assembly> rootAssemblies)
public HashSet<TypeRef> CollectRefs(List<string> rootAssemblies)
{
using (var assCollector = new AssemblyCache(_resolver))
{
var rootAssemblyName = new HashSet<string>();
foreach (var ass in rootAssemblies)
{
if (!rootAssemblyName.Add(ass.GetName().Name))
if (!rootAssemblyName.Add(ass))
{
throw new Exception($"assembly:{ass.GetName().Name} 重复");
throw new Exception($"assembly:{ass} 重复");
}
}
var typeRefs = new HashSet<TypeRef>(TypeEqualityComparer.Instance);
foreach (var rootAss in rootAssemblies)
{
var dnAss = assCollector.LoadModule(rootAss.GetName().Name);
var dnAss = assCollector.LoadModule(rootAss);
foreach (var type in dnAss.GetTypeRefs())
{
if (!rootAssemblyName.Contains(type.DefinitionAssembly.Name))

View File

@ -141,6 +141,25 @@ namespace HybridCLR.Editor.Meta
}
}
public static IAssemblyResolver CreateExternalAssemblyResolver(BuildTarget target)
{
var externalDirs = HybridCLRSettings.Instance.externalHotUpdateAssembliyDirs;
if (externalDirs == null || externalDirs.Length == 0)
{
return new PathAssemblyResolver();
}
else
{
var externalDirList = new List<string>();
foreach (var dir in externalDirs)
{
externalDirList.Add($"{dir}/{target}");
externalDirList.Add(dir);
}
return new PathAssemblyResolver(externalDirList.ToArray());
}
}
public static IAssemblyResolver CreateBuildTargetAssemblyResolver(BuildTarget target)
{
return new CombinedAssemblyResolver(CreateHotUpdateAssemblyResolver(target),

View File

@ -16,7 +16,11 @@ namespace HybridCLR.Editor.Meta
{
return refAss.Location;
}
return Assembly.Load(assemblyName).Location;
if (throwExIfNotFind)
{
throw new Exception($"resolve assembly:{assemblyName} fail");
}
return null;
}
}
}

View File

@ -1,6 +1,6 @@
{
"name": "com.focus-creative-games.hybridclr_unity",
"version": "1.1.10",
"version": "1.1.11",
"displayName": "HybridCLR",
"description": "Unity package for HybridCLR. It includes editor and runtime scripts and assets for HybridCLR",
"category": "Runtime",