@@ -234,6 +234,56 @@ function Get-OperatingSystem {
234
234
}
235
235
}
236
236
237
+ <#
238
+ . Synopsis
239
+ Get the Unity Editor application
240
+ . PARAMETER Path
241
+ Path of a UnitySetupInstance
242
+ . EXAMPLE
243
+ Get-UnityEditor -Path $unitySetupInstance.Path
244
+ #>
245
+ function Get-UnityEditor {
246
+ [CmdletBinding ()]
247
+ param (
248
+ [ValidateScript ( {Test-Path $_ - PathType Container} )]
249
+ [Parameter (Mandatory = $false , ValueFromPipeline = $true , Position = 0 , ParameterSetName = " Path" )]
250
+ [string []]$Path = $PWD ,
251
+
252
+ [Parameter (Mandatory = $true , ValueFromPipeline = $true , Position = 0 , ParameterSetName = " Instance" )]
253
+ [ValidateNotNull ()]
254
+ [UnitySetupInstance []]$Instance
255
+ )
256
+
257
+ process {
258
+
259
+ if ( $PSCmdlet.ParameterSetName -eq " Instance" ) {
260
+ $Path = $Instance.Path
261
+ }
262
+
263
+ $currentOS = Get-OperatingSystem
264
+ foreach ($p in $Path ) {
265
+ switch ($currentOS ) {
266
+ ([OperatingSystem ]::Windows) {
267
+ $editor = Get-ChildItem " $p " - Filter ' Unity.exe' - Recurse |
268
+ Select-Object - First 1 - ExpandProperty FullName
269
+
270
+ Write-Output $editor
271
+ }
272
+ ([OperatingSystem ]::Linux) {
273
+ throw " Get-UnityEditor has not been implemented on the Linux platform. Contributions welcomed!" ;
274
+ }
275
+ ([OperatingSystem ]::Mac) {
276
+ $editor = Join-Path " $p " " Unity.app/Contents/MacOS/Unity"
277
+
278
+ if (Test-Path $editor ) {
279
+ Write-Output (Resolve-Path $editor ).Path
280
+ }
281
+ }
282
+ }
283
+ }
284
+ }
285
+ }
286
+
237
287
<#
238
288
. Synopsis
239
289
Help to create UnitySetupComponent
@@ -1091,9 +1141,10 @@ function Get-UnitySetupInstance {
1091
1141
}
1092
1142
}
1093
1143
1094
- Get-ChildItem $BasePath - Directory | Where-Object {
1095
- Test-Path (Join-Path $_.FullName ' Editor\Unity.exe' ) - PathType Leaf
1096
- } | ForEach-Object {
1144
+
1145
+ $BasePath | Where-Object { Test-Path $_ - PathType Container } |
1146
+ Get-ChildItem - Directory | Where-Object { (Get-UnityEditor $_.FullName ).Count -gt 0 } |
1147
+ ForEach-Object {
1097
1148
$path = $_.FullName
1098
1149
try {
1099
1150
Write-Verbose " Creating UnitySetupInstance for $path "
@@ -1531,32 +1582,14 @@ function Start-UnityEditor {
1531
1582
$setupInstances += , $setupInstance
1532
1583
}
1533
1584
1534
- $currentOS = Get-OperatingSystem
1535
1585
1536
1586
for ($i = 0 ; $i -lt $setupInstances.Length ; $i ++ ) {
1537
1587
$setupInstance = $setupInstances [$i ]
1538
1588
1539
- switch ($currentOS ) {
1540
- ([OperatingSystem ]::Windows) {
1541
- $editor = Get-ChildItem " $ ( $setupInstance.Path ) " - Filter ' Unity.exe' - Recurse |
1542
- Select-Object - First 1 - ExpandProperty FullName
1543
-
1544
- if ([string ]::IsNullOrEmpty($editor )) {
1545
- Write-Error " Could not find Unity.exe under setup instance path: $ ( $setupInstance.Path ) "
1546
- continue
1547
- }
1548
- }
1549
- ([OperatingSystem ]::Linux) {
1550
- throw " Start-UnityEditor has not been implemented on the Linux platform. Contributions welcomed!" ;
1551
- }
1552
- ([OperatingSystem ]::Mac) {
1553
- $editor = [io.path ]::Combine(" $ ( $setupInstance.Path ) " , " Unity.app/Contents/MacOS/Unity" )
1554
-
1555
- if ([string ]::IsNullOrEmpty($editor )) {
1556
- Write-Error " Could not find Unity app under setup instance path: $ ( $setupInstance.Path ) "
1557
- continue
1558
- }
1559
- }
1589
+ $editor = Get-UnityEditor " $ ( $setupInstance.Path ) "
1590
+ if ( -not $editor ) {
1591
+ Write-Error " Could not find Unity Editor under setup instance path: $ ( $setupInstance.Path ) "
1592
+ continue
1560
1593
}
1561
1594
1562
1595
# clone the shared args list
@@ -1698,6 +1731,7 @@ function Get-UnityLicense {
1698
1731
@ { ' Name' = ' gusi' ; ' Value' = ' Get-UnitySetupInstance' },
1699
1732
@ { ' Name' = ' gupi' ; ' Value' = ' Get-UnityProjectInstance' },
1700
1733
@ { ' Name' = ' susi' ; ' Value' = ' Select-UnitySetupInstance' },
1734
+ @ { ' Name' = ' gue' ; ' Value' = ' Get-UnityEditor' }
1701
1735
@ { ' Name' = ' sue' ; ' Value' = ' Start-UnityEditor' }
1702
1736
) | ForEach-Object {
1703
1737
0 commit comments