-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #166 from Algoryx/feature/npm-support
Add support for installing example dependencies from NPMJS
- Loading branch information
Showing
7 changed files
with
128 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using System.Linq; | ||
using System.Reflection; | ||
using UnityEditor.PackageManager; | ||
using UnityEditor.PackageManager.Requests; | ||
|
||
public static class ScopedRegistryManager | ||
{ | ||
private static Request<RegistryInfo[]> s_request = null; | ||
public static void RequestRegistryListRefresh() | ||
{ | ||
var getMethod = typeof( Client ).GetMethod( "GetRegistries", BindingFlags.Static | BindingFlags.NonPublic, null, new System.Type[]{}, null ); | ||
s_request = (Request<RegistryInfo[]>)getMethod.Invoke( null, null ); | ||
} | ||
|
||
public static RegistryInfo[] GetRegistryInfos() | ||
{ | ||
if ( s_request == null ) | ||
RequestRegistryListRefresh(); | ||
|
||
var resultAccessor = typeof(Request<RegistryInfo[]>).GetProperty("Result",BindingFlags.Instance | BindingFlags.Public | BindingFlags.GetProperty); | ||
return (RegistryInfo[])resultAccessor.GetValue( s_request ); | ||
} | ||
|
||
public static void AddOrUpdateScopedRegistry( string name, string url, string[] scopes ) | ||
{ | ||
var assembly = typeof(UnityEditor.AssetDatabase).Assembly; | ||
var type = assembly.GetType( "UnityEditor.PackageManager.UI.Internal.ServicesContainer" ); | ||
var instanceAccessor = type.GetProperty( "instance", BindingFlags.Public | BindingFlags.Static | BindingFlags.GetProperty | BindingFlags.FlattenHierarchy ); | ||
var container = instanceAccessor.GetValue(null); | ||
|
||
var clientType = assembly.GetType("UnityEditor.PackageManager.UI.Internal.UpmRegistryClient"); | ||
|
||
var client = container.GetType().GetMethod( "Resolve", BindingFlags.Public | BindingFlags.Instance ).MakeGenericMethod( new System.Type[] { clientType } ).Invoke( container, new object[] {} ); | ||
|
||
var infos = GetRegistryInfos(); | ||
if(infos.Any(info => info.name == name ) ) { | ||
var updateMethod = clientType.GetMethod( | ||
"UpdateRegistry", | ||
BindingFlags.Instance | BindingFlags.Public, | ||
null, | ||
new System.Type[] { typeof( string ), typeof( string ), typeof( string ), typeof( string[] ) }, | ||
null ); | ||
updateMethod.Invoke( client, new object[] { (object)name, (object)name, (object)url, (object)scopes } ); | ||
} else { | ||
var addMethod = clientType.GetMethod( | ||
"AddRegistry", | ||
BindingFlags.Instance | BindingFlags.Public, | ||
null, | ||
new System.Type[] { typeof( string ), typeof( string ), typeof( string[] ) }, | ||
null ); | ||
addMethod.Invoke( client, new object[] { (object)name, (object)url, (object)scopes } ); | ||
} | ||
RequestRegistryListRefresh(); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters