@@ -24,13 +24,16 @@ $vMatches = [regex]::Matches($version, $pattern)
24
24
$unityVersion = $vMatches [1 ].Groups[' version' ].Value.Trim()
25
25
$unityVersionChangeSet = $vMatches [2 ].Groups[' revision' ].Value.Trim()
26
26
27
- if ( -not ([String ]::IsNullOrEmpty($unityVersion ))) {
27
+ if (-not ([String ]::IsNullOrEmpty($unityVersion ))) {
28
28
Write-Host " "
29
29
" UNITY_EDITOR_VERSION=$unityVersion " >> $env: GITHUB_ENV
30
30
Write-Host " Unity Editor version set to: $unityVersion "
31
+ } else {
32
+ Write-Error " Failed to determine editor version to install!"
33
+ exit 1
31
34
}
32
35
33
- if ( ( -not $ global :PSVersionTable .Platform ) -or ( $ global :PSVersionTable .Platform -eq " Win32NT " ) ) {
36
+ if ($IsWindows ) {
34
37
$hubPath = " C:\Program Files\Unity Hub\Unity Hub.exe"
35
38
$editorRootPath = " C:\Program Files\Unity\Hub\Editor\"
36
39
$editorFileEx = " \Editor\Unity.exe"
@@ -46,8 +49,7 @@ if ( (-not $global:PSVersionTable.Platform) -or ($global:PSVersionTable.Platform
46
49
$p = Start-Process - NoNewWindow - PassThru - Wait - FilePath " $hubPath " - ArgumentList $argList
47
50
$p.WaitForExit ()
48
51
}
49
- }
50
- elseif ( $global :PSVersionTable.OS.Contains (" Darwin" ) ) {
52
+ } elseif ($IsMacOS ) {
51
53
$hubPath = " /Applications/Unity Hub.app/Contents/MacOS/Unity Hub"
52
54
$editorRootPath = " /Applications/Unity/Hub/Editor/"
53
55
$editorFileEx = " /Unity.app/Contents/MacOS/Unity"
@@ -63,8 +65,7 @@ elseif ( $global:PSVersionTable.OS.Contains("Darwin") ) {
63
65
$p = Start-Process - NoNewWindow - PassThru - Wait - FilePath " $hubPath " - ArgumentList $argList
64
66
$p.WaitForExit ()
65
67
}
66
- }
67
- elseif ( $global :PSVersionTable.OS.Contains (" Linux" ) ) {
68
+ } elseif ($IsLinux ) {
68
69
$hubPath = " /usr/bin/unityhub"
69
70
$editorRootPath = " $HOME /Unity/Hub/Editor/"
70
71
$editorFileEx = " /Editor/Unity"
@@ -79,6 +80,9 @@ elseif ( $global:PSVersionTable.OS.Contains("Linux") ) {
79
80
$argsList = $args.Split (" " )
80
81
xvfb- run -- auto- servernum " $hubPath " -- disable-gpu - sandbox -- headless $argsList
81
82
}
83
+ } else {
84
+ Write-Error " Unsupported platform: $ ( $global :PSVersionTable.Platform ) "
85
+ exit 1
82
86
}
83
87
84
88
# Install hub if not found
@@ -88,9 +92,9 @@ if ( -not (Test-Path -Path "$hubPath") ) {
88
92
$outPath = $PSScriptRoot
89
93
$wc = New-Object System.Net.WebClient
90
94
91
- Write-Host " ::group::Installing Unity Hub..."
92
95
93
- if ((-not $global :PSVersionTable.Platform ) -or ($global :PSVersionTable.Platform -eq " Win32NT" )) {
96
+ if ($IsWindows ) {
97
+ Write-Host " ::group::Installing Unity Hub on windows..."
94
98
$wc.DownloadFile (" $baseUrl /UnityHubSetup.exe" , " $outPath /UnityHubSetup.exe" )
95
99
$startProcessArgs = @ {
96
100
' FilePath' = " $outPath /UnityHubSetup.exe" ;
@@ -106,8 +110,8 @@ if ( -not (Test-Path -Path "$hubPath") ) {
106
110
Write-Error " $ ( Get-Date ) : Failed with exit code: $ ( $process.ExitCode ) "
107
111
exit 1
108
112
}
109
- }
110
- elseif ( $ global :PSVersionTable .OS.Contains ( " Darwin " )) {
113
+ } elseif ( $IsMacOS ) {
114
+ Write-Host " ::group::Installing Unity Hub on masOS... "
111
115
$package = " UnityHubSetup.dmg"
112
116
$downloadPath = " $outPath /$package "
113
117
$wc.DownloadFile (" $baseUrl /$package " , $downloadPath )
@@ -121,13 +125,16 @@ if ( -not (Test-Path -Path "$hubPath") ) {
121
125
sudo mkdir - p " /Library/Application Support/Unity"
122
126
sudo chmod 775 " /Library/Application Support/Unity"
123
127
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... "
126
130
sudo sh - c ' echo ""deb https://hub.unity3d.com/linux/repos/deb stable main"" > /etc/apt/sources.list.d/unityhub.list'
127
131
wget - qO - https:// hub.unity3d.com / linux/ keys/ public | sudo apt- key add -
128
132
sudo apt update
129
133
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
131
138
}
132
139
133
140
Write-Host " ::endgroup::"
@@ -140,39 +147,42 @@ if ( -not (Test-Path "$hubPath") ) {
140
147
141
148
Write-Host " Unity Hub found at `" $hubPath `" "
142
149
143
- # Write-Host "Editor root path currently set to: `"$editorRootPath`""
144
-
145
150
Write-Host " ::group::Unity Hub Options"
146
151
Invoke-UnityHub help
147
152
Write-Host " ::endgroup::"
148
153
149
154
# 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
152
157
# }
153
158
159
+ # set the editor path
154
160
$editorPath = " {0}{1}{2}" -f $editorRootPath , $unityVersion , $editorFileEx
155
161
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
+ }
170
180
}
171
181
}
182
+ }
172
183
173
- $modules += $addModules
174
-
175
- foreach ($module in $modules ) {
184
+ function Invoke-Hub-Install ($installModules , $installArgs ) {
185
+ foreach ($module in $installModules ) {
176
186
$installArgs += ' -m'
177
187
$installArgs += $module
178
188
Write-Host " > with module: $module "
@@ -184,53 +194,64 @@ if ( -not (Test-Path -Path $editorPath)) {
184
194
Invoke-UnityHub $installArgsString
185
195
Write-Host " "
186
196
Write-Host " ::endgroup::"
187
- } else {
188
- Write-Host " Intalling modules for $unityVersion ($unityVersionChangeSet )"
189
- $installArgs = @ (' install-modules' , " --version $unityVersion " , ' --cm' )
197
+ }
190
198
199
+ function AddModules {
191
200
$addModules = @ ()
192
201
193
202
foreach ($module in $modules ) {
203
+ $addModules += $module
194
204
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
+ }
197
213
}
198
214
}
199
215
200
- $modules += $addModules
216
+ return $addModules
217
+ }
201
218
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 "
206
226
}
207
227
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
209
233
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
+ }
214
237
}
215
238
216
239
Write-Host " Installed Editors:"
217
240
Invoke-UnityHub editors - i
218
241
219
- if ( -not (Test-Path - Path $editorPath ) ) {
242
+ if (-not (Test-Path - Path $editorPath )) {
220
243
Write-Error " Failed to validate installed editor path at $editorPath "
221
244
exit 1
222
245
}
223
246
224
247
$modulesPath = ' {0}{1}{2}modules.json' -f $editorRootPath , $UnityVersion , [IO.Path ]::DirectorySeparatorChar
225
248
226
- if ( -not (Test-Path - Path $modulesPath )) {
249
+ if (-not (Test-Path - Path $modulesPath )) {
227
250
$editorPath = " {0}{1}" -f $editorRootPath , $unityVersion
228
- # Write-Host "Cleaning up invalid installation under $editorPath"
229
251
Write-Error " Failed to resolve modules path at $modulesPath "
230
252
231
253
if (Test-Path - Path $editorPath ) {
232
254
Get-ChildItem $editorPath
233
- # Remove-Item $editorPath -Recurse -Force
234
255
}
235
256
236
257
exit 1
@@ -239,8 +260,8 @@ if ( -not (Test-Path -Path $modulesPath)) {
239
260
Write-Host " Modules Manifest: " $modulesPath
240
261
241
262
foreach ($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 )) {
244
265
Write-Host " > additional module option: " $module.id
245
266
}
246
267
}
0 commit comments