1.c# encapsulated DLLs
Now create a class in VS, just write a simple static class and static method can be, as follows:
namespace pnsd{ publicstaticclass pn { public Staticstring getName (string name) { return name; } }}
Then compile it into a DLL file named Pnsd.dll.
2. Using custom C # encapsulated DLL components in Unity
Create a Plugins folder in unity, and all externally referenced DLL components must be placed under this file to be used
using Unityengine; using System.Collections; using pnsd; // Not the name of the DLL file, but the name of the namespace public class Test:monobehaviour { void Start () { string name = Pn.getname ( "PNSD ); // class name. Method Name Debug.Log (name); // output result
3. First build a DLL project with VC
4. Then create a testunity.h file inside. The contents are as follows
extern " C " int // defining the Out -of-the-way interface
Save, OK, at the establishment of a testunity.cpp, the code is as follows:
#include "testunity.h" int testunity () { return 0;//This is a function that can write any function you want to implement}
Then compile, build. The Testunity.dll file is generated.
Then put this file in your Unity project's assert plugins (if you don't have this file, you'll have to create it)
Then create a new C # script file Dlltest inside unity. The code is as follows
usingUnityengine;usingSystem.Collections;usingSystem.Runtime.InteropServices; Public classDlltest:monobehaviour
{[DllImport ("testunity")] Private Static extern inttestunity (); //Use this for initialization intI=testunity (); voidStart () {print (i); } //Update is called once per frame voidUpdate () {}}
Then drag the file into the camera inside unity and it's OK.
Then run, you can achieve the effect of ha.
If it is a C # encapsulated DLL, it is referenced by using, and if it is a C + + DLL, dllimport[". dll" to add a reference to the DLL
Unity3d calling VC and CSharp DLLs