# Create New Unity Project for ROS2 Integration # 为ROS2集成创建新的Unity项目 param( [string]$ProjectName = "ROS2_Niryo_Control", [string]$ProjectPath = "D:\ros2\DockerRos2Arm-niryo_arm\Unity_MoveIt2\NewUnityProject", [string]$UnityPath = "C:\Program Files\Unity\Hub\Editor\2021.3.33f1c1\Editor\Unity.exe", [switch]$CreateOnly, [switch]$OpenAfterCreate ) Write-Host "=== Creating New Unity Project for ROS2 Integration ===" -ForegroundColor Green # Check if Unity exists if (-not (Test-Path $UnityPath)) { Write-Host "Error: Unity not found at $UnityPath" -ForegroundColor Red exit 1 } # Create project directory $FullProjectPath = Join-Path $ProjectPath $ProjectName Write-Host "Creating project directory: $FullProjectPath" -ForegroundColor Yellow if (Test-Path $FullProjectPath) { Write-Host "Warning: Project directory already exists. Removing..." -ForegroundColor Yellow Remove-Item $FullProjectPath -Recurse -Force } New-Item -ItemType Directory -Path $FullProjectPath -Force | Out-Null # Create Unity project using command line Write-Host "Creating Unity project..." -ForegroundColor Yellow $createArgs = @( "-createProject", $FullProjectPath, "-batchmode", "-quit" ) $process = Start-Process -FilePath $UnityPath -ArgumentList $createArgs -Wait -PassThru -NoNewWindow if ($process.ExitCode -eq 0) { Write-Host "Unity project created successfully!" -ForegroundColor Green } else { Write-Host "Error creating Unity project. Exit code: $($process.ExitCode)" -ForegroundColor Red exit 1 } # Create basic project structure Write-Host "Setting up project structure..." -ForegroundColor Yellow $directories = @( "Assets/Scripts/ROS", "Assets/Scripts/Robot", "Assets/Scripts/UI", "Assets/Prefabs/Robot", "Assets/Materials", "Assets/Scenes", "Assets/Resources", "Assets/URDF" ) foreach ($dir in $directories) { $fullPath = Join-Path $FullProjectPath $dir New-Item -ItemType Directory -Path $fullPath -Force | Out-Null } # Create manifest.json for ROS packages $manifestPath = Join-Path $FullProjectPath "Packages\manifest.json" $manifestContent = @" { "dependencies": { "com.unity.collab-proxy": "2.0.5", "com.unity.feature.development": "1.0.1", "com.unity.textmeshpro": "3.0.6", "com.unity.timeline": "1.7.5", "com.unity.ugui": "1.0.0", "com.unity.visualscripting": "1.8.0", "com.unity.modules.ai": "1.0.0", "com.unity.modules.androidjni": "1.0.0", "com.unity.modules.animation": "1.0.0", "com.unity.modules.assetbundle": "1.0.0", "com.unity.modules.audio": "1.0.0", "com.unity.modules.cloth": "1.0.0", "com.unity.modules.director": "1.0.0", "com.unity.modules.imageconversion": "1.0.0", "com.unity.modules.imgui": "1.0.0", "com.unity.modules.jsonserialize": "1.0.0", "com.unity.modules.particlesystem": "1.0.0", "com.unity.modules.physics": "1.0.0", "com.unity.modules.physics2d": "1.0.0", "com.unity.modules.screencapture": "1.0.0", "com.unity.modules.terrain": "1.0.0", "com.unity.modules.terrainphysics": "1.0.0", "com.unity.modules.tilemap": "1.0.0", "com.unity.modules.ui": "1.0.0", "com.unity.modules.uielements": "1.0.0", "com.unity.modules.umbra": "1.0.0", "com.unity.modules.unityanalytics": "1.0.0", "com.unity.modules.unitywebrequest": "1.0.0", "com.unity.modules.unitywebrequestassetbundle": "1.0.0", "com.unity.modules.unitywebrequestexture": "1.0.0", "com.unity.modules.unitywebrequesttexture": "1.0.0", "com.unity.modules.unitywebrequestwww": "1.0.0", "com.unity.modules.vehicles": "1.0.0", "com.unity.modules.video": "1.0.0", "com.unity.modules.vr": "1.0.0", "com.unity.modules.wind": "1.0.0", "com.unity.modules.xr": "1.0.0" }, "scopedRegistries": [ { "name": "Unity Robotics", "url": "https://packages.unity.com", "scopes": [ "com.unity.robotics" ] } ] } "@ Write-Output $manifestContent | Out-File -FilePath $manifestPath -Encoding UTF8 # Create README for the new project $readmePath = Join-Path $FullProjectPath "README.md" $readmeContent = @" # ROS2 Niryo Robot Control Unity Project This Unity project is designed for controlling Niryo robots through ROS2 integration. ## Project Structure - **Assets/Scripts/ROS**: ROS2 communication scripts - **Assets/Scripts/Robot**: Robot control and movement scripts - **Assets/Scripts/UI**: User interface scripts - **Assets/Prefabs/Robot**: Robot prefabs and components - **Assets/URDF**: Robot URDF files and models - **Assets/Scenes**: Unity scenes for robot simulation ## Required Packages This project requires the following Unity packages: - ROS TCP Connector (com.unity.robotics.ros-tcp-connector) - URDF Importer (com.unity.robotics.urdf-importer) ## Setup Instructions 1. Open the project in Unity 2021.3.33f1c1 2. Install required ROS packages via Package Manager 3. Configure ROS TCP Endpoint connection 4. Import Niryo robot URDF files 5. Test connection with ROS2 Docker container ## Docker Integration This project integrates with a ROS2 Docker container that provides: - ROS2 Jazzy environment - MoveIt2 motion planning - Niryo robot packages - ROS TCP Endpoint server ## Getting Started 1. Ensure Docker container is running 2. Open Unity project 3. Load the main scene 4. Test robot connection and control "@ Write-Output $readmeContent | Out-File -FilePath $readmePath -Encoding UTF8 Write-Host "Project structure created successfully!" -ForegroundColor Green Write-Host "Project location: $FullProjectPath" -ForegroundColor Cyan Write-Host "" Write-Host "Next steps:" -ForegroundColor Yellow Write-Host "1. Install ROS TCP Connector package" -ForegroundColor White Write-Host "2. Install URDF Importer package" -ForegroundColor White Write-Host "3. Import robot assets and scripts" -ForegroundColor White Write-Host "4. Configure ROS2 connection settings" -ForegroundColor White if ($OpenAfterCreate) { Write-Host "" Write-Host "Opening Unity project..." -ForegroundColor Yellow Start-Process -FilePath $UnityPath -ArgumentList "-projectPath", $FullProjectPath } Write-Host "" Write-Host "Unity project creation completed!" -ForegroundColor Green