Hello everyone,
I am working on a project where I need to interact with Unity’s Mono API directly for native plugin work and more low-level functionality.
Could someone guide me on how to access Unity’s Mono API? I’m looking for advice on how to integrate and use Mono within Unity projects.
I came across some code written by ChatGPT for this purpose, but unfortunately, it doesn’t compile in my native plugin.
MonoAssembly* unityAssembly = mono_domain_assembly_open(domain, "UnityEngine.dll");
MonoImage* unityImage = mono_assembly_get_image(unityAssembly);
MonoClass* debugClass = mono_class_from_name(unityImage, "UnityEngine", "Debug");
// Find the Log method
MonoMethodDesc* methodDesc = mono_method_desc_new("UnityEngine.Debug:Log(string)", false);
MonoMethod* logMethod = mono_method_desc_search_in_class(methodDesc, debugClass);
mono_method_desc_free(methodDesc);
// Create a MonoString for the message
MonoString* monoMessage = mono_string_new(mono_domain_get(), message);
// Prepare the arguments
void* args[] = { monoMessage };
// Call the Log method
mono_runtime_invoke(logMethod, nullptr, args, nullptr);
Any help or pointers to documentation would be greatly appreciated!