Unity3d a dynamic library (DLL) that is loaded into C++/CLI (managed mode C + +) __c++

Source: Internet
Author: User

Due to the recent development of game find Road A * is used very frequently. So it's a logical bottleneck. C # is one times slower than C + +. So decide on C + +. This is an optimization. haha.

On vs VC + +. Sub-managed and unmanaged mode. Managed mode is C++/CLI also says you can use. NET libraries in C + +.  And the CLR are together. Also, unmanaged mode is the traditional C + + direct call Win32 API.

You can create a DLL in either of these ways. But it's more convenient to use it with C #. Here's how to Unity3d using the CLR's c++/cli. The internet is full of the use of unmanaged mode C + + and unity used in the way, where the Buddha is not elaborated.

The book belongs to the story:


Environment:

1. vs2012 or vs2013.

2. unity4.3.0


First, the creation of a CLR project.

Open vs. then new. This is the choice. A CLR Library project.



Then you enter the project. Then add the following code to test whether the DLL is being used. A and B are added to return the result. Very simple program.



After that, you need to change the properties of some items. Because Unity uses the mono reason.

The 1.framework3.5 is a unity version. Here my vs is 2012/2013 using FW 4.5. So high here needs to be lowered. Because there is no option in the IDE, you need to open the Proj file to modify the version.



It's OK to change the v4.5 into v3.5.


2.CLR is also a lot of versions. Unity supports safe's CLR. So this also needs to change.


Right Key property above the item.


Choose Safe's CLR. It's OK. Then compile it out of the DLL.


And in the end, copy the DLL to unity. Unity needs to build a plugin folder to store the DLL.


After putting it in this folder, unity can be used.

Then we create a Unity C # script. To invoke the TSENGINECLI.


Then drag the C # script onto a random gameobject. Run it. You will see 3 output in the console box. The description is done. Wow, quack.


All right, I hope you all have a good time. Happy knitting.




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.