ソースコード
using System.IO;
using System.Linq;
using UnityEditor;
using UnityEditor.Compilation;
using UnityEngine;
public static class AssembyBuilderExample
{
[MenuItem( "AssemblyBuilder Example/Build Assembly Async" )]
public static void BuildAssemblyAsync()
{
var scripts = new[] { "Test/MyScript1.cs", "Test/MyScript2.cs" };
var outputAssembly = "Test/MyAssembly.dll";
var assemblyProjectPath = "Assets/MyAssembly.dll";
var assemblyBuilder = new AssemblyBuilder( outputAssembly, scripts )
{
excludeReferences = new[] { assemblyProjectPath }
};
assemblyBuilder.buildStarted += assemblyPath => Debug.LogFormat( "Assembly build started for {0}", assemblyPath );
assemblyBuilder.buildFinished += ( assemblyPath, compilerMessages ) =>
{
var errorCount = compilerMessages.Count( x => x.type == CompilerMessageType.Error );
var warningCount = compilerMessages.Count( x => x.type == CompilerMessageType.Warning );
Debug.LogFormat( "Assembly build finished for {0}", assemblyPath );
Debug.LogFormat( "Warnings: {1} - Errors: {0}", errorCount, warningCount );
if ( errorCount != 0 ) return;
File.Copy( outputAssembly, assemblyProjectPath, true );
AssetDatabase.ImportAsset( assemblyProjectPath );
};
if ( assemblyBuilder.Build() ) return;
Debug.LogErrorFormat( "Failed to start build of assembly {0}!", assemblyBuilder.assemblyPath );
}
}
参考サイト様