File size: 2,212 Bytes
40c0886 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | """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
# Make the package importable when run directly.
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")
# Clear the destination so we always start fresh.
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)
# Add the CameraController alias the user spec asks for.
cam_result = WriteCSharpScriptTool(settings, transport).run(
filename="CameraController.cs", code=CAMERA_CONTROLLER_CS,
project_name="open_world_city",
)
print(cam_result.summary)
# QA the result.
report = ProjectQA(examples_dir / "open_world_city").run()
print(report.summary())
return 0 if report.passed else 1
if __name__ == "__main__":
sys.exit(main())
|