- Home /
How do I use a C# dll library from a script?
I found two math dlls written in c# that I would like to use in Unity3d. one is dotnumerics.dll and another one called MathNet.Iridium.dll
I want to access the routines in these libraries from javascript.
I tried putting the dotnumerics.dll into the assets folder but then what?
I also tried lines like
import DotNumerics
but that doesn't work either.
Does anybody know how to access a c# dll from unity javascript?
thanks,
Dan
Any luck with this? I'm trying to use $$anonymous$$athNet.Numerics too. I tried to recompile it in Visual Studio for .Net framework 3.5 but then realised that System.Numerics is only available from 4.0. So I'm stuck...
Answer by DaveA · May 15, 2011 at 01:36 AM
Try creating a Plugins folder under Assets and move the dll files there.
Yes. But it's more about creating your own plugin and does not have examples for accessing C# libraries from javascript in the webplayer. Apparently it can be done ...so I hear.
I'm not able to make the connection between that document and accessing the library. I'm not familiar with CS just JS for Unity3d.
Hmm. Not sure your problem then. I was able to simply copy a DLL to my Plugins folder, and access it like it was a regular script (just not see the code). I think I had to drag/drop the dll onto a game object, I forget.
Answer by cjmarsh · May 15, 2011 at 10:18 AM
You need to reference the specific namespace you are using in the .dll file. For example, (in C#) if you were to use the DotNumerics package for Linear Algebra you'd have to code the following:
using DotNumerics.LinearAlgebra;
using DotNumerics;
Similarly, for MathNet.Iridium:
using MathNet.Numerics;
using MathNet.Numerics.LinearAlgebra;
How would I access the dll routines from javascript? The examples are all in CS. Someone said that they act just like regular .NET libraries. That's why I was trying to use Import statements...i use import to access the .NET regular expressions library routines... do I first have to create a CS wrapper or something before I use the javascript?
I'm not entirely sure about the JavaScript aspect. The thing is unity actually uses it's own version of JavaScript which is CLR compliant (inter-operable with languages like C++ and C#) so it should be able to import those .dlls (assu$$anonymous$$g you use import rather than using). You could also write a C# wrapper if it doesn't work and basically just import the namespace Wrapper.* or something similar.
It could be the dll itself. Is there a sample dll I could use that everyone knows works? I need to do some sort of testing but am not sure what test to try next.
I tried another dll: dnAnalytics and it gets past the import statement without an error, but then I'm not exactly sure how to call a function. For example there is a function StandardDeviation() but calling StandardDeviation does not work nor does calling Statistics.StandardDeviation() which I believe is the "Namespace?" I'm not sure I understand how to use these namespaces classes, methods in a function call. Right now I get an error that says StandardDeviation is not a member of dnAnalytics or dnAnalytics.Statistics.
http://www.csharp-station.com/Tutorials/Lesson06.aspx has a good tutorial on the differences between namespaces, classes(objects), and methods(functions,programs,etc.). As for the math packages in particular, I can't say I'm too familiar with their implementation as I'm currently translating my math equations into binary numbers.
Your answer
Follow this Question
Related Questions
How do I reference components inside a managed .dll? 1 Answer
How do you compile a managed dll with mono/mcs targeting .net 2.0 or 3.5 for Unity? 1 Answer
Cannot compile .exe with specific .dll. (but with other .dlls created the same way) 0 Answers
Is there a garantee that managed Dll plugin will compile on to mobile? 0 Answers
Using dll file from c++ 1 Answer