# Unity 脚本编译检查 # 用法:在修改 src/CounterDrone.Core/ 或 src/Unity/Assets/Scripts/ 后运行 # 退出码 0 = 成功,非 0 = 有错误 $ErrorActionPreference = "Stop" $projectRoot = Split-Path -Parent $PSScriptRoot $unityEditor = "C:\Program Files\Unity\Hub\Editor\2022.3.62f3c1\Editor\Unity.exe" $unityProject = "$projectRoot\src\Unity" $logFile = "$projectRoot\unity_build.log" # 1. 重建 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 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 Write-Host "Core.dll updated" # 3. 编译 Unity 脚本 Write-Host "Compiling Unity scripts..." & $unityEditor -batchmode -quit -projectPath $unityProject -logFile $logFile 2>&1 | Out-Null $errors = Select-String -Path $logFile -Pattern "error CS" -SimpleMatch if ($errors) { Write-Host "UNITY BUILD FAILED:" $errors | ForEach-Object { Write-Host $_.Line } exit 1 } Write-Host "ALL CHECKS PASSED" exit 0