Unity打包代码到DLL的实现
作者:[奋斗不止] 时间:2022-06-28 08:38:17
使用Unity API PlayerBuildInterface.CompilePlayerScripts 将项目中的代码生成为 DLL 程序集
在 Editor 文件夹下新建脚本 CompileDll
using UnityEngine;
using UnityEditor;
using UnityEditor.Build.Player;
using System.IO;
public class CompileDll
{
// 菜单栏添加按钮
[MenuItem("Tools/CompileDll")]
static void Compile()
{
// 设置需要打DLL 的平台
BuildTarget target = BuildTarget.StandaloneWindows64;
ScriptCompilationSettings scriptCompilationSettings = new ScriptCompilationSettings();
scriptCompilationSettings.group = BuildPipeline.GetBuildTargetGroup(target);
scriptCompilationSettings.target = target;
// 获取 dll 输出目录
string outDir = Application.dataPath;
outDir = outDir.Substring(0, outDir.IndexOf("Assets"));
outDir = string.Format("{0}DLL", outDir);
if (!Directory.Exists(outDir))
{
Directory.CreateDirectory(outDir);
}
// 编译DLL
ScriptCompilationResult scriptCompilationResult = PlayerBuildInterface.CompilePlayerScripts(scriptCompilationSettings, outDir);
foreach(var ass in scriptCompilationResult.assemblies)
{
Debug.LogFormat("compile assemblies:{0}/{1}", outDir, ass);
}
}
}
点击 Tools->CompileDll 按钮,在 代码中 outDir 目录下生成所有 dll 以及 对应的 .pdb
如上 DLL 程序集是如何确定名字的?
如上 AA.dll
在 需要生成 AA.dll 的 C# 脚本目录下,新建 AA.asmdef
在 C# 脚本所在目录 右键 Create -> Assembly Definition
然后生成一个 .asmdef 的文件,选择文件在 Inspector 面板输入名字
然后在 AA.asmdef 目录新建一个 Npc.cs
选择 Npc.cs 看 Inspector 面板可以看到 Npc.cs 归属于 AA.dll 程序集
具体细节可以学习了解 Unity asmdef 文件的创建以及作用
在项目中任意选一个 C# 脚本,都可以在 Inspector 面板看到它归属的 dll 程序集
这就是上面执行编译导出的 dll 的来源
来源:https://blog.csdn.net/LIQIANGEASTSUN/article/details/129346814
标签:Unity,打包,DLL
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
深入分析Android系统中SparseArray的源码
2022-09-16 13:54:42
Caused by: java.lang.ClassNotFoundException: org.apache.commons.collections.Transformer异常
2022-07-03 11:12:34
浅析C# 函数的传值与传址
2023-11-22 04:46:57
![](https://img.aspxhome.com/file/2023/0/71730_0s.png)
Java System类两个常用方法代码实例
2023-02-01 13:52:15
![](https://img.aspxhome.com/file/2023/8/71238_0s.png)
java搭建ftp/sftp进行数据传递的全过程
2023-11-29 15:08:10
![](https://img.aspxhome.com/file/2023/6/60486_0s.png)
关于@GetMapping和@GetMapping(value=““)的区别
2023-11-27 11:07:37
![](https://img.aspxhome.com/file/2023/2/59992_0s.png)
java微信公众号支付开发之现金红包
2023-09-01 17:28:38
![](https://img.aspxhome.com/file/2023/3/66163_0s.jpg)
Mybatis 动态SQL的几种实现方法
2023-11-10 12:15:15
SpringCloud学习笔记之OpenFeign进行服务调用
2021-05-25 12:32:58
![](https://img.aspxhome.com/file/2023/0/62830_0s.png)
使用mybatis-plus的insert方法遇到的问题及解决方法(添加时id值不存在异常)
2023-11-12 19:25:55
![](https://img.aspxhome.com/file/2023/6/59606_0s.png)
Java StringUtils字符串分割转数组的实现
2023-07-19 12:43:37
java 2d画图示例分享(用java画图)
2023-07-25 22:03:52
MyBatis-Plus多表联查(动态查询)的项目实践
2023-11-19 21:43:17
![](https://img.aspxhome.com/file/2023/3/59663_0s.png)
java生成图片验证码实例代码
2022-01-06 04:01:37
Java实现天天酷跑小游戏完整代码(附源码)
2021-08-03 09:43:43
![](https://img.aspxhome.com/file/2023/3/60833_0s.png)
解决SpringBoot中MultipartResolver和ServletFileUpload的冲突问题
2023-10-22 15:28:19
![](https://img.aspxhome.com/file/2023/1/60841_0s.png)
SpringIOC BeanDefinition的加载流程详解
2023-11-25 18:06:22
![](https://img.aspxhome.com/file/2023/8/59938_0s.png)
深入了解Java核心类库--Math类
2023-08-19 01:06:21
使用@Validated 和 BindingResult 遇到的坑及解决
2022-12-18 20:36:28
![](https://img.aspxhome.com/file/2023/3/64223_0s.png)
说说在Spring中如何引用外部属性文件的方法
2023-09-18 21:47:25
![](https://img.aspxhome.com/file/2023/2/77152_0s.png)