Cleaned up PluginLoader class.
This commit is contained in:
parent
39158411ca
commit
7801e9ec45
@ -9,18 +9,18 @@ public class PluginLoader :MonoBehaviour
|
|||||||
{
|
{
|
||||||
private Assembly assembly;
|
private Assembly assembly;
|
||||||
|
|
||||||
// Adds machines from mods to the game.
|
// Adds plugins from mods to the game.
|
||||||
public void Start()
|
public void Start()
|
||||||
{
|
{
|
||||||
string modPath = Path.Combine(Application.persistentDataPath, "Mods");
|
string modPath = Path.Combine(Application.persistentDataPath, "Mods");
|
||||||
string[] modDirs = Directory.GetDirectories(modPath);
|
string[] modDirs = Directory.GetDirectories(modPath);
|
||||||
foreach (string path in modDirs)
|
foreach (string path in modDirs)
|
||||||
{
|
{
|
||||||
string machinePath = path + "/Plugins/";
|
string pluginPath = path + "/Plugins/";
|
||||||
DirectoryInfo d = new DirectoryInfo(machinePath);
|
DirectoryInfo d = new DirectoryInfo(pluginPath);
|
||||||
foreach (FileInfo file in d.GetFiles("*.dll"))
|
foreach (FileInfo file in d.GetFiles("*.dll"))
|
||||||
{
|
{
|
||||||
string filePath = machinePath + file.Name;
|
string filePath = pluginPath + file.Name;
|
||||||
string pluginName = file.Name.Remove(file.Name.Length - 4);
|
string pluginName = file.Name.Remove(file.Name.Length - 4);
|
||||||
LoadPlugin(pluginName, filePath);
|
LoadPlugin(pluginName, filePath);
|
||||||
Debug.Log("Loading mod plugin: " + pluginName);
|
Debug.Log("Loading mod plugin: " + pluginName);
|
||||||
@ -78,8 +78,7 @@ public class PluginLoader :MonoBehaviour
|
|||||||
Type type = dll.GetType(pluginName);
|
Type type = dll.GetType(pluginName);
|
||||||
if (type != null)
|
if (type != null)
|
||||||
{
|
{
|
||||||
GameObject obj = new GameObject();
|
GameObject obj = new GameObject { name = pluginName };
|
||||||
obj.name = pluginName;
|
|
||||||
obj.AddComponent(type);
|
obj.AddComponent(type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user