Skip to content
This repository was archived by the owner on Aug 11, 2024. It is now read-only.

Commit f0c931d

Browse files
.
1 parent bbaf56a commit f0c931d

File tree

2 files changed

+46
-52
lines changed

2 files changed

+46
-52
lines changed

dist/unity-install.ps1

+23-26
Original file line numberDiff line numberDiff line change
@@ -330,41 +330,38 @@ if ([String]::IsNullOrEmpty($envUnityHubPath)) {
330330
Write-Host "UnityHub path set to: `"$hubPath`""
331331
}
332332

333-
function Run-As {
333+
function Run {
334334
param(
335335
[string]$command,
336336
[string]$arguments
337337
)
338338

339-
if ((New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
340-
Write-Host "`"$command`" $arguments"
341-
$psi = New-Object System.Diagnostics.ProcessStartInfo;
342-
$psi.FileName = "$command";
343-
$psi.UseShellExecute = $false;
344-
$psi.Arguments = $arguments;
345-
$psi.CreateNoWindow = $true;
346-
$psi.RedirectStandardInput = $true;
347-
$p = [System.Diagnostics.Process]::Start($psi);
348-
while (-not $p.HasExited) {
349-
$p.StandardInput.WriteLine("y");
350-
Start-Sleep -Milliseconds 1
351-
}
352-
353-
if ($p.ExitCode -ne 0) {
354-
Write-Error "Failed to execute command `"$command`" with exit code: $($p.ExitCode)"
355-
exit 1
356-
}
339+
Write-Host "`"$command`" $arguments"
340+
$psi = New-Object System.Diagnostics.ProcessStartInfo;
341+
$psi.FileName = "$command";
342+
$psi.UseShellExecute = $false;
343+
$psi.Arguments = $arguments;
344+
$psi.CreateNoWindow = $true;
345+
$psi.RedirectStandardInput = $true;
346+
$p = [System.Diagnostics.Process]::Start($psi);
347+
while (-not $p.HasExited) {
348+
$p.StandardInput.WriteLine("y");
349+
Start-Sleep -Milliseconds 1
357350
}
358-
else {
359-
Write-Error "Administrative privileges required"
351+
352+
if ($p.ExitCode -ne 0) {
353+
Write-Error "Failed to execute command `"$command`" with exit code: $($p.ExitCode)"
360354
exit 1
361355
}
362356
}
363357

364358
# if modules contains android then attempt to install android sdk
365359
if ($modules -contains 'android') {
366-
# directory of the unity editor
367-
$rootEditorPath = (Get-Item $editorPath).Directory.Parent.FullName
360+
if (-not $IsMacOS) {
361+
$rootEditorPath = (Get-Item $editorPath).Directory.Parent.FullName
362+
} else{
363+
$rootEditorPath = $editorPath
364+
}
368365
$androidSdkPath = "$rootEditorPath/Editor/Data/PlaybackEngines/AndroidPlayer/SDK/cmdline-tools"
369366
# try to resolve the android cmdline tools path. The version isn't always latest. Just get first directory
370367
# C:\Program Files\Unity\Hub\Editor\2022.3.36f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\cmdline-tools\6.0\bin\sdkmanager
@@ -379,9 +376,9 @@ if ($modules -contains 'android') {
379376
exit 1
380377
}
381378
Write-Host "Accepting Android SDK Licenses"
382-
Run-As -command "$androidSdkManagerPath" -arguments "--licenses"
379+
Run -command "$androidSdkManagerPath" -arguments "--licenses"
383380
Write-Host "Updating Android SDK"
384-
Run-As -command "$androidSdkManagerPath" -arguments "--update"
381+
Run -command "$androidSdkManagerPath" -arguments "--update"
385382
$projectSettingsPath = "$projectPath/ProjectSettings/ProjectSettings.asset"
386383
if (-not (Test-Path -Path $projectSettingsPath)) {
387384
Write-Error "Failed to resolve project settings path at `"$projectSettingsPath`""
@@ -390,7 +387,7 @@ if ($modules -contains 'android') {
390387
$targetSdkVersion = Get-Content -Path $projectSettingsPath | Select-String -Pattern "AndroidTargetSdkVersion: \d+" -AllMatches | ForEach-Object { $_.Matches } | ForEach-Object { $_.Value -replace "AndroidTargetSdkVersion: ", "" }
391388
if ($targetSdkVersion -ne 0) {
392389
Write-Host "Installing Android SDK Platform $targetSdkVersion"
393-
Run-As -command "$androidSdkManagerPath" -arguments "`"platform-tools`" `"platforms;android-$targetSdkVersion`""
390+
Run -command "$androidSdkManagerPath" -arguments "`"platform-tools`" `"platforms;android-$targetSdkVersion`""
394391
}
395392
}
396393

src/unity-install.ps1

+23-26
Original file line numberDiff line numberDiff line change
@@ -330,41 +330,38 @@ if ([String]::IsNullOrEmpty($envUnityHubPath)) {
330330
Write-Host "UnityHub path set to: `"$hubPath`""
331331
}
332332

333-
function Run-As {
333+
function Run {
334334
param(
335335
[string]$command,
336336
[string]$arguments
337337
)
338338

339-
if ((New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
340-
Write-Host "`"$command`" $arguments"
341-
$psi = New-Object System.Diagnostics.ProcessStartInfo;
342-
$psi.FileName = "$command";
343-
$psi.UseShellExecute = $false;
344-
$psi.Arguments = $arguments;
345-
$psi.CreateNoWindow = $true;
346-
$psi.RedirectStandardInput = $true;
347-
$p = [System.Diagnostics.Process]::Start($psi);
348-
while (-not $p.HasExited) {
349-
$p.StandardInput.WriteLine("y");
350-
Start-Sleep -Milliseconds 1
351-
}
352-
353-
if ($p.ExitCode -ne 0) {
354-
Write-Error "Failed to execute command `"$command`" with exit code: $($p.ExitCode)"
355-
exit 1
356-
}
339+
Write-Host "`"$command`" $arguments"
340+
$psi = New-Object System.Diagnostics.ProcessStartInfo;
341+
$psi.FileName = "$command";
342+
$psi.UseShellExecute = $false;
343+
$psi.Arguments = $arguments;
344+
$psi.CreateNoWindow = $true;
345+
$psi.RedirectStandardInput = $true;
346+
$p = [System.Diagnostics.Process]::Start($psi);
347+
while (-not $p.HasExited) {
348+
$p.StandardInput.WriteLine("y");
349+
Start-Sleep -Milliseconds 1
357350
}
358-
else {
359-
Write-Error "Administrative privileges required"
351+
352+
if ($p.ExitCode -ne 0) {
353+
Write-Error "Failed to execute command `"$command`" with exit code: $($p.ExitCode)"
360354
exit 1
361355
}
362356
}
363357

364358
# if modules contains android then attempt to install android sdk
365359
if ($modules -contains 'android') {
366-
# directory of the unity editor
367-
$rootEditorPath = (Get-Item $editorPath).Directory.Parent.FullName
360+
if (-not $IsMacOS) {
361+
$rootEditorPath = (Get-Item $editorPath).Directory.Parent.FullName
362+
} else{
363+
$rootEditorPath = $editorPath
364+
}
368365
$androidSdkPath = "$rootEditorPath/Editor/Data/PlaybackEngines/AndroidPlayer/SDK/cmdline-tools"
369366
# try to resolve the android cmdline tools path. The version isn't always latest. Just get first directory
370367
# C:\Program Files\Unity\Hub\Editor\2022.3.36f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\cmdline-tools\6.0\bin\sdkmanager
@@ -379,9 +376,9 @@ if ($modules -contains 'android') {
379376
exit 1
380377
}
381378
Write-Host "Accepting Android SDK Licenses"
382-
Run-As -command "$androidSdkManagerPath" -arguments "--licenses"
379+
Run -command "$androidSdkManagerPath" -arguments "--licenses"
383380
Write-Host "Updating Android SDK"
384-
Run-As -command "$androidSdkManagerPath" -arguments "--update"
381+
Run -command "$androidSdkManagerPath" -arguments "--update"
385382
$projectSettingsPath = "$projectPath/ProjectSettings/ProjectSettings.asset"
386383
if (-not (Test-Path -Path $projectSettingsPath)) {
387384
Write-Error "Failed to resolve project settings path at `"$projectSettingsPath`""
@@ -390,7 +387,7 @@ if ($modules -contains 'android') {
390387
$targetSdkVersion = Get-Content -Path $projectSettingsPath | Select-String -Pattern "AndroidTargetSdkVersion: \d+" -AllMatches | ForEach-Object { $_.Matches } | ForEach-Object { $_.Value -replace "AndroidTargetSdkVersion: ", "" }
391388
if ($targetSdkVersion -ne 0) {
392389
Write-Host "Installing Android SDK Platform $targetSdkVersion"
393-
Run-As -command "$androidSdkManagerPath" -arguments "`"platform-tools`" `"platforms;android-$targetSdkVersion`""
390+
Run -command "$androidSdkManagerPath" -arguments "`"platform-tools`" `"platforms;android-$targetSdkVersion`""
394391
}
395392
}
396393

0 commit comments

Comments
 (0)