contunies plug in code?

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?

Your functions call the plugins.
Without C# code for the wrapper and additional code for functionality, plugins don’t do anything actually.

So you have all events at hand you have present regularily.

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;
}

In C# callbacks are used like this:

    // Delegate for DLL event handling
    delegate void DLLCallBack(IntPtr buffer, int bufferLength);

    [MarshalAs(UnmanagedType.FunctionPtr)]
    DLLCallBack dllCB;

    [DllImport("myPlugin")]
    private static extern void SetCallbackRef(DLLCallBack dllCB);

Hope this helps!

BR, Juha

Yes this does…thx.

Is there a flow chart that shows the relationship of the dll handling and unity anywhere?

also What about a plugin api reference?

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?

As far as I know, there’s no way for plugins to directly call Unity functions.

Unity scripts can call plugin functions, and change their behavior based on the result, but not vice-versa.

In fact, the callback example in my previous post is an example where managed C# function is called from unmanaged DLL…

More info: Calling Managed .NET Function from Unmanaged Windows Custom DLL. - CodeProject

BR, Juha

Thx for the info JFo.

–Ahh ok that could work. Was not thinking of it in reverse . that or I was thinking reverse .