Unity打包代碼到DLL的實(shí)現(xiàn)
使用Unity API PlayerBuildInterface.CompilePlayerScripts 將項(xiàng)目中的代碼生成為 DLL 程序集
在 Editor 文件夾下新建腳本 CompileDll
using UnityEngine; using UnityEditor; using UnityEditor.Build.Player; using System.IO; public class CompileDll { // 菜單欄添加按鈕 [MenuItem("Tools/CompileDll")] static void Compile() { // 設(shè)置需要打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); } } }
點(diǎn)擊 Tools->CompileDll 按鈕,在 代碼中 outDir 目錄下生成所有 dll 以及 對應(yīng)的 .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 程序集
具體細(xì)節(jié)可以學(xué)習(xí)了解 Unity asmdef 文件的創(chuàng)建以及作用
在項(xiàng)目中任意選一個 C# 腳本,都可以在 Inspector 面板看到它歸屬的 dll 程序集
這就是上面執(zhí)行編譯導(dǎo)出的 dll 的來源
到此這篇關(guān)于Unity打包代碼到DLL的實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)Unity打包代碼到DLL內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
10分鐘學(xué)會Visual Studio將自己創(chuàng)建的類庫打包到NuGet進(jìn)行引用(net,net core,C#)
這篇文章主要介紹了10分鐘學(xué)會Visual Studio將自己創(chuàng)建的類庫打包到NuGet進(jìn)行引用(net,net core,C#),本文給大家介紹的非常詳細(xì)對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-09-09winform C#獲得Mac地址,IP地址,子網(wǎng)掩碼,默認(rèn)網(wǎng)關(guān)的實(shí)例
下面小編就為大家?guī)硪黄獁inform C#獲得Mac地址,IP地址,子網(wǎng)掩碼,默認(rèn)網(wǎng)關(guān)的實(shí)例。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-01-01C#中List集合使用Max()方法查找到最大值的實(shí)例
這篇文章主要介紹了C#中List集合使用Max()方法查找到最大值的實(shí)例,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-12-12C#連接Oracle數(shù)據(jù)庫的實(shí)例方法
C#連接Oracle數(shù)據(jù)庫的實(shí)例方法,需要的朋友可以參考一下2013-04-04