FSFisGOOD
FSFisGOOD

Reputation: 183

Using .Net Library in Unity5

I have a huge project written in c# using .Net 3.5 I need to use Unity3D for my project. I tried to import Unity into my project but I found out that it is not possible. So, now I want to import the code that I have written in C# into Unity. I created a library using the code that I already have, to import it into Unity and use it. But when I try to import it I receive the following error:

Unhandled Exception: System.TypeLoadException: Could not load type 'SpeechTools.ClsSpeechSynthesis' from assembly 'MySpeechSynthesizer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. Could not load file or assembly 'System.Speech, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies.

I am using System.Speech in my library. It is not supported in Unity (Mono). I guess the problem is caused by this dependency.

Can anyone help me? Is there a way to write a wrapper around System.Speech.SpeechSynthesizer and use it in Unity?

I searched online and I found a lot of tutorials on writing wrappers for c++ codes but nothing for c# and .Net libraries.

Upvotes: 1

Views: 788

Answers (1)

Sam
Sam

Reputation: 3480

System.Speech is not supported by Unity's version of Mono, so you're out of luck. You also can't just drop in the Windows version of the System.Speech DLL since it probably won't work with Unity's version of Mono.

You can't write a C# wrapper DLL that uses System.Speech either because that is essentially the same as dropping the DLL straight in. Unity's Mono will try to load it and fail.

You'll have to find either a native library that implements the feature you want and write a wrapper around that, or write an implementation entirely in C#.

You could potentially write a native wrapper (i.e. in C++) around the C# DLL. This wrapper would initialise the CLR and load the C# DLL. Then the native wrapper would be referenced in Unity. You would have to expose the entire System.Speech API through this native wrapper. I think this would work, but it is pretty cumbersome and would only work on Windows or platforms where .NET is available (i.e. no web player, mobile, Linux, OS X).

Upvotes: 1

Related Questions