Add VRChat and GitHub packages to Unity project
This commit is contained in:
1 parent
0334a52b21
commit
85538aaccc
3297 files changed
+847877
No files matched your search
@@ -0,0 +1,71 @@
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEditor.PackageManager;
|
||||
using UnityEditor.PackageManager.Requests;
|
||||
using UnityEngine;
|
||||
|
||||
namespace VRC.Udon.Editor {
|
||||
[InitializeOnLoad]
|
||||
public class UPMImporter
|
||||
{
|
||||
// Add packages here to auto-import
|
||||
public static string[] requiredPackages =
|
||||
{
|
||||
"com.unity.cinemachine@2.6.3",
|
||||
"com.unity.postprocessing@2.3.0",
|
||||
"com.unity.textmeshpro@1.4.1",
|
||||
};
|
||||
|
||||
private static ListRequest list;
|
||||
|
||||
static UPMImporter()
|
||||
{
|
||||
list = Client.List();
|
||||
EditorApplication.update += Update;
|
||||
}
|
||||
|
||||
public static void Update()
|
||||
{
|
||||
// Exit early if we're still gathering the list
|
||||
if (!list.IsCompleted) return;
|
||||
|
||||
// Unsubscribe from Update once the list is ready
|
||||
EditorApplication.update -= Update;
|
||||
|
||||
var localPackages = list.Result;
|
||||
bool importedNewPackage = false;
|
||||
foreach (string packageName in requiredPackages)
|
||||
{
|
||||
var packageNameNoVersion = packageName.Substring(0, packageName.IndexOf('@'));
|
||||
if(!localPackages.Any(p => p.name == packageNameNoVersion))
|
||||
{
|
||||
Install(packageName);
|
||||
importedNewPackage = true;
|
||||
}
|
||||
}
|
||||
|
||||
// if Unity tried to import SDK3 before required packages, it will have old errors showing.
|
||||
if(importedNewPackage) ClearLog();
|
||||
}
|
||||
|
||||
public static bool Install(string id)
|
||||
{
|
||||
var request = Client.Add(id);
|
||||
while (!request.IsCompleted) {};
|
||||
if(request.Error != null)Debug.LogError(request.Error.message);
|
||||
return request.Error == null;
|
||||
}
|
||||
|
||||
public static void ClearLog()
|
||||
{
|
||||
System.Reflection.Assembly assembly = System.Reflection.Assembly.GetAssembly(typeof(SceneView));
|
||||
|
||||
System.Type type = assembly.GetType("UnityEditor.LogEntries");
|
||||
System.Reflection.MethodInfo method = type.GetMethod("Clear");
|
||||
method.Invoke(new object(), null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user