feat(tools): 添加UE5编辑器内白模构建启动脚本
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
"""UE5 编辑器内白模关卡构建启动脚本。
|
||||
|
||||
使用方式:
|
||||
1. 打开 UE5 编辑器
|
||||
2. Window → Developer Tools → Output Log
|
||||
3. 左下角下拉菜单切换到 "Python"
|
||||
4. 粘贴执行:
|
||||
exec(open(r"<项目绝对路径>/tools/level-builder/build_in_editor.py").read())
|
||||
|
||||
或者:
|
||||
File → Execute Python Script → 选择此文件
|
||||
"""
|
||||
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
# ---- 配置 ----
|
||||
PROJECT_ROOT = Path(r"E:/MiceCola/work/ChildHood")
|
||||
LEVEL_JSON = PROJECT_ROOT / "tools/level-builder/output/level_v01.json"
|
||||
# ---- 配置结束 ----
|
||||
|
||||
# 将项目路径加入 sys.path
|
||||
TOOLS_DIR = PROJECT_ROOT / "tools"
|
||||
LEVEL_BUILDER_DIR = PROJECT_ROOT / "tools/level-builder"
|
||||
for p in [str(PROJECT_ROOT), str(TOOLS_DIR), str(LEVEL_BUILDER_DIR)]:
|
||||
if p not in sys.path:
|
||||
sys.path.insert(0, p)
|
||||
|
||||
# 检查 unreal 模块
|
||||
try:
|
||||
import unreal
|
||||
except ImportError:
|
||||
print("[错误] 未检测到 unreal 模块,此脚本必须在 UE5 编辑器 Python 环境中运行!")
|
||||
print(" 请在 Output Log 中切换到 Python 控制台后执行。")
|
||||
raise
|
||||
|
||||
# 检查 JSON 文件存在
|
||||
if not LEVEL_JSON.exists():
|
||||
print(f"[错误] JSON 文件不存在: {LEVEL_JSON}")
|
||||
print(" 请先在命令行运行: python main.py parse -i ../../docs/technical/关卡-v01-搭建指南.md")
|
||||
raise FileNotFoundError(str(LEVEL_JSON))
|
||||
|
||||
# 导入并执行构建
|
||||
from builder.scene_builder import build_level
|
||||
|
||||
print(f"[LevelBuilder] 项目根目录: {PROJECT_ROOT}")
|
||||
print(f"[LevelBuilder] JSON 数据: {LEVEL_JSON}")
|
||||
print(f"[LevelBuilder] 开始构建...")
|
||||
|
||||
build_log = build_level(
|
||||
json_path=str(LEVEL_JSON),
|
||||
clear_existing=True,
|
||||
zones=None, # 构建所有区域;如仅需部分区域改为 ["Z1", "Z3"]
|
||||
)
|
||||
|
||||
if build_log:
|
||||
ok = sum(1 for b in build_log if b.get("status") == "ok")
|
||||
failed = sum(1 for b in build_log if b.get("status") != "ok")
|
||||
print(f"\n[LevelBuilder] ========== 构建结果 ==========")
|
||||
print(f" 成功: {ok}")
|
||||
print(f" 失败: {failed}")
|
||||
print(f" 总计: {len(build_log)}")
|
||||
if failed > 0:
|
||||
print(f"\n 失败列表:")
|
||||
for b in build_log:
|
||||
if b.get("status") != "ok":
|
||||
print(f" ❌ {b.get('name', '?')}: {b.get('reason', '未知错误')}")
|
||||
Reference in New Issue
Block a user