Last active
January 24, 2025 08:55
-
-
Save habedi/c6bbe3cd3351c32c592a19314cf34e14 to your computer and use it in GitHub Desktop.
A PowerShell script to create a Unity project struture (execute: `.\CreateUnityProjectStructure.ps1` in PoweShell to run)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This script creates a basic Unity project structure in the current directory. | |
# To run the script, open a PowerShell terminal and execute the following command: | |
# .\CreateUnityProjectStructure.ps1 | |
param( | |
[string]$BaseDir = (Get-Location).Path | |
) | |
# Function to create a directory and handle errors | |
function Create-Dir { | |
param([string]$Path) | |
try { | |
if (-not (Test-Path -Path $Path)) { | |
New-Item -ItemType Directory -Force -Path $Path | Out-Null | |
Write-Host "Created directory: $Path" | |
} else { | |
Write-Host "Directory already exists: $Path" | |
} | |
} catch { | |
Write-Warning "Failed to create directory: $Path. Error: $($_.Exception.Message)" | |
} | |
} | |
# Create the base project structure | |
Write-Host "Creating Unity project structure..." | |
Create-Dir "$BaseDir\Assets" | |
Create-Dir "$BaseDir\Packages" | |
Create-Dir "$BaseDir\ProjectSettings" | |
Create-Dir "$BaseDir\Logs" | |
# Create subdirectories under Assets | |
Write-Host "Creating subdirectories under Assets..." | |
Create-Dir "$BaseDir\Assets\Art" | |
Create-Dir "$BaseDir\Assets\Audio" | |
Create-Dir "$BaseDir\Assets\Prefabs" | |
Create-Dir "$BaseDir\Assets\Scenes" | |
Create-Dir "$BaseDir\Assets\Scripts" | |
Create-Dir "$BaseDir\Assets\UI" | |
Create-Dir "$BaseDir\Assets\Resources" | |
Create-Dir "$BaseDir\Assets\Settings" | |
Create-Dir "$BaseDir\Assets\ThirdParty" | |
# Inside Art | |
Create-Dir "$BaseDir\Assets\Art\Animations" | |
Create-Dir "$BaseDir\Assets\Art\Materials" | |
Create-Dir "$BaseDir\Assets\Art\Models" | |
Create-Dir "$BaseDir\Assets\Art\Textures" | |
Create-Dir "$BaseDir\Assets\Art\VFX" | |
# Inside Audio | |
Create-Dir "$BaseDir\Assets\Audio\Music" | |
Create-Dir "$BaseDir\Assets\Audio\SoundEffects" | |
# Inside Scenes | |
Create-Dir "$BaseDir\Assets\Scenes\MainMenu" | |
Create-Dir "$BaseDir\Assets\Scenes\Levels" | |
Create-Dir "$BaseDir\Assets\Scenes\Sandbox" | |
# Inside Scripts | |
Create-Dir "$BaseDir\Assets\Scripts\Managers" | |
Create-Dir "$BaseDir\Assets\Scripts\Gameplay" | |
Create-Dir "$BaseDir\Assets\Scripts\Utilities" | |
Create-Dir "$BaseDir\Assets\Scripts\Tests" | |
# Inside UI | |
Create-Dir "$BaseDir\Assets\UI\Fonts" | |
Create-Dir "$BaseDir\Assets\UI\Images" | |
# Inside Settings | |
Create-Dir "$BaseDir\Assets\Settings\Input" | |
# Create structure explanation file | |
$TreeStructure = "$BaseDir\structure.txt" | |
Write-Host "Writing structure explanation to $TreeStructure..." | |
@" | |
Unity Project Structure | |
======================== | |
- Assets/ : Main folder for all game assets. | |
- Art/ : Visual assets (animations, models, textures, etc.). | |
- Audio/ : Sound assets (music and sound effects). | |
- Prefabs/ : Reusable game objects (player, enemy, collectible items, etc.). | |
- Scenes/ : Game scenes and levels. | |
- Scripts/ : Code assets (C# scripts). | |
- UI/ : UI-related assets (fonts, sprites, etc.). | |
- Resources/ : Dynamically loaded runtime assets. | |
- Settings/ : Project settings (input, physics, rendering, etc.). | |
- ThirdParty/ : Third-party assets and libraries (external packages and plugins). | |
- Packages/ : Unity Package Manager dependencies (managed by Unity). | |
- ProjectSettings/ : Project settings and configuration files (managed by Unity). | |
- Logs/ : Log files (managed by Unity). | |
"@ | Set-Content -Path $TreeStructure -Encoding UTF8 | |
# Create `.gitignore` file | |
$GitIgnoreFile = "$BaseDir\.gitignore" | |
Write-Host "Writing .gitignore file..." | |
@" | |
# Unity generated files | |
[Ll]ibrary/ | |
[Tt]emp/ | |
[Oo]bj/ | |
[Bb]uild/ | |
[Bb]uilds/ | |
[Ll]ogs/ | |
[Mm]emoryCaptures/ | |
# Visual Studio | |
*.csproj | |
*.unityproj | |
*.sln | |
*.suo | |
*.tmp | |
*.user | |
*.userprefs | |
*.pidb | |
*.booproj | |
*.svd | |
# JetBrains Rider | |
.idea/ | |
# OS generated files | |
.DS_Store | |
Thumbs.db | |
"@ | Set-Content -Path $GitIgnoreFile -Encoding UTF8 | |
# Create `.gitattributes` file | |
$GitAttributesFile = "$BaseDir\.gitattributes" | |
Write-Host "Writing .gitattributes file..." | |
@" | |
# Set default behaviour to automatically merge binary files | |
* text=auto | |
# Unity YAML files | |
*.unity merge=unityyaml | |
*.asset merge=unityyaml | |
*.prefab merge=unityyaml | |
*.mat merge=unityyaml | |
*.anim merge=unityyaml | |
# Image files | |
*.png binary | |
*.jpg binary | |
*.jpeg binary | |
*.psd binary | |
# Audio files | |
*.mp3 binary | |
*.wav binary | |
"@ | Set-Content -Path $GitAttributesFile -Encoding UTF8 | |
# Create `ignore.conf` file for Plastic SCM | |
$IgnoreConfFile = "$BaseDir\ignore.conf" | |
Write-Host "Writing ignore.conf file for Plastic SCM..." | |
@" | |
Library | |
library | |
Temp | |
temp | |
Obj | |
obj | |
Build | |
build | |
Builds | |
builds | |
UserSettings | |
usersettings | |
MemoryCaptures | |
memorycaptures | |
Logs | |
logs | |
.DS_Store* | |
Thumbs.db | |
Desktop.ini | |
*.apk | |
*.unitypackage | |
"@ | Set-Content -Path $IgnoreConfFile -Encoding UTF8 | |
# Print completion message | |
Write-Host "Unity project structure created successfully in '$BaseDir'." | |
Write-Host "Refer to 'structure.txt' for directory explanations." | |
Write-Host ".gitignore, .gitattributes, and ignore.conf files created successfully!" | |
Write-Host "You can start building your Unity project now! ๐ ๐ฎ ๐" | |
# Note: Adjust execution policy if needed | |
# Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment