fix: IL扫描忘记判断特性头了
This commit is contained in:
2 files changed
+39
-4
No files matched your search
@@ -32,7 +32,31 @@ namespace ShrinkEventBus.CodeGen
|
|||||||
var assemblyDefinition = AssemblyDefinitionFor(compiledAssembly);
|
var assemblyDefinition = AssemblyDefinitionFor(compiledAssembly);
|
||||||
var mainModule = assemblyDefinition.MainModule;
|
var mainModule = assemblyDefinition.MainModule;
|
||||||
|
|
||||||
ImportReferences(mainModule);
|
bool needWeaving = false;
|
||||||
|
foreach (var type in mainModule.Types)
|
||||||
|
{
|
||||||
|
if (HasAttribute(type, "EventBusSubscriberAttribute") && InheritsFromMonoBehaviour(type))
|
||||||
|
{
|
||||||
|
needWeaving = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!needWeaving) return null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ImportReferences(mainModule);
|
||||||
|
}
|
||||||
|
catch (System.Exception ex)
|
||||||
|
{
|
||||||
|
_diagnostics.Add(new DiagnosticMessage
|
||||||
|
{
|
||||||
|
DiagnosticType = DiagnosticType.Error,
|
||||||
|
MessageData = $"[ShrinkEventBus] ILPostProcessor Error: {ex.Message}"
|
||||||
|
});
|
||||||
|
return GetResult(assemblyDefinition, _diagnostics);
|
||||||
|
}
|
||||||
|
|
||||||
foreach (var type in mainModule.Types)
|
foreach (var type in mainModule.Types)
|
||||||
{
|
{
|
||||||
@@ -172,7 +196,16 @@ namespace ShrinkEventBus.CodeGen
|
|||||||
private void ImportReferences(ModuleDefinition module)
|
private void ImportReferences(ModuleDefinition module)
|
||||||
{
|
{
|
||||||
var runtimeModule = FindRuntimeModule(module);
|
var runtimeModule = FindRuntimeModule(module);
|
||||||
var eventBusType = runtimeModule.GetAllTypes().First(t => t.Name == "EventBus");
|
if (runtimeModule == null)
|
||||||
|
{
|
||||||
|
throw new System.Exception("Cannot find ShrinkEventBus.Runtime module in assembly references.");
|
||||||
|
}
|
||||||
|
|
||||||
|
var eventBusType = runtimeModule.GetAllTypes().FirstOrDefault(t => t.Name == "EventBus");
|
||||||
|
if (eventBusType == null)
|
||||||
|
{
|
||||||
|
throw new System.Exception("Cannot find EventBus class in ShrinkEventBus.Runtime.");
|
||||||
|
}
|
||||||
|
|
||||||
_autoRegisterMethodRef = module.ImportReference(
|
_autoRegisterMethodRef = module.ImportReference(
|
||||||
eventBusType.Methods.First(m => m.Name == "AutoRegister"));
|
eventBusType.Methods.First(m => m.Name == "AutoRegister"));
|
||||||
@@ -190,9 +223,11 @@ namespace ShrinkEventBus.CodeGen
|
|||||||
|
|
||||||
private void SearchRecursive(AssemblyDefinition asm, ref ModuleDefinition found, HashSet<string> visited)
|
private void SearchRecursive(AssemblyDefinition asm, ref ModuleDefinition found, HashSet<string> visited)
|
||||||
{
|
{
|
||||||
|
if (asm == null) return;
|
||||||
|
|
||||||
foreach (var mod in asm.Modules)
|
foreach (var mod in asm.Modules)
|
||||||
{
|
{
|
||||||
if (mod.Name == "ShrinkEventBus.Runtime.dll")
|
if (mod.Name == "ShrinkEventBus.Runtime.dll" || mod.Name == "ShrinkEventBus.Runtime")
|
||||||
{
|
{
|
||||||
found = mod;
|
found = mod;
|
||||||
return;
|
return;
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "com.cneicy.shrink-eventbus",
|
"name": "com.cneicy.shrink-eventbus",
|
||||||
"version": "1.1.3",
|
"version": "1.1.4",
|
||||||
"displayName": "ShrinkEventBus",
|
"displayName": "ShrinkEventBus",
|
||||||
"description": "高性能、类型安全的 Unity 事件总线,支持优先级调度与自动注册。",
|
"description": "高性能、类型安全的 Unity 事件总线,支持优先级调度与自动注册。",
|
||||||
"unity": "2022.3",
|
"unity": "2022.3",
|
||||||
|
|||||||
Reference in new issue
Block a user