Unity3d load C ++/CLI (managed Mode c ++) dynamic library (DLL)

Source: Internet
Author: User

Due to the recent development of game path A *, it is frequently used. therefore, it is a logical bottleneck. c # is twice slower than c ++. therefore, c ++ is decided. this is an optimization. haha.

About vc ++ on. managed mode and non-managed mode. the hosting mode is C ++/CLI, which can be used by c ++. net Library. and CLR. in addition, in the unmanaged mode, the traditional c ++ directly calls the win32 API.

You can create a dll in either of the two methods. however, if it is used with c #, it must be a more convenient hosting mode. the following explains how to use C ++/CLI of CLR in unity3d. the Internet is full of ways to use the unmanaged Mode c ++ and unity, so I will not elaborate on it here ..

Returning to the original post:


Environment:

1. vs2012 or vs2013.

2. unity4.3.0


First, let's talk about creating a CLR project.

Open vs. and create a new one. At this time, select the. CLR library project.



Then you enter the project. Then add the following code to test whether the dll is used. a and B are added to return results. a very simple program.



Then, you need to modify the attributes of some projects because unity uses mono.

1. framework3.5 is the unity version. here my vs is 2012/2013 using fw 4.5. so if it is too high, we need to downgrade it. because there is no option in IDE, you need to open the proj file to modify the version.



Change v4.5 to v3.5.


2. clr is also available in many versions. unity supports safe clr, so this also needs to be changed.


Right-click Properties on the project.


Select safe clr. then compile the dll.


The last step is to copy the dll to unity to use it. unity needs to create a plugin folder to store the dll.


Put it in this folder. unity can be used.

Then we create a unity c # script to call TSEngineCLI.


Drag the c # script to a random GameObject and run it. The Console box is displayed. 3. The result is displayed. Wow.


Okay. I wish you a good time. Make sure you have a good time ~...




Related Article

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.