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