I am working on a game engine + editor in C #. The idea is that the user writes all of his game code into a project, which the editor then loads, so he can display custom classes and also create them in the scene editor.
By immersing the concept of (re) loading DLLs, I can load the DLLs, instantiate and call methods in the class defined in the external assembly, rebuild the external assembly and load it again into the host without restarting the guest. And this work (at least similar to it), however, it does not free memory from the previously loaded assembly.
Bootloader class:
public class Loader
{
private const string AsmPath = @"D:\Dev\AsmLoading\AsmLoadingImpl\bin\Debug\AsmLoadingImpl.dll";
public ILoadable GetExternalLoadable()
{
var asmBytes = File.ReadAllBytes(AsmPath);
Assembly asm = Assembly.Load(asmBytes, null);
var loadableInterface = typeof(ILoadable);
var loadableImpl = asm.GetTypes().First(loadableInterface.IsAssignableFrom);
return (ILoadable)Activator.CreateInstance(loadableImpl);
}
}
GetExternalLoadable() 2 3 , 1 -, , .
? , Unity , , , Unity , .
, " " .