修复打包脚本调用找不到类

main
xiaohang 2024-04-08 19:00:32 +08:00
parent f98ae3e001
commit bbd013b7a0
1 changed files with 24 additions and 16 deletions

View File

@ -1,5 +1,6 @@
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using Guru.Editor;
using UnityEditor;
@ -249,23 +250,30 @@ public class BuildTool
{
PlayerSettings.SplashScreen.show = false;
PlayerSettings.SplashScreen.showUnityLogo = false;
Assembly assembly = Assembly.GetAssembly(typeof(IBuildImp));
var types = assembly.GetTypes();
foreach (var item in types)
{
if(item.IsInterface) continue;
var interfaces = item.GetInterfaces();
foreach (var interfaceType in interfaces)
{
if (interfaceType == typeof(IBuildImp))
{
var instance = Activator.CreateInstance(item) as IBuildImp;
Debug.Log(instance.GetType().Name);
instance.OnGuruSDKBuildPreprocess(targetGroup, buildParam);
break;
}
}
var assembly = AppDomain.CurrentDomain.GetAssemblies()
.FirstOrDefault(a => a.GetName().Name == "Assembly-CSharp-Editor");
if (assembly == null) {
Debug.LogError("Assembly-CSharp-Editor not found.");
return;
}
// 找到实现了IBuildImp接口的类
var type = assembly.GetTypes()
.FirstOrDefault(t => t.GetInterfaces().Any(i => i.Name == "IBuildImp"));
if (type == null) {
Debug.LogError("IBuildImp implementation not found.");
return;
}
// 创建实现类的实例
var instance = Activator.CreateInstance(type) as IBuildImp;
if (instance == null) {
Debug.LogError("Failed to create an instance of IBuildImp implementation.");
return;
}
instance.OnGuruSDKBuildPreprocess(targetGroup, buildParam);
}
private static void BuildAndroid(BuildParam buildParam)