Skip to content

Instantly share code, notes, and snippets.

@z3t0
Last active July 4, 2016 07:36
Show Gist options
  • Save z3t0/12c3f400827ae915446182537b0ba32d to your computer and use it in GitHub Desktop.
Save z3t0/12c3f400827ae915446182537b0ba32d to your computer and use it in GitHub Desktop.
loader.createInstance = (Type t) =>
{
string fileName = t.ToString() + ".cs";
Debug.Log(t.GetType());
foreach (var mod in modLoader.mods) {
string modPath = mod.path + "/Scripts/";
foreach (var script in mod.scripts) {
string shortPath = script.Substring(modPath.Length);
if(shortPath == fileName) {
Debug.Log("found a match: '" + fileName + "' is from Mod: '" + mod.name + "'");
if(typeof(Component).IsAssignableFrom(t)){
return mod.gameobject.AddComponent(t);
// return mod.loadedScripts.Add(fileName, t);
}
}
}
}
Debug.Log("Script: '" + fileName + "cannot find its Mod");
return System.Activator.CreateInstance(t);
};
void CreateNewInstances()
{
if (assembly == null) return;
foreach (var type in assembly.GetTypes())
{
manager.synchronizedInvoke.Invoke((System.Action)(() =>
{
instances.Add(manager.createInstance(type));
}), null);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment