2
2
# Licensed under the MIT License.
3
3
Import-Module powershell- yaml - MinimumVersion ' 0.3' - ErrorAction Stop
4
4
5
- [Flags ()]
5
+ [Flags ()]
6
6
enum UnitySetupComponent {
7
7
Setup = (1 -shl 0 )
8
8
Documentation = (1 -shl 1 )
@@ -18,6 +18,7 @@ enum UnitySetupComponent {
18
18
Mac = (1 -shl 11 )
19
19
Vuforia = (1 -shl 12 )
20
20
WebGL = (1 -shl 13 )
21
+ Windows = (1 -shl 14 )
21
22
All = (1 -shl 14 ) - 1
22
23
}
23
24
@@ -33,7 +34,7 @@ class UnitySetupInstance {
33
34
[UnityVersion ]$Version
34
35
[UnitySetupComponent ]$Components
35
36
[string ]$Path
36
-
37
+
37
38
UnitySetupInstance([string ]$path ) {
38
39
39
40
# Windows
@@ -44,14 +45,14 @@ class UnitySetupInstance {
44
45
else {
45
46
$ivyPath = ' Unity.app/Contents/UnityExtensions/Unity/Networking/ivy.xml'
46
47
}
47
-
48
+
48
49
$ivyPath = [io.path ]::Combine(" $path " , $ivyPath );
49
50
if (! (Test-Path $ivyPath )) { throw " Path is not a Unity setup: $path " }
50
51
[xml ]$xmlDoc = Get-Content $ivyPath
51
52
52
53
if ( ! ($xmlDoc .' ivy-module' .info.unityVersion)) {
53
54
throw " Unity setup ivy is missing version: $ivyPath "
54
- }
55
+ }
55
56
56
57
$this.Path = $path
57
58
$this.Version = $xmlDoc .' ivy-module' .info.unityVersion
@@ -105,16 +106,16 @@ class UnitySetupInstance {
105
106
}
106
107
107
108
class UnityProjectInstance {
108
- [UnityVersion ]$Version
109
+ [UnityVersion ]$Version
109
110
[string ]$Path
110
-
111
+
111
112
UnityProjectInstance([string ]$path ) {
112
113
$versionFile = [io.path ]::Combine($path , " ProjectSettings\ProjectVersion.txt" )
113
114
if (! (Test-Path $versionFile )) { throw " Path is not a Unity project: $path " }
114
115
115
116
$fileVersion = (Get-Content $versionFile - Raw | ConvertFrom-Yaml )[' m_EditorVersion' ];
116
117
if (! $fileVersion ) { throw " Project is missing a version in: $versionFile " }
117
-
118
+
118
119
$this.Path = $path
119
120
$this.Version = $fileVersion
120
121
}
@@ -138,13 +139,13 @@ class UnityVersion : System.IComparable {
138
139
$parts = $version.Split (' -' )
139
140
140
141
$parts [0 ] -match " (\d+)\.(\d+)\.(\d+)([fpb])(\d+)" | Out-Null
141
- if ( $Matches.Count -ne 6 ) { throw " Invalid unity version: $version " }
142
+ if ( $Matches.Count -ne 6 ) { throw " Invalid unity version: $version " }
142
143
$this.Major = [int ]($Matches [1 ]);
143
144
$this.Minor = [int ]($Matches [2 ]);
144
145
$this.Revision = [int ]($Matches [3 ]);
145
146
$this.Release = [char ]($Matches [4 ]);
146
147
$this.Build = [int ]($Matches [5 ]);
147
-
148
+
148
149
if ($parts.Length -gt 1 ) {
149
150
$this.Suffix = $parts [1 ];
150
151
}
@@ -153,20 +154,20 @@ class UnityVersion : System.IComparable {
153
154
[int ] CompareTo([object ]$obj ) {
154
155
if ($null -eq $obj ) { return 1 }
155
156
if ($obj -isnot [UnityVersion ]) { throw " Object is not a UnityVersion" }
156
-
157
+
157
158
return [UnityVersion ]::Compare($this , $obj )
158
159
}
159
160
160
161
static [int ] Compare([UnityVersion ]$a , [UnityVersion ]$b ) {
161
162
if ($a.Major -lt $b.Major ) { return -1 }
162
163
if ($a.Major -gt $b.Major ) { return 1 }
163
-
164
+
164
165
if ($a.Minor -lt $b.Minor ) { return -1 }
165
166
if ($a.Minor -gt $b.Minor ) { return 1 }
166
-
167
+
167
168
if ($a.Revision -lt $b.Revision ) { return -1 }
168
169
if ($a.Revision -gt $b.Revision ) { return 1 }
169
-
170
+
170
171
if ($a.Release -lt $b.Release ) { return -1 }
171
172
if ($a.Release -gt $b.Release ) { return 1 }
172
173
@@ -182,7 +183,7 @@ class UnityVersion : System.IComparable {
182
183
183
184
<#
184
185
. Synopsis
185
- Help to create UnitySetupComponent
186
+ Help to create UnitySetupComponent
186
187
. PARAMETER Components
187
188
What components would you like included?
188
189
. EXAMPLE
@@ -210,7 +211,7 @@ function ConvertTo-UnitySetupComponent {
210
211
. EXAMPLE
211
212
Find-UnitySetupInstaller -Version 2017.3.0f3
212
213
. EXAMPLE
213
- Find-UnitySetupInstaller -Version 2017.3.0f3 -Components Setup,Documentation
214
+ Find-UnitySetupInstaller -Version 2017.3.0f3 -Components Setup,Documentation
214
215
#>
215
216
function Find-UnitySetupInstaller {
216
217
[CmdletBinding ()]
@@ -263,8 +264,8 @@ function Find-UnitySetupInstaller {
263
264
$patchPage = " https://unity3d.com/unity/qa/patch-releases?version=$ ( $Version.Major ) .$ ( $Version.Minor ) "
264
265
$searchPages += $patchPage
265
266
266
- $webResult = Invoke-WebRequest $patchPage - UseBasicParsing
267
- $searchPages += $webResult.Links | Where-Object {
267
+ $webResult = Invoke-WebRequest $patchPage - UseBasicParsing
268
+ $searchPages += $webResult.Links | Where-Object {
268
269
$_.href -match " \/unity\/qa\/patch-releases\?version=$ ( $Version.Major ) \.$ ( $Version.Minor ) &page=(\d+)" -and $Matches [1 ] -gt 1
269
270
} | ForEach-Object {
270
271
" https://unity3d.com/unity/qa/patch-releases?version=$ ( $Version.Major ) .$ ( $Version.Minor ) &page=$ ( $Matches [1 ]) "
@@ -274,13 +275,13 @@ function Find-UnitySetupInstaller {
274
275
275
276
foreach ($page in $searchPages ) {
276
277
$webResult = Invoke-WebRequest $page - UseBasicParsing
277
- $prototypeLink = $webResult.Links | Select-Object - ExpandProperty href - ErrorAction SilentlyContinue | Where-Object {
278
- $_ -match " $ ( $installerTemplates [[UnitySetupComponent ]::Setup ]) $"
278
+ $prototypeLink = $webResult.Links | Select-Object - ExpandProperty href - ErrorAction SilentlyContinue | Where-Object {
279
+ $_ -match " $ ( $installerTemplates [[UnitySetupComponent ]::Setup ]) $"
279
280
}
280
281
281
282
if ($null -ne $prototypeLink ) { break }
282
283
}
283
-
284
+
284
285
if ($null -eq $prototypeLink ) {
285
286
throw " Could not find archives for Unity version $Version "
286
287
}
@@ -293,7 +294,7 @@ function Find-UnitySetupInstaller {
293
294
else {
294
295
$knownBaseUrls = $knownBaseUrls | Sort-Object - Property @ { Expression = {[math ]::Abs(($_.CompareTo ($linkComponents [0 ])))}; Ascending = $true }
295
296
}
296
-
297
+
297
298
$installerTemplates.Keys | Where-Object { $Components -band $_ } | ForEach-Object {
298
299
$templates = $installerTemplates.Item ($_ );
299
300
$result = $null
@@ -383,7 +384,7 @@ function Install-UnitySetupInstance {
383
384
$localDestinations += , " C:\Program Files\Unity-$ ( $i.Version ) "
384
385
}
385
386
386
- if ( Test-Path $destPath ) {
387
+ if ( Test-Path $destPath ) {
387
388
$destItem = Get-Item $destPath
388
389
if ( ($destItem.Length -eq $i.Length ) -and ($destItem.LastWriteTime -eq $i.LastModified ) ) {
389
390
Write-Verbose " Skipping download because it's already in the cache: $ ( $i.DownloadUrl ) "
@@ -403,10 +404,10 @@ function Install-UnitySetupInstance {
403
404
New-Item " $destDirectory " - ItemType Directory | Out-Null
404
405
}
405
406
}
406
-
407
+
407
408
Start-BitsTransfer - Source $downloadSource - Destination $downloadDest
408
409
}
409
-
410
+
410
411
$spins = @ (' |' , ' /' , ' -' , ' \' )
411
412
for ($i = 0 ; $i -lt $localInstallers.Length ; $i ++ ) {
412
413
$installer = $localInstallers [$i ]
@@ -421,7 +422,7 @@ function Install-UnitySetupInstance {
421
422
if ($Verb ) {
422
423
$startProcessArgs [' Verb' ] = $Verb
423
424
}
424
-
425
+
425
426
$spinnerIndex = 0
426
427
$process = Start-Process @startProcessArgs
427
428
while (! $process.HasExited ) {
@@ -433,7 +434,7 @@ function Install-UnitySetupInstance {
433
434
Write-Host " `b Failed."
434
435
Write-Error " Installing $installer failed with exit code: $ ( $process.ExitCode ) "
435
436
}
436
- else {
437
+ else {
437
438
Write-Host " `b Succeeded."
438
439
}
439
440
}
@@ -444,7 +445,7 @@ function Install-UnitySetupInstance {
444
445
. Synopsis
445
446
Uninstall Unity Setup Instances
446
447
. DESCRIPTION
447
- Uninstall the specified Unity Setup Instances
448
+ Uninstall the specified Unity Setup Instances
448
449
. PARAMETER Instance
449
450
What instances of UnitySetup should be uninstalled
450
451
. EXAMPLE
@@ -462,7 +463,7 @@ function Uninstall-UnitySetupInstance {
462
463
$uninstaller = Get-ChildItem " $ ( $setupInstance.Path ) " - Filter ' Uninstall.exe' - Recurse |
463
464
Select-Object - First 1 - ExpandProperty FullName
464
465
465
- if ($null -eq $uninstaller ) {
466
+ if ($null -eq $uninstaller ) {
466
467
Write-Error " Could not find Uninstaller.exe under $ ( $setupInstance.Path ) "
467
468
continue
468
469
}
@@ -520,7 +521,7 @@ function Get-UnitySetupInstance {
520
521
foreach ( $folder in $BasePath ) {
521
522
$path = [io.path ]::Combine(" $folder " , $ivyPath );
522
523
523
- Get-ChildItem $path - Recurse - ErrorAction Ignore |
524
+ Get-ChildItem $path - Recurse - ErrorAction Ignore |
524
525
ForEach-Object {
525
526
[UnitySetupInstance ]::new((Join-Path $_.Directory " ..\..\..\..\..\" | Convert-Path ))
526
527
}
@@ -557,17 +558,17 @@ function Select-UnitySetupInstance {
557
558
[parameter (Mandatory = $true , ValueFromPipeline = $true )]
558
559
[UnitySetupInstance []] $Instances
559
560
)
560
-
561
+
561
562
process {
562
- if ( $Version ) {
563
+ if ( $Version ) {
563
564
$Instances = $Instances | Where-Object { [UnityVersion ]::Compare($_.Version , $Version ) -eq 0 }
564
565
}
565
566
566
567
if ( $Latest ) {
567
- foreach ( $i in $Instances ) {
568
- if ( $null -eq $latestInstance -or [UnityVersion ]::Compare($i.Version , $latestInstance.Version ) -gt 0 ) {
568
+ foreach ( $i in $Instances ) {
569
+ if ( $null -eq $latestInstance -or [UnityVersion ]::Compare($i.Version , $latestInstance.Version ) -gt 0 ) {
569
570
$latestInstance = $i
570
- }
571
+ }
571
572
}
572
573
}
573
574
elseif ( $Instances.Count -gt 0 ) { $Instances }
@@ -583,7 +584,7 @@ function Select-UnitySetupInstance {
583
584
. DESCRIPTION
584
585
Recursively discovers Unity projects and their Unity version
585
586
. PARAMETER BasePath
586
- Under what base pattern should we look for Unity projects? Defaults to '$PWD'.
587
+ Under what base pattern should we look for Unity projects? Defaults to '$PWD'.
587
588
. EXAMPLE
588
589
Get-UnityProjectInstance
589
590
. EXAMPLE
@@ -708,7 +709,7 @@ function Start-UnityEditor {
708
709
[parameter (Mandatory = $false )]
709
710
[switch ]$PassThru
710
711
)
711
- process {
712
+ process {
712
713
switch - wildcard ( $PSCmdlet.ParameterSetName ) {
713
714
' Context' {
714
715
$projectInstances = [UnityProjectInstance []]@ ()
@@ -725,17 +726,17 @@ function Start-UnityEditor {
725
726
}
726
727
}
727
728
}
728
- ' Projects*' {
729
+ ' Projects*' {
729
730
$projectInstances = $Project
730
731
$setupInstances = [UnitySetupInstance []]@ ()
731
732
}
732
- ' Setups' {
733
+ ' Setups' {
733
734
$projectInstances = [UnityProjectInstance []]@ ()
734
735
$setupInstances = $Setup
735
736
}
736
737
' Latest' {
737
738
$projectInstances = [UnityProjectInstance []]@ ()
738
-
739
+
739
740
$currentFolderProject = if (! $IgnoreProjectContext ) { Get-UnityProjectInstance $PWD.Path }
740
741
if ($null -ne $currentFolderProject ) {
741
742
$projectInstances += , $currentFolderProject
@@ -778,8 +779,8 @@ function Start-UnityEditor {
778
779
if ( $ImportPackage ) { $sharedArgs += " -importPackage" , " $ImportPackage " }
779
780
780
781
$instanceArgs = @ ()
781
- foreach ( $p in $projectInstances ) {
782
-
782
+ foreach ( $p in $projectInstances ) {
783
+
783
784
if ( $Latest ) {
784
785
$setupInstance = Get-UnitySetupInstance | Select-UnitySetupInstance - Latest
785
786
if ($setupInstance.Count -eq 0 ) {
@@ -794,29 +795,42 @@ function Start-UnityEditor {
794
795
continue
795
796
}
796
797
}
797
- else {
798
+ else {
798
799
$setupInstance = Get-UnitySetupInstance | Select-UnitySetupInstance - Version $p.Version
799
800
if ($setupInstance.Count -eq 0 ) {
800
801
Write-Error " Could not find Unity Editor for version $ ( $p.Version ) "
801
802
continue
802
803
}
803
804
}
804
-
805
+
805
806
$projectPath = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath ($ ($p.Path ))
806
807
$instanceArgs += , (" -projectPath" , $projectPath )
807
808
$setupInstances += , $setupInstance
808
809
}
809
810
810
811
for ($i = 0 ; $i -lt $setupInstances.Length ; $i ++ ) {
811
812
$setupInstance = $setupInstances [$i ]
812
- $editor = Get-ChildItem " $ ( $setupInstance.Path ) " - Filter ' Unity.exe' - Recurse |
813
- Select-Object - First 1 - ExpandProperty FullName
814
813
815
- if ([string ]::IsNullOrEmpty($editor )) {
816
- Write-Error " Could not find Unity.exe under setup instance path: $ ( $setupInstance.Path ) "
817
- continue
814
+ # Windows
815
+ if ((-not $PSVersionTable.Platform ) -or ($PSVersionTable.Platform -eq " Win32NT" )) {
816
+ $editor = Get-ChildItem " $ ( $setupInstance.Path ) " - Filter ' Unity.exe' - Recurse |
817
+ Select-Object - First 1 - ExpandProperty FullName
818
+
819
+ if ([string ]::IsNullOrEmpty($editor )) {
820
+ Write-Error " Could not find Unity.exe under setup instance path: $ ( $setupInstance.Path ) "
821
+ continue
822
+ }
823
+ }
824
+ # Mac or Linux
825
+ else {
826
+ $editor = [io.path ]::Combine(" $ ( $setupInstance.Path ) " , " Unity.app/Contents/MacOS/Unity" )
827
+
828
+ if ([string ]::IsNullOrEmpty($editor )) {
829
+ Write-Error " Could not find Unity app under setup instance path: $ ( $setupInstance.Path ) "
830
+ continue
831
+ }
818
832
}
819
-
833
+
820
834
# clone the shared args list
821
835
$unityArgs = $sharedArgs | ForEach-Object { $_ }
822
836
if ( $instanceArgs [$i ] ) { $unityArgs += $instanceArgs [$i ] }
@@ -855,16 +869,16 @@ function Start-UnityEditor {
855
869
@ { ' Name' = ' gusi' ; ' Value' = ' Get-UnitySetupInstance' },
856
870
@ { ' Name' = ' gupi' ; ' Value' = ' Get-UnityProjectInstance' },
857
871
@ { ' Name' = ' susi' ; ' Value' = ' Select-UnitySetupInstance' },
858
- @ { ' Name' = ' sue' ; ' Value' = ' Start-UnityEditor' }
859
- ) | ForEach-Object {
872
+ @ { ' Name' = ' sue' ; ' Value' = ' Start-UnityEditor' }
873
+ ) | ForEach-Object {
860
874
861
875
$alias = Get-Alias - Name $_.Name - ErrorAction ' SilentlyContinue'
862
876
if ( -not $alias ) {
863
- Write-Verbose " Creating new alias $ ( $_.Name ) for $ ( $_.Value ) "
864
- New-Alias @_
877
+ Write-Verbose " Creating new alias $ ( $_.Name ) for $ ( $_.Value ) "
878
+ New-Alias @_
865
879
}
866
880
elseif ( $alias.ModuleName -eq ' UnitySetup' ) {
867
- Write-Verbose " Setting alias $ ( $_.Name ) to $ ( $_.Value ) "
881
+ Write-Verbose " Setting alias $ ( $_.Name ) to $ ( $_.Value ) "
868
882
Set-Alias @_
869
883
}
870
884
else {
0 commit comments