Example #1
0
        public string BuildScripts(string[] scripts, string assemblyName)
        {
            if (scripts.Length == 0)
            {
                return(null);
            }

            // スクリプトのパスをいちいち指定してたらコマンドラインが文字数オーバーするかもしれないから
            // 一旦テンポラリに全部コピーして *.cs で指定できるようにする。
            var tmpScriptsDir = AssetUtil.CombinePath(Application.temporaryCachePath, assemblyName);

            AssetUtil.CleanupDirectory(tmpScriptsDir);

            foreach (var script in scripts)
            {
                var source = AssetUtil.CombinePath(ProjectInfo.RootPath, script);
                var dest   = AssetUtil.CombinePath(tmpScriptsDir, Path.GetFileName(script));
                AssetUtil.CopyFile(source, dest, true);
            }

            // 既にビルド済みアセンブリがいたら消す
            var outputPath = AssetUtil.CombinePath(_settings.AssemblyRoot, assemblyName, assemblyName + ".dll");

            AssetUtil.CleanupAssetDirectory(Path.GetDirectoryName(outputPath));

            var outputAssemblyPath = AssetUtil.CombinePath(ProjectInfo.RootPath, outputPath);

            // ビルド
            var buildSuccess = ScriptBuilder.Build(
                outputAssemblyPath,
                new[] { tmpScriptsDir + "/*.cs" },
                output => Debug.Log(output),
                error => Debug.LogError(error));

            if (!buildSuccess)
            {
                AssetUtil.DeleteFile(outputAssemblyPath);
                return(null);
            }

            // ビルドしたアセンブリをインポートして、ソースコードを退避
            AssetDatabase.ImportAsset(outputPath);

            var info = new AssemblyInfo(_settings, outputPath, scripts);

            info.SaveToFile();
            info.StashScripts();

            return(outputPath);
        }