HideCodeWithDLL other can not see the code except decompiler suc
-
创建类库项目,此处暂时没找到一次项目创建多个dll文件的方法,即类似Unity中AssemblyDefinitionFile的自定义程序集功能。
图1-1
-
注意命名方式,生成的动态链接库会以改名字生成,注意这里的命名不同于命名空间,这里是程序集命名。
图1-2
-
创建之后的会进入第一个类文件Class1,这里已经将命名空间改为项目的名称。
图1-3
-
添加依赖项(添加Unity相关类库的依赖),在项目下拉框下,点击添加项目引用,会弹出一个浏览文件窗口,再定位到你电脑中Unity的类库的位置,如图1-5所示。
图1-4
图1-5
-
添加了依赖项之后就可以开始编写Mono脚本,添加UnityEngine的引用,撰写脚本,如图1-6。
图1-6
- 生成解决方案,步骤为下图1-7,结果为图1-8。
图1-7
图1-8
图1-9
- 使用类库中的相关类。
图1-10
图1-11
- Inspector面板和运行结果。
图1-12
图1-13
- 构建相关的AssemblyDefinationFile文件控制相关的代码,我的文件结构如下:
图2-1
- 在Unity项目中找到对应的DLL文件,将其拖入Unity中。
图2-2
- 拖入项目后,还不能将DLL文件中的Mono脚本挂在场景中的GameObject上,此时要将源码和ADF文件删除。
图2-3
- 将Mono脚本挂载在相关的脚本上。
图2-4
图2-5
- 运行游戏打印结果
图2-6
1.经过推敲,如果是项目代码需要隐藏,可实施性不大,因为代码在不停的修改,不停的生成最新的DLL文件,即使是使用Unity自带的目前最新的Roslyn Compiler,直接将新生成的DLL文件放入工程以DLL的形式跑代码(上述方法二),也是一件很费时的事情。
2.此法最好隐藏代码是写一个插件,插件以DLL的形式引用、调用、甚至挂载在GameObject上。
*相关资料查询:*
DLL构建、隐藏代码
https://answers.unity.com/questions/1707814/how-to-hide-c-code-from-custom-package-for-distrib.html
https://www.jacksondunstan.com/articles/3052
https://answers.unity.com/questions/1078603/unity-editor-script-in-dll.html
https://www.youtube.com/watch?v=CPkO1Gek8XQ
ADF
https://blog.csdn.net/baidu_39447417/article/details/115151569