1

I have created one package from some of my prefabs in my project. these prefabs have some C# codes in them and what i want is to encrypt these codes like no one can see the actual codes!!

I've seen some packages that use ".dll" files and in their code files they just use their own methods. i wanted to build a dll file from my code like what it said in this link

http://www.c-sharpcorner.com/article/creating-C-Sharp-class-library-dll-using-visual-studio-net/

but i couldn't get any dll file!

What should i do?!!

Reynevan
  • 1,475
  • 1
  • 18
  • 35
Hooman BZ
  • 53
  • 1
  • 8

1 Answers1

4

First of all, compiling your code into a DLL only makes it more difficult for people to read it. It doesn't encrypt it per se.

Still, if you want to compile your code into a .dll, you'd need to make a new project in VS/MonoDevelop and set the outbut to Class Library. Then, after building your code you should get a nice 'n round DLL file in the bin folder. As far as I can tell, you can then embed this file into your Unity project by just drag and dropping it onto the Project window.

More info here: Managed Plugins

Also, remember that with this approach comes an important limitation (well, it isn't a limitation exactly, but it can get confusing at first). You're creating another aassembly, so you can't reference your regular .cs files directly from the classes in the .DLL file. That means that you should keep it standalone.

Also, as a side note: It's not always a good idea to compile your asset's code into a DLL file -- especially if the classes inside are using UnityEngine.* or UnityEditor.* namespaces. The Unity editor is constantly changing, and with each update the Scripting API changes.

If you decide to package the code this way, you should take responsibility for it working on future versions of Unity, since most people won't know how to fix eventual errors.

Reynevan
  • 1,475
  • 1
  • 18
  • 35
  • Thanks a lot @Reynevan.... So what is the best way to encrypt the code?! – Hooman BZ Sep 11 '17 at 07:29
  • You don't *encrypt* the code. You could [look up this SO post](https://stackoverflow.com/questions/506282/protect-net-code-from-reverse-engineering), but ultimately, it's not something that you should worry about too much. You could obfuscate your code I guess. – Reynevan Sep 11 '17 at 15:59
  • But why would you want to secure your code to such a degree on a Unity package? – Reynevan Sep 11 '17 at 16:00