diff --git a/Assets/Editor/BuildScript.cs b/Assets/Editor/BuildScript.cs new file mode 100644 index 0000000..dfe37e0 --- /dev/null +++ b/Assets/Editor/BuildScript.cs @@ -0,0 +1,81 @@ +using UnityEditor; +using UnityEngine; +using System; + +public class BuildScript +{ + public static void Build() + { + string[] scenes = EditorBuildSettings.scenes + .FindAll(scene => scene.enabled) + .ConvertAll(scene => scene.path) + .ToArray(); + + string buildPath = GetArg("-buildPath"); + string buildTarget = GetArg("-buildTarget"); + + if (string.IsNullOrEmpty(buildPath)) + { + Debug.LogError("Build path not specified"); + EditorApplication.Exit(1); + return; + } + + BuildTarget target = ParseBuildTarget(buildTarget); + BuildOptions options = BuildOptions.None; + + Debug.Log($"Starting build for {target}"); + Debug.Log($"Build path: {buildPath}"); + Debug.Log($"Scenes: {string.Join(", ", scenes)}"); + + BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions + { + scenes = scenes, + locationPathName = buildPath, + target = target, + options = options + }; + + var report = BuildPipeline.BuildPlayer(buildPlayerOptions); + + if (report.summary.result == UnityEditor.Build.Reporting.BuildResult.Succeeded) + { + Debug.Log($"Build succeeded: {report.summary.totalSize} bytes"); + EditorApplication.Exit(0); + } + else + { + Debug.LogError($"Build failed: {report.summary.result}"); + EditorApplication.Exit(1); + } + } + + private static string GetArg(string name) + { + string[] args = Environment.GetCommandLineArgs(); + for (int i = 0; i < args.Length; i++) + { + if (args[i] == name && i + 1 < args.Length) + { + return args[i + 1]; + } + } + return null; + } + + private static BuildTarget ParseBuildTarget(string target) + { + switch (target) + { + case "StandaloneWindows64": return BuildTarget.StandaloneWindows64; + case "StandaloneOSX": return BuildTarget.StandaloneOSX; + case "StandaloneLinux64": return BuildTarget.StandaloneLinux64; + case "Android": return BuildTarget.Android; + case "iOS": return BuildTarget.iOS; + case "WebGL": return BuildTarget.WebGL; + default: + Debug.LogWarning($"Unknown build target: {target}, using Windows64"); + return BuildTarget.StandaloneWindows64; + } + } +} \ No newline at end of file