@@ -24,13 +24,16 @@ $vMatches = [regex]::Matches($version, $pattern)
2424$unityVersion = $vMatches [1 ].Groups[' version' ].Value.Trim()
2525$unityVersionChangeSet = $vMatches [2 ].Groups[' revision' ].Value.Trim()
2626
27- if ( -not ([String ]::IsNullOrEmpty($unityVersion ))) {
27+ if (-not ([String ]::IsNullOrEmpty($unityVersion ))) {
2828 Write-Host " "
2929 " UNITY_EDITOR_VERSION=$unityVersion " >> $env: GITHUB_ENV
3030 Write-Host " Unity Editor version set to: $unityVersion "
31+ } else {
32+ Write-Error " Failed to determine editor version to install!"
33+ exit 1
3134}
3235
33- if ( ( -not $ global :PSVersionTable .Platform ) -or ( $ global :PSVersionTable .Platform -eq " Win32NT " ) ) {
36+ if ($IsWindows ) {
3437 $hubPath = " C:\Program Files\Unity Hub\Unity Hub.exe"
3538 $editorRootPath = " C:\Program Files\Unity\Hub\Editor\"
3639 $editorFileEx = " \Editor\Unity.exe"
@@ -46,8 +49,7 @@ if ( (-not $global:PSVersionTable.Platform) -or ($global:PSVersionTable.Platform
4649 $p = Start-Process - NoNewWindow - PassThru - Wait - FilePath " $hubPath " - ArgumentList $argList
4750 $p.WaitForExit ()
4851 }
49- }
50- elseif ( $global :PSVersionTable.OS.Contains (" Darwin" ) ) {
52+ } elseif ($IsMacOS ) {
5153 $hubPath = " /Applications/Unity Hub.app/Contents/MacOS/Unity Hub"
5254 $editorRootPath = " /Applications/Unity/Hub/Editor/"
5355 $editorFileEx = " /Unity.app/Contents/MacOS/Unity"
@@ -63,8 +65,7 @@ elseif ( $global:PSVersionTable.OS.Contains("Darwin") ) {
6365 $p = Start-Process - NoNewWindow - PassThru - Wait - FilePath " $hubPath " - ArgumentList $argList
6466 $p.WaitForExit ()
6567 }
66- }
67- elseif ( $global :PSVersionTable.OS.Contains (" Linux" ) ) {
68+ } elseif ($IsLinux ) {
6869 $hubPath = " /usr/bin/unityhub"
6970 $editorRootPath = " $HOME /Unity/Hub/Editor/"
7071 $editorFileEx = " /Editor/Unity"
@@ -79,6 +80,9 @@ elseif ( $global:PSVersionTable.OS.Contains("Linux") ) {
7980 $argsList = $args.Split (" " )
8081 xvfb- run -- auto- servernum " $hubPath " -- disable-gpu - sandbox -- headless $argsList
8182 }
83+ } else {
84+ Write-Error " Unsupported platform: $ ( $global :PSVersionTable.Platform ) "
85+ exit 1
8286}
8387
8488# Install hub if not found
@@ -88,9 +92,9 @@ if ( -not (Test-Path -Path "$hubPath") ) {
8892 $outPath = $PSScriptRoot
8993 $wc = New-Object System.Net.WebClient
9094
91- Write-Host " ::group::Installing Unity Hub..."
9295
93- if ((-not $global :PSVersionTable.Platform ) -or ($global :PSVersionTable.Platform -eq " Win32NT" )) {
96+ if ($IsWindows ) {
97+ Write-Host " ::group::Installing Unity Hub on windows..."
9498 $wc.DownloadFile (" $baseUrl /UnityHubSetup.exe" , " $outPath /UnityHubSetup.exe" )
9599 $startProcessArgs = @ {
96100 ' FilePath' = " $outPath /UnityHubSetup.exe" ;
@@ -106,8 +110,8 @@ if ( -not (Test-Path -Path "$hubPath") ) {
106110 Write-Error " $ ( Get-Date ) : Failed with exit code: $ ( $process.ExitCode ) "
107111 exit 1
108112 }
109- }
110- elseif ( $ global :PSVersionTable .OS.Contains ( " Darwin " )) {
113+ } elseif ( $IsMacOS ) {
114+ Write-Host " ::group::Installing Unity Hub on masOS... "
111115 $package = " UnityHubSetup.dmg"
112116 $downloadPath = " $outPath /$package "
113117 $wc.DownloadFile (" $baseUrl /$package " , $downloadPath )
@@ -121,13 +125,16 @@ if ( -not (Test-Path -Path "$hubPath") ) {
121125 sudo mkdir - p " /Library/Application Support/Unity"
122126 sudo chmod 775 " /Library/Application Support/Unity"
123127 touch ' /Library/Application Support/Unity/temp'
124- }
125- elseif ( $ global :PSVersionTable .OS.Contains ( " Linux " )) {
128+ } elseif ( $IsLinux ) {
129+ Write-Host " ::group::Installing Unity Hub on ubuntu... "
126130 sudo sh - c ' echo ""deb https://hub.unity3d.com/linux/repos/deb stable main"" > /etc/apt/sources.list.d/unityhub.list'
127131 wget - qO - https:// hub.unity3d.com / linux/ keys/ public | sudo apt- key add -
128132 sudo apt update
129133 sudo apt install - y unityhub
130- which unityhub
134+ $hubPath = which unityhub
135+ } else {
136+ Write-Error " Unsupported platform: $ ( $global :PSVersionTable.Platform ) "
137+ exit 1
131138 }
132139
133140 Write-Host " ::endgroup::"
@@ -140,39 +147,42 @@ if ( -not (Test-Path "$hubPath") ) {
140147
141148Write-Host " Unity Hub found at `" $hubPath `" "
142149
143- # Write-Host "Editor root path currently set to: `"$editorRootPath`""
144-
145150Write-Host " ::group::Unity Hub Options"
146151Invoke-UnityHub help
147152Write-Host " ::endgroup::"
148153
149154# only show errors if github actions debug is enabled
150- # if ($env:GITHUB_ACTIONS -eq " true" ) {
151- Invoke-UnityHub -- errors
155+ # if ($env:GITHUB_ACTIONS -eq ' true' ) {
156+ # Invoke-UnityHub --errors
152157# }
153158
159+ # set the editor path
154160$editorPath = " {0}{1}{2}" -f $editorRootPath , $unityVersion , $editorFileEx
155161
156- if ( -not (Test-Path - Path $editorPath )) {
157- Write-Host " Installing $unityVersion ($unityVersionChangeSet )"
158- $installArgs = @ (' install' , " --version $unityVersion " , " --changeset $unityVersionChangeSet " , ' --cm' )
159-
160- if (-not [string ]::IsNullOrEmpty($architecture )) {
161- $installArgs += " -a $architecture "
162- }
163-
164- $addModules = @ ()
165-
166- foreach ($module in $modules ) {
167- if ($module -eq ' android' ) {
168- $addmodules += ' android-open-jdk'
169- $addmodules += ' android-sdk-ndk-tools'
162+ # if architecture is set, check if the specific architecture is installed
163+ if (-not [string ]::IsNullOrEmpty($architecture )) {
164+ # if an editor path is found, check which architecture it is
165+ if (Test-Path - Path $editorPath ) {
166+ # list all editor installations and pick the ones with the matching version from the returned console output
167+ $archEditors = Invoke-UnityHub editors - i | Select-String - Pattern " $unityVersion " - AllMatches | ForEach-Object { $_.Matches } | ForEach-Object { $_.Value }
168+
169+ # iterate over the editors and check if the version name contains (Intel) for x86_64 or (Apple silicon) for arm64
170+ foreach ($archEditor in $archEditors ) {
171+ if ($IsMacOS ) {
172+ if ((($archEditor.Contains (" (Intel)" ) -and $architecture -eq ' x86_64' )) -or ($archEditor.Contains (" (Apple silicon)" ) -and $architecture -eq ' arm64' )) {
173+ # set the editor path based on the editor string that was found using a substring. Split subtring by ',' and take the last element
174+ $editorPath = $archEditor.Substring (0 , $archEditor.IndexOf (' ,' ))
175+ }
176+ } else {
177+ Write-Error " Architecture lookup not supported for $ ( $global :PSVersionTable.Platform ) "
178+ exit 1
179+ }
170180 }
171181 }
182+ }
172183
173- $modules += $addModules
174-
175- foreach ($module in $modules ) {
184+ function Invoke-Hub-Install ($installModules , $installArgs ) {
185+ foreach ($module in $installModules ) {
176186 $installArgs += ' -m'
177187 $installArgs += $module
178188 Write-Host " > with module: $module "
@@ -184,53 +194,64 @@ if ( -not (Test-Path -Path $editorPath)) {
184194 Invoke-UnityHub $installArgsString
185195 Write-Host " "
186196 Write-Host " ::endgroup::"
187- } else {
188- Write-Host " Intalling modules for $unityVersion ($unityVersionChangeSet )"
189- $installArgs = @ (' install-modules' , " --version $unityVersion " , ' --cm' )
197+ }
190198
199+ function AddModules {
191200 $addModules = @ ()
192201
193202 foreach ($module in $modules ) {
203+ $addModules += $module
194204 if ($module -eq ' android' ) {
195- $addmodules += ' android-open-jdk'
196- $addmodules += ' android-sdk-ndk-tools'
205+ $jdkModule = $modules | Where-Object { $_ -like ' android-open-jdk*' }
206+ if (-not ($modules | Where-Object { $_ -eq $jdkModule })) {
207+ $addModules += $jdkModule
208+ }
209+ $ndkModule = $modules | Where-Object { $_ -like ' android-sdk-ndk-tools*' }
210+ if (-not ($modules | Where-Object { $_ -eq $ndkModule })) {
211+ $addModules += $ndkModule
212+ }
197213 }
198214 }
199215
200- $modules += $addModules
216+ return $addModules
217+ }
201218
202- foreach ($module in $modules ) {
203- $installArgs += ' -m'
204- $installArgs += $module
205- Write-Host " > with module: $module "
219+ if (-not (Test-Path - Path $editorPath )) {
220+ Write-Host " Installing $unityVersion ($unityVersionChangeSet )"
221+ $installArgs = @ (' install' , " --version $unityVersion " , " --changeset $unityVersionChangeSet " , ' --cm' )
222+ $installModules = AddModules
223+
224+ if (-not [string ]::IsNullOrEmpty($architecture ) -and $architecture -ne ' x86_64' ) {
225+ $installArgs += " -a $architecture "
206226 }
207227
208- $installArgsString = $installArgs -join " "
228+ Invoke-Hub - Install $installModules $installArgs
229+ } else {
230+ Write-Host " Checking modules for $unityVersion ($unityVersionChangeSet )"
231+ $installArgs = @ (' install-modules' , " --version $unityVersion " , ' --cm' )
232+ $installModules = AddModules
209233
210- Write-Host " ::group::Run unity-hub $installArgsString "
211- Invoke-UnityHub $installArgsString
212- Write-Host " "
213- Write-Host " ::endgroup::"
234+ if ($installModules.Count -gt 0 ) {
235+ Invoke-Hub - Install $installModules $installArgs
236+ }
214237}
215238
216239Write-Host " Installed Editors:"
217240Invoke-UnityHub editors - i
218241
219- if ( -not (Test-Path - Path $editorPath ) ) {
242+ if (-not (Test-Path - Path $editorPath )) {
220243 Write-Error " Failed to validate installed editor path at $editorPath "
221244 exit 1
222245}
223246
224247$modulesPath = ' {0}{1}{2}modules.json' -f $editorRootPath , $UnityVersion , [IO.Path ]::DirectorySeparatorChar
225248
226- if ( -not (Test-Path - Path $modulesPath )) {
249+ if (-not (Test-Path - Path $modulesPath )) {
227250 $editorPath = " {0}{1}" -f $editorRootPath , $unityVersion
228- # Write-Host "Cleaning up invalid installation under $editorPath"
229251 Write-Error " Failed to resolve modules path at $modulesPath "
230252
231253 if (Test-Path - Path $editorPath ) {
232254 Get-ChildItem $editorPath
233- # Remove-Item $editorPath -Recurse -Force
234255 }
235256
236257 exit 1
@@ -239,8 +260,8 @@ if ( -not (Test-Path -Path $modulesPath)) {
239260Write-Host " Modules Manifest: " $modulesPath
240261
241262foreach ($module in (Get-Content - Raw - Path $modulesPath | ConvertFrom-Json - AsHashTable)) {
242- if ( ($module.category -eq ' Platforms' ) -and ($module.visible -eq $true ) ) {
243- if ( -not ($modules -contains $module.id ) ) {
263+ if (($module.category -eq ' Platforms' ) -and ($module.visible -eq $true )) {
264+ if (-not ($modules -contains $module.id )) {
244265 Write-Host " > additional module option: " $module.id
245266 }
246267 }
0 commit comments