# Unity Environment Check Script # 简化版Unity环境检查脚本 param( [switch]$OpenProject, [string]$UnityPath = "C:\Program Files\Unity\Hub\Editor\2021.3.33f1c1\Editor\Unity.exe" ) $ProjectRoot = Split-Path -Parent $PSScriptRoot $PickAndPlaceProject = Join-Path (Split-Path -Parent $ProjectRoot) "PickAndPlaceProject" Write-Host "=== Unity Environment Check ===" -ForegroundColor Green Write-Host "Unity Path: $UnityPath" -ForegroundColor Cyan Write-Host "Project Path: $PickAndPlaceProject" -ForegroundColor Cyan # 检查Unity安装 Write-Host "`nChecking Unity installation..." -ForegroundColor Yellow if (Test-Path $UnityPath) { Write-Host "✓ Unity 2021.3.33f1c1 found" -ForegroundColor Green } else { Write-Host "✗ Unity not found at specified path" -ForegroundColor Red exit 1 } # 检查项目存在 Write-Host "`nChecking project..." -ForegroundColor Yellow if (Test-Path $PickAndPlaceProject) { Write-Host "✓ PickAndPlace project found" -ForegroundColor Green } else { Write-Host "✗ Project directory not found" -ForegroundColor Red exit 1 } # 检查项目版本 $versionFile = Join-Path $PickAndPlaceProject "ProjectSettings\ProjectVersion.txt" if (Test-Path $versionFile) { $content = Get-Content $versionFile $version = ($content | Where-Object { $_ -match "m_EditorVersion:" }) -replace "m_EditorVersion: ", "" Write-Host "Current project version: $version" -ForegroundColor Gray if ($version -like "2022.*") { Write-Host "⚠ Project created with Unity 2022.x, may need version adjustment" -ForegroundColor Yellow } } # 检查ROS包 $manifestFile = Join-Path $PickAndPlaceProject "Packages\manifest.json" if (Test-Path $manifestFile) { Write-Host "`nChecking ROS packages..." -ForegroundColor Yellow $manifest = Get-Content $manifestFile -Raw | ConvertFrom-Json if ($manifest.dependencies."com.unity.robotics.ros-tcp-connector") { Write-Host "✓ ROS TCP Connector found" -ForegroundColor Green } else { Write-Host "✗ ROS TCP Connector missing" -ForegroundColor Red } if ($manifest.dependencies."com.unity.robotics.urdf-importer") { Write-Host "✓ URDF Importer found" -ForegroundColor Green } else { Write-Host "✗ URDF Importer missing" -ForegroundColor Red } } # 测试网络连接 Write-Host "`nTesting ROS connection..." -ForegroundColor Yellow try { $connection = Test-NetConnection -ComputerName "localhost" -Port 10000 -WarningAction SilentlyContinue if ($connection.TcpTestSucceeded) { Write-Host "✓ ROS TCP Endpoint accessible on port 10000" -ForegroundColor Green } else { Write-Host "⚠ ROS TCP Endpoint not accessible (Docker may not be running)" -ForegroundColor Yellow } } catch { Write-Host "⚠ Could not test network connectivity" -ForegroundColor Yellow } # 打开项目选项 if ($OpenProject) { Write-Host "`nOpening Unity project..." -ForegroundColor Yellow # 更新项目版本到2021.3 $newContent = @( "m_EditorVersion: 2021.3.33f1c1" "m_EditorVersionWithRevision: 2021.3.33f1c1 (b9a993fd2ece)" ) Set-Content -Path $versionFile -Value $newContent -Encoding UTF8 Write-Host "✓ Project version updated to 2021.3.33f1c1" -ForegroundColor Green # 启动Unity Start-Process -FilePath $UnityPath -ArgumentList "-projectPath `"$PickAndPlaceProject`"" Write-Host "✓ Unity starting..." -ForegroundColor Green Write-Host "Please wait for Unity to load and resolve packages" -ForegroundColor Gray } Write-Host "`n=== Summary ===" -ForegroundColor Cyan Write-Host "Unity 2021.3.33f1c1: Available" -ForegroundColor Green Write-Host "PickAndPlace Project: Ready" -ForegroundColor Green Write-Host "ROS Packages: Installed" -ForegroundColor Green Write-Host "" Write-Host "Next steps:" -ForegroundColor Yellow Write-Host "1. Run: .\unity-check.ps1 -OpenProject # Open Unity project" Write-Host "2. Wait for Docker ROS2 container to finish building" Write-Host "3. Test Unity-ROS2 connection"