@@ -44,22 +44,22 @@ internal enum ManifestModificationMode {
44
44
}
45
45
46
46
private const string ADD_REGISTRIES_QUESTION =
47
- "Add the selected Unity Package Manager registries to your project?" ;
47
+ "Add the selected Package Manager registries to your project?" ;
48
48
private const string REMOVE_REGISTRIES_QUESTION =
49
- "Remove the selected Unity Package Manager registries from your project?" ;
49
+ "Remove the selected Package Manager registries from your project?" ;
50
50
private const string ADD_REGISTRIES_DESCRIPTION =
51
51
"Adding a registry will allow you to install, upgrade and remove packages from the " +
52
- "registry's server in the Unity Package Manager. By adding the selected registries, you " +
52
+ "registry's server in the Package Manager. By adding the selected registries, you " +
53
53
"agree that your use of these registries are subject to their terms of service and you " +
54
54
"acknowledge that data will be collected in accordance with each registry's privacy " +
55
55
"policy." ;
56
56
private const string REMOVE_REGISTRIES_DESCRIPTION =
57
57
"Removing a registry will prevent you from installing and upgrading packages from the " +
58
- "registry's server in the Unity Package Manager. It will not remove packages from the " +
58
+ "registry's server in the Package Manager. It will not remove packages from the " +
59
59
"registry's server that are already installed" ;
60
60
private const string ADD_OR_REMOVE_REGISTRIES_QUESTION =
61
- "Add the selected Unity Package Manager (UPM) registries to and remove the " +
62
- "unselected UPM registries from your project?" ;
61
+ "Add the selected Package Manager registries to and remove the " +
62
+ "unselected registries from your project?" ;
63
63
private const string MODIFY_MENU_ITEM_DESCRIPTION =
64
64
"You can always add or remove registries at a later time using menu item:\n " +
65
65
"'Assets > External Dependency Manager > Package Manager Resolver > " +
@@ -71,7 +71,17 @@ internal enum ManifestModificationMode {
71
71
private static readonly string [ ] googleScopes = new [ ] { "com.google" } ;
72
72
73
73
/// <summary>
74
- /// Enables / disables external package registries for Unity Package Manager.
74
+ /// Scroll location of the manifest view on the left in the registry selection window.
75
+ /// </summary>
76
+ private static Vector2 scrollManifestViewLeft ;
77
+
78
+ /// <summary>
79
+ /// Scroll location of the manifest view on the right in the registry selection window.
80
+ /// </summary>
81
+ private static Vector2 scrollManifestViewRight ;
82
+
83
+ /// <summary>
84
+ /// Enables / disables external package registries for Package Manager.
75
85
/// </summary>
76
86
static PackageManagerResolver ( ) {
77
87
logger . Log ( "Loaded PackageManagerResolver" , level : LogLevel . Verbose ) ;
@@ -219,9 +229,11 @@ private static Dictionary<string, PackageManagerRegistry> ReadRegistriesFromXml(
219
229
}
220
230
221
231
/// <summary>
222
- /// Apply registry changes to the projects manifest .
232
+ /// Apply registry changes to the modifier .
223
233
/// </summary>
224
234
/// <param name="manifestModifier">Object that modifies the project's manifest.</param>
235
+ /// <param name="registriesToAdd">Registries added to the modifier.</param>
236
+ /// <param name="registriesToRemove">Registries removed from the modifier.</param>
225
237
/// <param name="availableRegistries">Registries that are available in the
226
238
/// configuration.</param>
227
239
/// <param name="manifestRegistries">Registries that are present in the manifest.</param>
@@ -233,21 +245,20 @@ private static Dictionary<string, PackageManagerRegistry> ReadRegistriesFromXml(
233
245
/// <param name="invertSelection">If false, adds the selected registries and removes the
234
246
/// unselected registries. If true, removes the selected registries and adds the unselected
235
247
/// registries.</param>
236
- /// <param name="addedRegistries">If specified, is extended with the list of registries added
237
- /// to the manifest.<param>
238
- /// <returns>true if successful, false otherwise.</returns>
239
- private static bool SyncRegistriesToManifest (
248
+ /// <returns>true if the manifest is modified.</returns>
249
+ private static bool SyncRegistriesToModifier (
240
250
PackageManifestModifier manifestModifier ,
251
+ out List < PackageManagerRegistry > registriesToAdd ,
252
+ out List < PackageManagerRegistry > registriesToRemove ,
241
253
Dictionary < string , PackageManagerRegistry > availableRegistries ,
242
254
Dictionary < string , List < PackageManagerRegistry > > manifestRegistries ,
243
255
HashSet < string > selectedRegistryUrls ,
244
256
bool addRegistries = true ,
245
257
bool removeRegistries = true ,
246
- bool invertSelection = false ,
247
- List < PackageManagerRegistry > addedRegistries = null ) {
248
- // Build a list of registries to add to and remove from the manifest.
249
- var registriesToAdd = new List < PackageManagerRegistry > ( ) ;
250
- var registriesToRemove = new List < PackageManagerRegistry > ( ) ;
258
+ bool invertSelection = false ) {
259
+ // Build a list of registries to add to and remove from the modifier.
260
+ registriesToAdd = new List < PackageManagerRegistry > ( ) ;
261
+ registriesToRemove = new List < PackageManagerRegistry > ( ) ;
251
262
252
263
foreach ( var availableRegistry in availableRegistries . Values ) {
253
264
var url = availableRegistry . Url ;
@@ -276,6 +287,42 @@ private static bool SyncRegistriesToManifest(
276
287
manifestModifier . RemoveRegistries ( registriesToRemove ) ;
277
288
manifestModified = true ;
278
289
}
290
+ return manifestModified ;
291
+ }
292
+
293
+ /// <summary>
294
+ /// Apply registry changes to the projects manifest.
295
+ /// </summary>
296
+ /// <param name="manifestModifier">Object that modifies the project's manifest.</param>
297
+ /// <param name="availableRegistries">Registries that are available in the
298
+ /// configuration.</param>
299
+ /// <param name="manifestRegistries">Registries that are present in the manifest.</param>
300
+ /// <param name="selectedRegistryUrls">URLs of selected registries, these should be items in
301
+ /// availableRegistries.</param>
302
+ /// <param name="addRegistries">Whether to add selected registries to the manifest.</param>
303
+ /// <param name="removeRegistries">Whether to remove unselected registries from the
304
+ /// manifest.</param>
305
+ /// <param name="invertSelection">If false, adds the selected registries and removes the
306
+ /// unselected registries. If true, removes the selected registries and adds the unselected
307
+ /// registries.</param>
308
+ /// <param name="addedRegistries">If specified, is extended with the list of registries added
309
+ /// to the manifest.<param>
310
+ /// <returns>true if successful, false otherwise.</returns>
311
+ private static bool SyncRegistriesToManifest (
312
+ PackageManifestModifier manifestModifier ,
313
+ Dictionary < string , PackageManagerRegistry > availableRegistries ,
314
+ Dictionary < string , List < PackageManagerRegistry > > manifestRegistries ,
315
+ HashSet < string > selectedRegistryUrls ,
316
+ bool addRegistries = true ,
317
+ bool removeRegistries = true ,
318
+ bool invertSelection = false ,
319
+ List < PackageManagerRegistry > addedRegistries = null ) {
320
+ List < PackageManagerRegistry > registriesToAdd ;
321
+ List < PackageManagerRegistry > registriesToRemove ;
322
+ bool manifestModified = SyncRegistriesToModifier (
323
+ manifestModifier , out registriesToAdd , out registriesToRemove ,
324
+ availableRegistries , manifestRegistries , selectedRegistryUrls ,
325
+ addRegistries , removeRegistries , invertSelection ) ;
279
326
280
327
bool successful = true ;
281
328
if ( manifestModified ) {
@@ -401,6 +448,22 @@ internal static void UpdateManifest(ManifestModificationMode mode,
401
448
}
402
449
} ;
403
450
451
+ // Get the manifest json string based on the current selection and mode.
452
+ Func < HashSet < string > , string > getManifestJsonAfterChange = ( urlSelectionToApply ) => {
453
+ PackageManifestModifier clonedModifier = new PackageManifestModifier ( modifier ) ;
454
+ List < PackageManagerRegistry > toAdd ;
455
+ List < PackageManagerRegistry > toRemove ;
456
+ SyncRegistriesToModifier ( clonedModifier , out toAdd , out toRemove ,
457
+ xmlRegistries , manifestRegistries ,
458
+ urlSelectionToApply ,
459
+ addRegistries : ( mode == ManifestModificationMode . Add ||
460
+ mode == ManifestModificationMode . Modify ) ,
461
+ removeRegistries : ( mode == ManifestModificationMode . Remove ||
462
+ mode == ManifestModificationMode . Modify ) ,
463
+ invertSelection : mode == ManifestModificationMode . Remove ) ;
464
+ return clonedModifier . GetManifestJson ( ) ;
465
+ } ;
466
+
404
467
if ( xmlRegistries . Count > 0 ) {
405
468
if ( promptBeforeAction ) {
406
469
// Build a list of items to display.
@@ -455,6 +518,42 @@ internal static void UpdateManifest(ManifestModificationMode mode,
455
518
}
456
519
}
457
520
} ;
521
+ // Set the scroll position to the bottom since "scopedRegistry" section is most
522
+ // likely at the bottom of the file.
523
+ scrollManifestViewLeft = new Vector2 ( 0.0f , float . PositiveInfinity ) ;
524
+ scrollManifestViewRight = new Vector2 ( 0.0f , float . PositiveInfinity ) ;
525
+
526
+ // Render the change in manifest.json dynamically.
527
+ window . RenderAfterItems = ( ) => {
528
+ GUILayout . Label ( "Changes to Packages/manifest.json" ) ;
529
+ EditorGUILayout . Space ( ) ;
530
+
531
+ EditorGUILayout . BeginHorizontal ( ) ;
532
+
533
+ EditorGUILayout . BeginVertical ( ) ;
534
+ GUILayout . Label ( "Before" , EditorStyles . boldLabel ) ;
535
+ EditorGUILayout . Space ( ) ;
536
+ scrollManifestViewLeft =
537
+ EditorGUILayout . BeginScrollView ( scrollManifestViewLeft ,
538
+ GUILayout . MaxWidth ( window . position . width / 2.0f ) ) ;
539
+ EditorGUILayout . TextArea ( modifier . GetManifestJson ( ) ) ;
540
+ EditorGUILayout . EndScrollView ( ) ;
541
+ EditorGUILayout . EndVertical ( ) ;
542
+
543
+ EditorGUILayout . Space ( ) ;
544
+
545
+ EditorGUILayout . BeginVertical ( ) ;
546
+ GUILayout . Label ( "After" , EditorStyles . boldLabel ) ;
547
+ EditorGUILayout . Space ( ) ;
548
+ scrollManifestViewRight =
549
+ EditorGUILayout . BeginScrollView ( scrollManifestViewRight ,
550
+ GUILayout . MaxWidth ( window . position . width / 2.0f ) ) ;
551
+ EditorGUILayout . TextArea ( getManifestJsonAfterChange ( window . SelectedItems ) ) ;
552
+ EditorGUILayout . EndScrollView ( ) ;
553
+ EditorGUILayout . EndVertical ( ) ;
554
+
555
+ EditorGUILayout . EndHorizontal ( ) ;
556
+ } ;
458
557
if ( showDisableButton ) {
459
558
window . RenderBeforeCancelApply = ( ) => {
460
559
if ( GUILayout . Button ( "Disable Registry Addition" ) ) {
0 commit comments