Skip to content

Commit

Permalink
1.1 添加可加载依赖
Browse files Browse the repository at this point in the history
  • Loading branch information
3DMXM committed Sep 23, 2022
1 parent dab1a72 commit 54a5ea8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
26 changes: 25 additions & 1 deletion ScriptEngine/ReloadPlugins.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,10 @@ public void LoadMods(string path)
{
Debug.Log($"开始加载 {path}");

string scirptsPath = Path.Combine(ModManager.GetModRootFolder(), "scirpts");

var defaultResolver = new DefaultAssemblyResolver();
defaultResolver.AddSearchDirectory(Path.Combine(ModManager.GetModRootFolder(), "scirpts"));
defaultResolver.AddSearchDirectory(scirptsPath);

var dll = AssemblyDefinition.ReadAssembly(path, new ReaderParameters { AssemblyResolver = defaultResolver });
dll.Name.Name = $"{dll.Name.Name}-{DateTime.Now.Ticks}";
Expand All @@ -137,6 +139,28 @@ public void LoadMods(string path)
// 判断是否继承自 MonoBehaviour
if (type.IsSubclassOf(typeof(MonoBehaviour)))
{
//Debug.Log($"依赖数量:{ass.GetReferencedAssemblies().Length}");
// 加载相关依赖
foreach (var item in ass.GetReferencedAssemblies())
{

try
{
string file = Path.Combine(scirptsPath, $"{item.Name}.dll");
if (File.Exists(file))
{
Assembly.LoadFile(file);
Debug.Log($"加载依赖 {item.Name} 成功");
}

}
catch (Exception e)
{
Debug.Log($"加载依赖 {item.Name} 失败");
}

}

scriptManager.AddComponent(type);
Debug.Log($"加载 {path} 成功");
}
Expand Down
2 changes: 1 addition & 1 deletion ScriptEngine/ScriptEngine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>F:\steam\steamapps\common\太吾绘卷 The Scroll Of Taiwu 功能测试\Mod\ScriptEngine\Plugins\</OutputPath>
<OutputPath>F:\steam\steamapps\common\The Scroll Of Taiwu\Mod\ScriptEngine\Plugins\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
Expand Down

0 comments on commit 54a5ea8

Please sign in to comment.