Files
001code-html--cocos/scratch-gui/static/unity/import-to-unity.sh
刘宇飞 6e0a1fbcbb Initial commit of 001code-html Scratch frontend project.
Includes scratch-gui, scratch-vm, scratch-blocks, scratch-render, scratch-l10n, and deployment config.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-16 15:37:45 +08:00

66 lines
1.7 KiB
Bash
Executable File

#!/usr/bin/env bash
# 将 Cocos 运行时包 build/mstest5/ 同步到 scratch-gui/static/unity/
# 用法: ./import-to-unity.sh [mstest5目录]
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
TARGET_DIR="$SCRIPT_DIR"
SRC_DIR="${1:-$HOME/tfrh/cocos/tfrh001/build/mstest5}"
if [[ ! -f "$SRC_DIR/Build/mstest5.loader.js" ]]; then
echo "错误: 找不到 Cocos 运行时包: $SRC_DIR/Build/mstest5.loader.js" >&2
echo "请先执行: cd ~/tfrh/cocos/tfrh001 && bash tools/package-for-project.sh" >&2
exit 1
fi
echo "==> 源: $SRC_DIR"
echo "==> 目标: $TARGET_DIR"
sync_dir() {
local rel="$1"
local src="$SRC_DIR/$rel"
local dst="$TARGET_DIR/$rel"
if [[ ! -e "$src" ]]; then
echo "警告: 跳过缺失项 $rel" >&2
return 0
fi
mkdir -p "$(dirname "$dst")"
if command -v rsync >/dev/null 2>&1; then
rsync -a --delete "$src/" "$dst/"
else
rm -rf "$dst"
cp -R "$src" "$dst"
fi
echo " 已同步 $rel/"
}
sync_file() {
local rel="$1"
local src="$SRC_DIR/$rel"
local dst="$TARGET_DIR/$rel"
if [[ ! -f "$src" ]]; then
echo "警告: 跳过缺失文件 $rel" >&2
return 0
fi
mkdir -p "$(dirname "$dst")"
cp -f "$src" "$dst"
echo " 已同步 $rel"
}
sync_dir "Build"
sync_dir "StreamingAssets"
sync_file "levels-database.json"
[[ -f "$SRC_DIR/levels-database.json.br" ]] && sync_file "levels-database.json.br"
# 校验关键文件
for f in Build/mstest5.loader.js StreamingAssets/aa/catalog.json levels-database.json; do
if [[ ! -f "$TARGET_DIR/$f" ]]; then
echo "错误: 导入后缺少 $f" >&2
exit 1
fi
done
echo ""
echo "==> 导入完成。请重启 scratch-gui 开发服务器或重新 npm run build。"
echo " 本地路径: /unity/Build/mstest5.loader.js"