Not sure if I’m overlooking something here and may need to try a multi thread approach but wanted to ask.
We are integrating a speech engine with unity via a plug-in.
Now with this speech engine it needs to be running continuously. As far as I see it, that is not going to work with a dll based system. The dll is called and intended to run without a continues loop ( I would think ) . So I was wondering is there an event call for a dll?
Alternatively a button could turn on the speech engine from the users perspective, but that would stop all game attributes. So would there be a way to some how run a bit of code off of the main engine loop?
dreamora, thx so much for your reply. Can you help me understand where I’m failing to understand?
// The function we will call from Unity.
//
// We pass the Color array, texture size and current time to the plugin.
// The C++ plugin then assigns noise-like colors to the color array.
void EXPORT_API UpdateTexture( void* colors, int width, int height, float time )
I read this as unity calling this code. If I put any type of loop in this code unity locks up. How can I loop say, just for example, a sound. Understating of course this would be pointless, but for sake of argument.
You need to create new thread for time consuming operations.
For Windows DLL, check CreateThread (or _beginthreadex) and for OS X dynlib check pthread_create.
You can use callbacks in plugins to inform when your functions has done something etc.
In Windows (MinGW compiler) callback looks something like this:
#define EXPORT __declspec(dllexport)
// Reference for external callback
static const char*(__stdcall *callback_func)(char * buffer, int bufferLength);
EXPORT void SetCallbackRef(const char*(__stdcall *f)(char * buffer, int bufferLength))
{
callback_func = f;
}
There is no plug-in API, but there is some information about using plug-ins here in the manual. At the bottom of that page, there are also some links to useful material about using the Mono runtime with C/C++ code.
Then what is “UpdateTexture” ? surly that is a unity function of some type? There is no way the unity3d team would expect people to guess function names? I got this example form that link you posted. This info is nice but there has to be some way for a plug-in developer to know what functions they can call? – I’m missing something I know, but just dont know what?