コードを DLL にしたい場合は、まずアセンブリと適切なコード ディレクトリ構造計画を立てる必要があります。
1. グループ化するスクリプトを同じファイルに配置し、フォルダーを右クリックしてアセンブリ定義を作成します。デフォルトでは、同じフォルダーおよびサブディレクトリ内のスクリプトが 1 つのアセンブリにグループ化されます。
2. エディターで CompileDll スクリプトを作成し、ワンクリックでスクリプトを DLL にパッケージ化します。
using UnityEditor;
using System.IO;
using UnityEngine;
using UnityEditor.Build.Player;
public class CompileDLLHelper
{
[MenuItem("HTools/CompileDlls")]
public static void CompileDll()
{
var tempOutputPath = $"{
Application.dataPath}/../Dlls";
Directory.CreateDirectory(tempOutputPath);
ScriptCompilationSettings scriptCompilationSettings = new ScriptCompilationSettings();
scriptCompilationSettings.group = BuildPipeline.GetBuildTargetGroup(BuildTarget.StandaloneWindows64);
scriptCompilationSettings.target = BuildTarget.StandaloneWindows64;
PlayerBuildInterface.CompilePlayerScripts(scriptCompilationSettings, tempOutputPath);
}
}
3. 編集ウィンドウで「HTools」->「CompileDlls」をクリックします。
最後に、現在のプロジェクト ディレクトリの Dlls (Assets フォルダーと同じディレクトリ) フォルダーにパッケージ化したすべての DLL が表示されます。
ヒント (PDB ファイルとは、パッケージ化時に取り出される「プログラム データベース」ファイルを指します)