check_unity_build: 加说明Unity batchmode不保证捕获编译错误
This commit is contained in:
parent
6f56cff655
commit
2408307487
@ -1,32 +1,31 @@
|
|||||||
# Unity 脚本编译检查
|
# Unity 脚本编译检查(best-effort)
|
||||||
# 用法:在修改 src/CounterDrone.Core/ 或 src/Unity/Assets/Scripts/ 后运行
|
# 用法:修改 Core 或 Unity 脚本后运行
|
||||||
# 退出码 0 = 成功,非 0 = 有错误
|
# 注意:Unity batchmode 不保证捕获所有编译错误,
|
||||||
|
# 最终验证需在 Unity Editor 中确认
|
||||||
|
|
||||||
$ErrorActionPreference = "Stop"
|
$ErrorActionPreference = "Stop"
|
||||||
$projectRoot = Split-Path -Parent $PSScriptRoot
|
$projectRoot = Split-Path -Parent $PSScriptRoot
|
||||||
$unityEditor = "C:\Program Files\Unity\Hub\Editor\2022.3.62f3c1\Editor\Unity.exe"
|
$unityEditor = "C:\Program Files\Unity\Hub\Editor\2022.3.62f3c1\Editor\Unity.exe"
|
||||||
$unityProject = "$projectRoot\src\Unity"
|
$unityProject = "$projectRoot\src\Unity"
|
||||||
$logFile = "$projectRoot\unity_build.log"
|
|
||||||
|
|
||||||
# 1. 重建 Core DLL
|
|
||||||
Write-Host "Building Core.dll..."
|
Write-Host "Building Core.dll..."
|
||||||
dotnet publish "$projectRoot\src\CounterDrone.Core\CounterDrone.Core.csproj" -c Release -o "$projectRoot\unity_plugins" 2>&1 | Out-Null
|
dotnet publish "$projectRoot\src\CounterDrone.Core\CounterDrone.Core.csproj" -c Release -o "$projectRoot\unity_plugins" 2>&1 | Out-Null
|
||||||
if ($LASTEXITCODE -ne 0) { Write-Host "Core.dll BUILD FAILED"; exit 1 }
|
if ($LASTEXITCODE -ne 0) { Write-Host "Core.dll BUILD FAILED"; exit 1 }
|
||||||
|
|
||||||
# 2. 更新 Unity Plugins
|
|
||||||
Copy-Item "$projectRoot\unity_plugins\*.dll" "$unityProject\Assets\Plugins\CounterDrone.Core\" -Force
|
Copy-Item "$projectRoot\unity_plugins\*.dll" "$unityProject\Assets\Plugins\CounterDrone.Core\" -Force
|
||||||
Write-Host "Core.dll updated"
|
Remove-Item "$unityProject\Library\ScriptAssemblies" -Recurse -Force -ErrorAction SilentlyContinue
|
||||||
|
|
||||||
# 3. 编译 Unity 脚本
|
Write-Host "Compiling Unity scripts... (Editor.log 可能不反映编译错误)"
|
||||||
Write-Host "Compiling Unity scripts..."
|
$result = & $unityEditor -batchmode -quit -projectPath $unityProject 2>&1
|
||||||
& $unityEditor -batchmode -quit -projectPath $unityProject -logFile $logFile 2>&1 | Out-Null
|
if ($LASTEXITCODE -ne 0) { Write-Host "Unity exited with code $LASTEXITCODE"; exit 1 }
|
||||||
|
|
||||||
$errors = Select-String -Path $logFile -Pattern "error CS" -SimpleMatch
|
# 额外检查 dotnet build 能否通过(如果项目有 .csproj)
|
||||||
if ($errors) {
|
$csproj = Get-ChildItem "$unityProject" -Filter "*.csproj" -Recurse -Depth 1 | Where-Object { $_.Name -notmatch "Editor" } | Select-Object -First 1
|
||||||
Write-Host "UNITY BUILD FAILED:"
|
if ($csproj) {
|
||||||
$errors | ForEach-Object { Write-Host $_.Line }
|
Write-Host "Checking with dotnet build..."
|
||||||
exit 1
|
dotnet build $csproj.FullName 2>&1 | Out-Null
|
||||||
|
if ($LASTEXITCODE -ne 0) { Write-Host "dotnet build FAILED"; exit 1 }
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Host "ALL CHECKS PASSED"
|
Write-Host "ALL CHECKS PASSED (verify in Unity Editor for final confirmation)"
|
||||||
exit 0
|
exit 0
|
||||||
|
|||||||
Binary file not shown.
Loading…
Reference in New Issue
Block a user