|
Is it possible to call a separately created C# assembly from Unity? I have an assembly I created for controlling a piece of hardware that was developed in C# using .NET 3.5 and I'd like to be able to call it from Unity. For example, when a users avatar collides with an object, I need to be able to call a function in the external library that will make the hardware do something. Is this possible? What is the easiest way to go about it?
(comments are locked)
|
|
The problem is because you're using a .Net 3.5 assembly, whereas Unity ships with a version of Mono that is equivalent to .Net 2.0. While Unity supports external assemblies via Mono, your assembly has dependencies on a more recent version (System.Runtime.Serialization 3.0, judging from your comment). Hmmm...so it's looking like my only option might be to figure out how to register by dll for COM interop and import it with a bunch of DllImport's? In other words, back to what Tetrad suggested!
Dec 08 '09 at 07:57 PM
Matt
Never tried that approach, to be frank. If you have the source for the DLL, you could rebuild it with .Net 2.0, but more convoluted approaches might be required if you only have the compiled library.
Dec 08 '09 at 08:04 PM
Ricardo
Actually, I do have the source, but I can't compile it to .NET 2.0 since it's using WCF and I'd have to work out another way to do that. Yes, it's layer upon layer of stuff going on which all seemed like a good idea at the time!
Dec 08 '09 at 09:01 PM
Matt
Which is 3.0 only. Ding!
Dec 08 '09 at 09:04 PM
Ricardo
(comments are locked)
|
|
Have you read the documentation on plugin support? http://unity3d.com/support/documentation/Manual/Plugins.html Not especially helpful since it talks about plugins written in C, C++ or objective-C. I want to be able to instantiate an object of a type defined in my C# dll and use it. Since it's .NET, I thought it would be easier than using a bunch of DllImport's
Dec 08 '09 at 06:38 PM
Matt
(comments are locked)
|
|
Yeah. If it's a normal .NET assembly, just copy the .dll to anywhere in your Assets folder, and Unity will detect and use it. Also, when Unity generates the sln/csproj files, it's nice enough to adds the reference to that file for you too. The problem is that when I added my dll it complained that Unity complained that it could load it because it doesn't have access to System.Runtime.Serialization. I tried adding that library as well, but it seems it can load it. BCE0106: Failed to access the types defined in assembly 'System.Runtime.Serialization, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' Any ideas?
Dec 08 '09 at 06:10 PM
Matt
I see. Sorry, i overlooked your mention of .NET 3.5 in your question.
Dec 08 '09 at 08:07 PM
Lance Sun
(comments are locked)
|
|
I assume you don't have the source... in that case, this is a longshot, but if you only need DataContractSerializer and maybe a few other things from System.Runtime.Serialization, you can try grabbing the S.R.S assembly from the Moonlight 2.0 beta. C# 3.5 compiles for the 2.0 CLR, so it theoretically could work.
(comments are locked)
|
|
Okay, so it looks like I'm pretty much screwed at the moment, which is disappointing. I was gravitating towards Unity precisely because I could use my C# skills and hoped it would be fairly straight forward to integrate with code I already have.
(comments are locked)
|
1 2 next page »
