| """Regenerate the open_world_city example using the unity_agent package. |
| |
| Usage:: |
| |
| python examples/generate_example.py |
| |
| This re-creates ``examples/open_world_city/`` from scratch using the same |
| tool chain the orchestrator would use. |
| """ |
|
|
| from __future__ import annotations |
|
|
| import sys |
| from pathlib import Path |
|
|
| |
| ROOT = Path(__file__).resolve().parent.parent |
| sys.path.insert(0, str(ROOT)) |
|
|
| from unity_agent.config import Settings |
| from unity_agent.transport.unity_transport import UnityTransport |
| from unity_agent.tools.unity_tools import ( |
| GenerateCompleteGameTool, |
| WriteCSharpScriptTool, |
| ) |
| from unity_agent.qa import ProjectQA |
|
|
|
|
| CAMERA_CONTROLLER_CS = """\ |
| using UnityEngine; |
| |
| namespace UnityAgent |
| { |
| /// <summary> |
| /// Convenience alias for <see cref="ThirdPersonCamera"/>. Lets designers |
| /// attach a component named CameraController if they prefer that name. |
| /// </summary> |
| public class CameraController : ThirdPersonCamera |
| { |
| // All behaviour is inherited from ThirdPersonCamera. |
| } |
| } |
| """ |
|
|
|
|
| def main() -> int: |
| examples_dir = ROOT / "examples" |
| settings = Settings(output_dir=str(examples_dir), product_name="open_world_city") |
| transport = UnityTransport(settings) |
| transport.open_project("open_world_city") |
|
|
| |
| import shutil |
| if (examples_dir / "open_world_city").exists(): |
| shutil.rmtree(examples_dir / "open_world_city") |
| transport.open_project("open_world_city") |
|
|
| result = GenerateCompleteGameTool(settings, transport).run( |
| game_name="open_world_city", preset="open_world_city", |
| project_name="open_world_city", |
| ) |
| print(result.summary) |
|
|
| |
| cam_result = WriteCSharpScriptTool(settings, transport).run( |
| filename="CameraController.cs", code=CAMERA_CONTROLLER_CS, |
| project_name="open_world_city", |
| ) |
| print(cam_result.summary) |
|
|
| |
| report = ProjectQA(examples_dir / "open_world_city").run() |
| print(report.summary()) |
| return 0 if report.passed else 1 |
|
|
|
|
| if __name__ == "__main__": |
| sys.exit(main()) |
|
|