The project Unity3d made is very easy to decompile, and all of your resources and code will be rendered without a cover-up after being recompiled. Since. NET itself has no encryption, we generally use confusing code to encrypt the program in some way. in the next 2 blogs, I'll simply talk about my own cryptographic practices in the Unity3d program. First of all, I'll briefly explain how to use DLL dynamic-link libraries in Unity3d, and then the second article will explain how to confuse DLLs.
Start the content of the first article:
For more information, please visit the "Dog Planing Learning Network" http://unity.gopedu.com
First, we need to create a new class library project that can be done using Visual Studio or MonoDevelop. Here I use vs2012 to create:
Select the project type and write the project name.
The newly generated project has a default Class1 class
You can change the name of the class you want by renaming it in Solution Explorer, like I changed it to Math3d.
Then write a simple static method inside. Here I have written the simplest addition (add). Also can not write static method, write the ordinary public method, use when the new object comes out to call this method also can. This is no different from normal C # programming.
After writing, in the Explorer to select "Generate", then in the project Bin/debug will see the DLL file, such as my this amount is AzhaoDll.dll
Next, create the project you need in Unity3d and put the DLL file in the project's assets folder. About this DLL file storage location, some people on the internet said that it must be placed in the plug-in folder, in fact, is not needed, in any location it can be recognized. Of course, according to good project path habits, we set up a dedicated plug-in folder to store DLL files, it is also reasonable.
Then create a C # script in Unity3d and write a simple line of code to invoke the Math3d.add method we just wrote.
You will find that the Math3d class is not recognized, and we using the Azhaodll namespace
Then in the Unity3d to hang the script on the camera, run, you can see the correct results are printed, which proves that the DLL has been successfully called.
Look back at some of the little details we've just done, inside the class library project's Math3d class. We use the Azhaodll namespace by default. So what if we don't use namespaces, or do we use other namespace rows? The answer is yes, the namespace can be arbitrarily changed, if not the namespace, then you do not need the use of the call, if other namespaces, the corresponding using its namespace is OK.
Try to delete the namespace:
Then the call in the Unity3d can be used directly:
The result of the operation is also normal:
Of course, it is not recommended not to use namespaces, this is a description, because the script created by Unity3d itself does not use the namespace, just to illustrate that if you do not want trouble, directly to the Unity3d no namespace script directly to compile is also possible.
Looking again at the details, just now we are using native C #, what if we need to write a method to invoke Unity3d's own function in a class library project?
In Unity3d's installation directory editordatamanaged, find UnityEditor.dll and UnityEngine.dll two files.
Then add a reference to the class Library project and add the two DLLs in
At this point, we can use the Unity3d method in the Class library project using Unityengine, for example, we write a creategameobject method here, and generate a gameobject named "Createbydll".
Build the DLL, put it back in the Unity3d project, and we can call this method:
Run and see this object called "Createbydll" generated.
With the above instructions, we will find that it is very simple to build your own DLL in Unity3d. We can also add other class-in-class library projects that we have written, and then build DLLs to use.
Finally, let's talk about the precautions.
The DLL that you just generated is basically available in the Unity3d editor, but it doesn't have to be compiled. It is possible to make an error when compiling an EXE or APK.
It is important to note that the. Net framework version is used by the class library project. My own attempt was to use a DLL published in the. Net 4.0 version, which would not be compiled in Unity3d. So we can use a version of 2.0 or 3.0 to publish.
There are also cases where some off-the-shelf DLL dynamic libraries are used intact. Net2.0 to publish, so we may need to choose the full. Net 2.0来 release when compiling.
At this point, we can cut all the scripts in Unity3d's entire code folder into the Class library project to generate the DLL and put it back inside the Unity3d project. So that others can not directly edit the code in our project.
But the DLL itself is unsafe, others can easily see inside the content. Next blog We explain how to confuse the DLL.
For more information, please visit the "Dog Planing Learning Network" http://unity.gopedu.com
Unity3d Project program encryption to use your own DLL in Unity3d