43 lines
1.7 KiB
C#
43 lines
1.7 KiB
C#
using System.Linq;
|
|
using UnityEditor;
|
|
using UnityEditor.PackageManager;
|
|
using UnityEditor.PackageManager.Requests;
|
|
using UnityEngine;
|
|
|
|
namespace MagnetismHeroes.Editor
|
|
{
|
|
public static class PackageInstaller
|
|
{
|
|
private static AddAndRemoveRequest _request;
|
|
private static double _deadline;
|
|
|
|
public static void Install()
|
|
{
|
|
var installed = UnityEditor.PackageManager.PackageInfo.GetAllRegisteredPackages().Select(p => p.name).ToArray();
|
|
var remove = new[] { "com.unity.ai.navigation", "com.unity.collab-proxy", "com.unity.visualscripting", "com.unity.timeline", "com.unity.ide.rider" }
|
|
.Where(id => installed.Contains(id)).ToArray();
|
|
_request = Client.AddAndRemove(
|
|
new[] { "com.unity.inputsystem@1.20.0", "com.unity.render-pipelines.universal@17.6.0", "com.unity.test-framework@1.8.0", "com.unity.ugui@2.6.0", "com.unity.nuget.newtonsoft-json@3.2.2" },
|
|
remove);
|
|
_deadline = EditorApplication.timeSinceStartup + 600;
|
|
EditorApplication.update += Poll;
|
|
}
|
|
|
|
private static void Poll()
|
|
{
|
|
if (!_request.IsCompleted && EditorApplication.timeSinceStartup < _deadline) return;
|
|
EditorApplication.update -= Poll;
|
|
if (_request.Status == StatusCode.Success)
|
|
{
|
|
Debug.Log("[Packages] " + string.Join(", ", _request.Result.Select(p => p.name + "@" + p.version)));
|
|
EditorApplication.Exit(0);
|
|
}
|
|
else
|
|
{
|
|
Debug.LogError("[Packages] " + (_request.Error?.message ?? "Resolution timed out."));
|
|
EditorApplication.Exit(1);
|
|
}
|
|
}
|
|
}
|
|
}
|