diff --git a/scripts/check_unity_build.ps1 b/scripts/check_unity_build.ps1 index 1696378..7175440 100644 --- a/scripts/check_unity_build.ps1 +++ b/scripts/check_unity_build.ps1 @@ -1,32 +1,31 @@ -# Unity 脚本编译检查 -# 用法:在修改 src/CounterDrone.Core/ 或 src/Unity/Assets/Scripts/ 后运行 -# 退出码 0 = 成功,非 0 = 有错误 +# 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" -$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" +Remove-Item "$unityProject\Library\ScriptAssemblies" -Recurse -Force -ErrorAction SilentlyContinue -# 3. 编译 Unity 脚本 -Write-Host "Compiling Unity scripts..." -& $unityEditor -batchmode -quit -projectPath $unityProject -logFile $logFile 2>&1 | Out-Null +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 } -$errors = Select-String -Path $logFile -Pattern "error CS" -SimpleMatch -if ($errors) { - Write-Host "UNITY BUILD FAILED:" - $errors | ForEach-Object { Write-Host $_.Line } - 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" +Write-Host "ALL CHECKS PASSED (verify in Unity Editor for final confirmation)" exit 0 diff --git a/src/Unity/Assets/Plugins/CounterDrone.Core/CounterDrone.Core.dll b/src/Unity/Assets/Plugins/CounterDrone.Core/CounterDrone.Core.dll index 6e73dc6..d6dac38 100644 Binary files a/src/Unity/Assets/Plugins/CounterDrone.Core/CounterDrone.Core.dll and b/src/Unity/Assets/Plugins/CounterDrone.Core/CounterDrone.Core.dll differ