Open
Description
Description
Currently, the library supports executing build methods via UnityEditor.executeMethod()
, but lacks a dedicated API for building projects in batch mode with proper progress tracking. Users have to create their own build methods and manually parse the output to understand build progress.
Current Behavior
To build a Unity project, developers must:
- Write a custom build method in C# within their Unity project
- Execute it via
UnityEditor.executeMethod()
- Parse the output manually to track progress
- Handle all build configuration themselves
// Current approach
await UnityEditor.executeMethod(
{ projectPath: "/path/to/project", editorVersion: "2022.3.15f1" },
"MyNamespace.MyBuildScript.PerformBuild",
["arg1", "arg2"]
);
// No structured build progress information returned
Proposed Solution
Add a dedicated buildProject()
method that:
- Accepts structured build configuration parameters
- Streams build output in real-time
- Provides progress tracking and build stage information
- Returns structured build results
// Proposed API
const buildProcess = UnityEditor.buildProject({
projectInfo: {
projectPath: "/path/to/project",
editorVersion: "2022.3.15f1"
},
buildOptions: {
targetPlatform: BuildTargetPlatform.WebGL,
outputPath: "/path/to/build",
development: false,
compression: CompressionMethod.LZ4,
buildOptions: ["CompressWithLz4HC", "StripDebugSymbols"]
}
});
// Event-based progress tracking
buildProcess.on('progress', (data) => {
console.log(`Build progress: ${data.stage}, ${data.percent}%`);
// data.stage could be 'Compilation', 'AssetProcessing', 'SceneBaking', etc.
});
// Or with async iterator
for await (const update of buildProcess.updates()) {
console.log(`Stage: ${update.stage}, Progress: ${update.progress}%`);
}
// Get final result
const result = await buildProcess.complete();
console.log(`Build completed: ${result.success}, output at: ${result.outputPath}`);
Implementation Approach
- Create new data types for build configuration and progress tracking
- Modify the command executor to support streaming via execa's stdout/stderr streams
- Parse Unity Editor build output to extract stage and progress information
- Return a structured object with build results
Benefits
- Improved DX: Developers get real-time feedback during builds
- Structured Configuration: No need to manually create build scripts
- Progress Information: Applications can display accurate progress bars
- CI/CD Integration: Better integration with CI/CD pipelines with rich progress information
Technical Considerations
- The implementation can leverage execa's streaming capabilities
- Unity's build output follows predictable patterns that can be parsed
- Standard build targets and options can be exposed as enums
- Progress parsing would need to support various Unity versions
Related Issue
- This would complement issue Add streaming output for UnityHub.addEditor to provide real-time feedback #13 which focuses on streaming output for Unity Hub operations