#if UNITY_EDITOR using System.IO; using System.Linq; using UnityEditor; namespace UltraCombos { public class Deploy { private const string head = "[Giant Museum]"; [MenuItem(head + "/Build Project")] public static void BuildProject() { Build(new BuildPlayerOptions() { scenes = CollectScenesPath(), locationPathName = PlayerOutputPath, target = EditorUserBuildSettings.activeBuildTarget, options = BuildOptions.None, }); } /* [MenuItem( head + "/Build Development" )] public static void BuildProjectDevelopement() { Build( new BuildPlayerOptions() { scenes = CollectScenesPath(), locationPathName = DevelopmentOutputFolder, target = EditorUserBuildSettings.activeBuildTarget, //options = BuildOptions.Development | BuildOptions.SymlinkLibraries, options = BuildOptions.Development, } ); } */ private static void Build(BuildPlayerOptions options) { BuildPlayer(options); GenerateIgnoreFile(); GenerateAttributeFile(); #if UNITY_STANDALONE_WIN GenerateBatchFile(); #endif } [MenuItem(head + "/Open Output Folder")] public static void OpenFolder() { EditorUtility.RevealInFinder(RootOutputFolder); } private static string[] CollectScenesPath() { return EditorBuildSettings.scenes.Where(s => s.enabled).Select(s => s.path).ToArray(); } private static string CheckFolder(string path) { if (Directory.Exists(path) == false) { Log.Info("Deploy", $"Create directory: {path}"); Directory.CreateDirectory(path); } return path; } private static string RootOutputFolder { get { var path = Core.BuildPath; CheckFolder($"{path}/Material"); return CheckFolder(path); } } private static string PlayerOutputFolder { get { var path = $"{RootOutputFolder}/{Core.OutputFolderName}"; return CheckFolder(path); } } private static string DevelopmentOutputFolder { get { var path = $"{RootOutputFolder}/{Core.OutputFolderName} - Dev"; return CheckFolder(path); } } private static string PlayerOutputPath { get { #if UNITY_STANDALONE_WIN return $"{PlayerOutputFolder}/{PlayerSettings.productName}.exe"; #elif UNITY_ANDROID return $"{PlayerOutputFolder}.apk"; #else return $"{PlayerOutputFolder}"; #endif } } private static void BuildPlayer(BuildPlayerOptions buildPlayerOptions) { var report = BuildPipeline.BuildPlayer(buildPlayerOptions); var summary = report.summary; var totalSizeMB = summary.totalSize / 1024.0 / 1024.0; Log.Info("Deploy", $"Build {summary.result}: {totalSizeMB:N2} MB"); } #if UNITY_EDITOR_WIN private static void GenerateBatchFile() { var path = $"{RootOutputFolder}/startup.bat"; if (File.Exists(path)) { return; } var contents = $@"@ECHO OFF SETLOCAL SET ""BASE_DIR=%~dp0"" ECHO Starting {PlayerSettings.productName}... START """" /D ""%BASE_DIR%{Core.OutputFolderName}"" ""{PlayerSettings.productName}.exe"" TIMEOUT /t 10 ECHO All programs started."; File.WriteAllText(path, contents, System.Text.Encoding.Default); Log.Info("Deploy", $"Generate batch file: {path}"); } #endif private static void GenerateIgnoreFile() { var path = $"{RootOutputFolder}/.gitignore"; if (File.Exists(path)) { return; } var contents = "\n"; File.WriteAllText(path, contents); Log.Info("Deploy", $"Generate ignore file: {path}"); } private static void GenerateAttributeFile() { var filename = ".gitattributes"; var destPath = Path.Combine(RootOutputFolder, filename); if (!File.Exists(filename) || File.Exists(destPath)) { return; } var name = Core.OutputFolderName; var suffix = "filter=lfs diff=lfs merge=lfs"; var baseContent = File.ReadAllText(filename); var newLines = $@" # Build Output Materials/** {name}/** {suffix} "; File.WriteAllText(destPath, baseContent + "\n" + newLines.Trim()); Log.Info("Deploy", $"Generate attribute file: {destPath}"); } } } #endif