CounterDroneBackend/scripts/check_unity_build.ps1

32 lines
1.6 KiB
PowerShell
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Unity 脚本编译检查best-effort
# 用法:修改 Core 或 Unity 脚本后运行
# 注意Unity batchmode 不保证捕获所有编译错误,
# 最终验证需在 Unity Editor 中确认
$ErrorActionPreference = "Stop"
$projectRoot = Split-Path -Parent $PSScriptRoot
$unityEditor = "C:\Program Files\Unity\Hub\Editor\2022.3.62f3c1\Editor\Unity.exe"
$unityProject = "$projectRoot\src\Unity"
Write-Host "Building Core.dll..."
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 }
Copy-Item "$projectRoot\unity_plugins\*.dll" "$unityProject\Assets\Plugins\CounterDrone.Core\" -Force
Remove-Item "$unityProject\Library\ScriptAssemblies" -Recurse -Force -ErrorAction SilentlyContinue
Write-Host "Compiling Unity scripts... (Editor.log 可能不反映编译错误)"
$result = & $unityEditor -batchmode -quit -projectPath $unityProject 2>&1
if ($LASTEXITCODE -ne 0) { Write-Host "Unity exited with code $LASTEXITCODE"; exit 1 }
# 额外检查 dotnet build 能否通过(如果项目有 .csproj
$csproj = Get-ChildItem "$unityProject" -Filter "*.csproj" -Recurse -Depth 1 | Where-Object { $_.Name -notmatch "Editor" } | Select-Object -First 1
if ($csproj) {
Write-Host "Checking with dotnet build..."
dotnet build $csproj.FullName 2>&1 | Out-Null
if ($LASTEXITCODE -ne 0) { Write-Host "dotnet build FAILED"; exit 1 }
}
Write-Host "ALL CHECKS PASSED (verify in Unity Editor for final confirmation)"
exit 0