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); }
public static bool Build(string outputPath, string[] scripts, Action <string> onOutputReceived, Action <string> onErrorReceived) { var result = true; AssetUtil.DeleteFile(outputPath); AssetUtil.CleanupDirectory(Path.GetDirectoryName(outputPath)); using (var process = Process.Start(new ProcessStartInfo() { #if UNITY_EDITOR_WIN FileName = EditorUtil.Preference.MonoDirectory + "/bin/smcs.bat", #elif UNITY_EDITOR_OSX FileName = EditorUtil.Preference.MonoDirectory + "/bin/smcs", #endif Arguments = string.Join( " ", new[] { string.Format("-r:\"{0}\"", AssetUtil.CombinePath(ProjectInfo.UnityAssemblyRoot, "UnityEngine.dll")), string.Format("-r:\"{0}\"", AssetUtil.CombinePath(ProjectInfo.UnityAssemblyRoot, "UnityEditor.dll")), "-target:library", "-warnaserror+", string.Format("-out:\"{0}\"", outputPath), string.Join(" ", scripts.Select(x => string.Format("\"{0}\"", x)).ToArray()), }), CreateNoWindow = true, UseShellExecute = false, RedirectStandardOutput = true, RedirectStandardError = true, })) { if (onOutputReceived != null) { process.OutputDataReceived += (_, e) => onOutputReceived(e.Data); } if (onErrorReceived != null) { process.ErrorDataReceived += (_, e) => { result = false; onErrorReceived(e.Data); }; } process.WaitForExit(); } return(result && File.Exists(outputPath)); }
public static void ExportPackage() { var paths = Selection.objects.Select(obj => AssetDatabase.GetAssetPath(obj)) .ToArray(); var exportPath = AssetUtil.CombinePath( Preference.ExportDirectory, Preference.GetAssemblyName(paths) + ".unitypackage"); AssetUtil.DeleteFile(exportPath); if (!Directory.Exists(Path.GetDirectoryName(exportPath))) { Directory.CreateDirectory(Path.GetDirectoryName(exportPath)); } AssetDatabase.ExportPackage( paths, exportPath, ExportPackageOptions.Recurse | ExportPackageOptions.IncludeDependencies); }