Skip to content

Commit a32d40e

Browse files
authored
Merge pull request #177 from jwittner/fix/errorOnMissingPaths
Clean up editor search and fix recent issues
2 parents e2100a8 + d748ff7 commit a32d40e

File tree

2 files changed

+61
-25
lines changed

2 files changed

+61
-25
lines changed

UnitySetup/UnitySetup.psd1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
'Install-UnitySetupInstance',
8585
'Select-UnitySetupInstance',
8686
'Uninstall-UnitySetupInstance',
87+
'Get-UnityEditor',
8788
'Start-UnityEditor',
8889
'ConvertTo-UnitySetupComponent',
8990
'Get-UnityLicense'
@@ -100,6 +101,7 @@
100101
'gusi',
101102
'gupi',
102103
'susi',
104+
'gue',
103105
'sue'
104106
)
105107

UnitySetup/UnitySetup.psm1

Lines changed: 59 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,56 @@ function Get-OperatingSystem {
234234
}
235235
}
236236

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+
237287
<#
238288
.Synopsis
239289
Help to create UnitySetupComponent
@@ -1091,9 +1141,10 @@ function Get-UnitySetupInstance {
10911141
}
10921142
}
10931143

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 {
10971148
$path = $_.FullName
10981149
try {
10991150
Write-Verbose "Creating UnitySetupInstance for $path"
@@ -1531,32 +1582,14 @@ function Start-UnityEditor {
15311582
$setupInstances += , $setupInstance
15321583
}
15331584

1534-
$currentOS = Get-OperatingSystem
15351585

15361586
for ($i = 0; $i -lt $setupInstances.Length; $i++) {
15371587
$setupInstance = $setupInstances[$i]
15381588

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
15601593
}
15611594

15621595
# clone the shared args list
@@ -1698,6 +1731,7 @@ function Get-UnityLicense {
16981731
@{ 'Name' = 'gusi'; 'Value' = 'Get-UnitySetupInstance' },
16991732
@{ 'Name' = 'gupi'; 'Value' = 'Get-UnityProjectInstance' },
17001733
@{ 'Name' = 'susi'; 'Value' = 'Select-UnitySetupInstance' },
1734+
@{ 'Name' = 'gue'; 'Value' = 'Get-UnityEditor' }
17011735
@{ 'Name' = 'sue'; 'Value' = 'Start-UnityEditor' }
17021736
) | ForEach-Object {
17031737

0 commit comments

Comments
 (0)