Search Unity

Package manager - showing hidden packages (script)

Discussion in 'Package Manager' started by OndrejP, Oct 27, 2020.

  1. OndrejP

    OndrejP

    Joined:
    Jul 19, 2017
    Posts:
    304
    Scripts for showing hidden packages and disabling annoying button on toolbar (Preview packages in use).
    Now works in both 2020.1 and 2020.2.

    EDIT: Now available as GIT package
    https://github.com/OndrejPetrzilka/package-manager-extra-settings.git
    1. Open PackageManager
    2. Add package from git URL (URL above)
    3. Refresh Package Manager
    4. Wait a little after refresh finishes
    Added settings
    upload_2020-11-8_14-29-46.png

    Original scripts (without Project Settings) below:
    1. Download scripts into project
    2. Open package manager and press refresh
    3. Wait a little after refresh finishes


    Showing hidden packages in package manager:

    Code (CSharp):
    1. using System;
    2. using System.Collections.Generic;
    3. using System.Linq;
    4. using System.Reflection;
    5. using UnityEditor;
    6. using UnityEditor.PackageManager;
    7. using UnityEditor.PackageManager.Requests;
    8. using UnityEditor.PackageManager.UI;
    9. using Object = UnityEngine.Object;
    10. using PackageInfo = UnityEditor.PackageManager.PackageInfo;
    11.  
    12. public static class DiscoverExtraPackages
    13. {
    14.     static string[] m_extraPackages = new string[]
    15.     {
    16.         "com.ptc.vuforia.engine",
    17.         "com.unity.2d.entities",
    18.         "com.unity.ai.planner",
    19.         "com.unity.aovrecorder",
    20.         "com.unity.assetbundlebrowser",
    21.         "com.unity.assetgraph",
    22.         "com.unity.barracuda",
    23.         "com.unity.barracuda.burst",
    24.         "com.unity.build-report-inspector",
    25.         "com.unity.cloud.userreporting",
    26.         "com.unity.collections",
    27.         "com.unity.connect.share",
    28.         "com.unity.dots.editor",
    29.         "com.unity.entities",
    30.         "com.unity.film-tv.toolbox",
    31.         "com.unity.google.resonance.audio",
    32.         "com.unity.immediate-window",
    33.         "com.unity.mathematics",
    34.         "com.unity.meshsync",
    35.         "com.unity.multiplayer-hlapi",
    36.         "com.unity.package-manager-doctools",
    37.         "com.unity.package-manager-ui",
    38.         "com.unity.package-validation-suite",
    39.         "com.unity.physics",
    40.         "com.unity.platforms",
    41.         "com.unity.platforms.android",
    42.         "com.unity.platforms.linux",
    43.         "com.unity.platforms.macos",
    44.         "com.unity.platforms.web",
    45.         "com.unity.platforms.windows",
    46.         "com.unity.playablegraph-visualizer",
    47.         "com.unity.render-pipelines.lightweight",
    48.         "com.unity.rendering.hybrid",
    49.         "com.unity.renderstreaming",
    50.         "com.unity.scene-template",
    51.         "com.unity.simulation.client",
    52.         "com.unity.simulation.core",
    53.         "com.unity.simulation.capture",
    54.         "com.unity.simulation.games",
    55.         "com.unity.standardevents",
    56.         "com.unity.streaming-image-sequence",
    57.         "com.unity.test-framework.performance",
    58.         "com.unity.tiny.all",
    59.         "com.unity.transport",
    60.         "com.unity.upm.develop",
    61.         "com.unity.vectorgraphics",
    62.         "com.unity.webrtc",
    63.         "com.unity.xr.googlevr.android",
    64.         "com.unity.xr.googlevr.ios",
    65.         "com.unity.xr.legacyinputhelpers",
    66.         "com.unity.xr.oculus.android",
    67.         "com.unity.xr.oculus.standalone",
    68.         "com.unity.xr.openvr.standalone",
    69.         "com.unity.xr.arsubsystems",
    70.         "com.unity.xr.interactionsubsystems",
    71.         "com.unity.xr.windowsmr.metro",
    72.     };
    73.  
    74.     static readonly Type m_cacheType = typeof(PackageManagerExtensions).Assembly.GetType("UnityEditor.PackageManager.UI.UpmCache");
    75.     static readonly Type m_cacheInterfaceType = typeof(PackageManagerExtensions).Assembly.GetType("UnityEditor.PackageManager.UI.IUpmCache");
    76.     static readonly PropertyInfo m_getPackageInfos = m_cacheType.GetProperty("searchPackageInfos") ?? m_cacheInterfaceType.GetProperty("searchPackageInfos");
    77.     static readonly MethodInfo m_setPackageInfos = m_cacheType.GetMethod("SetSearchPackageInfos") ?? m_cacheInterfaceType.GetMethod("SetSearchPackageInfos");
    78.     static readonly PropertyInfo m_operationInProgress = typeof(PackageManagerExtensions).Assembly.GetType("UnityEditor.PackageManager.UI.IOperation").GetProperty("isInProgress");
    79.     static readonly Type serviceContainerType = typeof(PackageManagerExtensions).Assembly.GetType("UnityEditor.PackageManager.UI.ServicesContainer");
    80.     static readonly Func<object> m_serviceContainerGetter = (Func<object>)serviceContainerType?.BaseType.GetProperty("instance", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static).GetGetMethod().CreateDelegate(typeof(Func<object>));
    81.     static readonly Func<object> m_upmCacheGetter = CreateUpmCacheGetter();
    82.  
    83.     static readonly EditorApplication.CallbackFunction m_callback = OnProgress;
    84.     static readonly List<SearchRequest> m_requests = new List<SearchRequest>(32);
    85.  
    86.     static object m_searchAllOperation;
    87.  
    88.     static Func<object> CreateUpmCacheGetter()
    89.     {
    90. #if UNITY_2020_2_OR_NEWER
    91.         return (Func<object>)serviceContainerType.GetMethod("Resolve").MakeGenericMethod(m_cacheType).CreateDelegate(typeof(Func<object>), m_serviceContainerGetter());
    92. #else
    93.         return (Func<object>)m_cacheType.GetProperty("instance").GetGetMethod().CreateDelegate(typeof(Func<object>));
    94. #endif
    95.     }
    96.  
    97.     [InitializeOnLoadMethod]
    98.     static void Init()
    99.     {
    100.         // Hook package manager SearchAll operation
    101.         var clientType = typeof(PackageManagerExtensions).Assembly.GetType("UnityEditor.PackageManager.UI.UpmClient");
    102. #if UNITY_2020_2_OR_NEWER
    103.         var instance = serviceContainerType.GetMethod("Resolve").MakeGenericMethod(clientType).Invoke(m_serviceContainerGetter(), null);
    104. #else
    105.         var instance = clientType.GetProperty("instance", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static).GetValue(null) as Object;
    106. #endif
    107.         var evnt = instance.GetType().GetEvent("onSearchAllOperation");
    108.         evnt.AddEventHandler(instance, Delegate.CreateDelegate(evnt.EventHandlerType, new Action<object>(OnSearchAll).Method));
    109.     }
    110.  
    111.     static void OnSearchAll(object operation)
    112.     {
    113.         m_searchAllOperation = operation;
    114.  
    115.         // Clear requests, in case any searches are running, they will finish without doing anything
    116.         m_requests.Clear();
    117.  
    118.         // Kick off searching
    119.         foreach (var id in m_extraPackages)
    120.         {
    121.             m_requests.Add(Client.Search(id));
    122.         }
    123.  
    124.         // Re-register update callback
    125.         EditorApplication.update -= m_callback;
    126.         EditorApplication.update += m_callback;
    127.     }
    128.  
    129.     private static void OnProgress()
    130.     {
    131.         // Wait for all requests to complete and for SearchAll opeartion to finish
    132.         if (m_requests.All(s => s.IsCompleted) && !(bool)m_operationInProgress.GetValue(m_searchAllOperation))
    133.         {
    134.             // Then add results
    135.             var cache = m_upmCacheGetter();
    136.             var packages = ((IEnumerable<PackageInfo>)m_getPackageInfos.GetValue(cache));
    137.             var everything = m_requests.Where(s => s.Status == StatusCode.Success).SelectMany(s => s.Result).Union(packages);
    138.             m_setPackageInfos.Invoke(cache, new object[] { everything });
    139.  
    140.             EditorApplication.update -= m_callback;
    141.             m_requests.Clear();
    142.             m_searchAllOperation = null;
    143.         }
    144.     }
    145. }
    146.  
    Disabling annoying warning on toolbar:
    Code (CSharp):
    1. using System;
    2. using System.Collections.Generic;
    3. using System.Linq;
    4. using System.Reflection;
    5. using UnityEditor;
    6. using UnityEditor.PackageManager.UI;
    7. using UnityEngine;
    8. using Object = UnityEngine.Object;
    9.  
    10. public static class DisablePreviewPackageWarning
    11. {
    12.     [InitializeOnLoadMethod]
    13.     static void Init()
    14.     {
    15.         var prefsType = typeof(PackageManagerExtensions).Assembly.GetType("UnityEditor.PackageManager.UI.PackageManagerPrefs");
    16.  
    17. #if UNITY_2020_2_OR_NEWER
    18.         var serviceContainerType = typeof(PackageManagerExtensions).Assembly.GetType("UnityEditor.PackageManager.UI.ServicesContainer");
    19.         var serviceContainer = serviceContainerType.BaseType.GetProperty("instance", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static).GetValue(null);
    20.         var prefsInstance = serviceContainerType.GetMethod("Resolve").MakeGenericMethod(prefsType).Invoke(serviceContainer, null);
    21. #else
    22.         var prefsInstance = prefsType.GetProperty("instance", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static).GetValue(null) as Object;
    23. #endif
    24.         var property = prefsInstance.GetType().GetProperty("dismissPreviewPackagesInUse", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
    25.         property.SetValue(prefsInstance, true);
    26.     }
    27. }
    28.  
     

    Attached Files:

    Last edited: Nov 15, 2020
    Elapotp, Neiist, Re0cto and 9 others like this.
  2. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,527
    Thank you!
     
    OndrejP and JBR-games like this.
  3. thylaxene

    thylaxene

    Joined:
    Oct 10, 2005
    Posts:
    716
    My god what is happening to Unity...

    Thanks BTW!
     
    OndrejP and JBR-games like this.
  4. MostHated

    MostHated

    Joined:
    Nov 29, 2015
    Posts:
    1,235
    It's honestly best. When Unity makes work that is still really early in development as easily available as it was to anyone who wants to get it, no matter how many flashy warning labels there are, or checkboxes you have to check saying "I UNDERSTAND THAT THIS S*** IS PROBABLY BROKEN BECAUSE IT'S NOT DONE YET!" most people bitch and complain when it doesn't work flawlessly, flood the forums with "Unitys broken, my game is ruined" type posts, and it is just a huge waste of everyone's time.

    It's better that the masses have to really go out of their way and know what they are doing and looking for to get the truly WIP packages, as those people are much more likely to understand the development process and provide actual constructive feedback.

    Transparency and open-source development can really be a double edged sword, and most people like to stab themselves in the face and blame the developer for leaving the sword in a reachable location.

    ----
    All that said, I was just about to write something somewhat similar to this, which is how I came across the Gist on Github when doing some research, so thanks for sharing it.
     
    Last edited: Nov 4, 2020
  5. OndrejP

    OndrejP

    Joined:
    Jul 19, 2017
    Posts:
    304
    JBR-games likes this.
  6. MNNoxMortem

    MNNoxMortem

    Joined:
    Sep 11, 2016
    Posts:
    723
    This is gold.
     
  7. lclemens

    lclemens

    Joined:
    Feb 15, 2020
    Posts:
    761
    Sweet!!! I've been using this package for a week and it has already saved me a bunch of time. You rock man!
     
    OndrejP likes this.
  8. Mark_29

    Mark_29

    Joined:
    Aug 11, 2014
    Posts:
    79
    I was looking for film and tv and AOV packages - found this thread. (I am not a coder)

    Seems as the ExtraSettingsProvider is not working in 2020.2.1?

    Could you please advise?
     
  9. lclemens

    lclemens

    Joined:
    Feb 15, 2020
    Posts:
    761
    Yeah, it stopped working for me too when I switched to 2020.2. I haven't found a fix.
     
  10. OndrejP

    OndrejP

    Joined:
    Jul 19, 2017
    Posts:
    304
    @Mark_J18 If you just grabbed the scripts from Git repo, you'll need to install Settings Manager package (from Unity).
    It's dependency.

    If you installed it through Add package from Git, it should have installed Settings Manager automatically, because it's dependency.

    upload_2021-1-1_17-29-13.png

    I've just tested it in Unity 2020.2.1f1 and it's working fine for me.

    upload_2021-1-1_17-31-53.png
     
  11. lclemens

    lclemens

    Joined:
    Feb 15, 2020
    Posts:
    761
    I have been installing via https://github.com/OndrejPetrzilka/package-manager-extra-settings.git . That was always the first thing I did when creating a new project or opening a repo that I cloned from git. It worked great for several months, and then once I updated to 2020.2, I wasn't able to get it working. However, I tried it just now on a blank new project, and it worked fine. So I'm not really sure why it wasn't working before, but I'm glad I can use it again!!!
     
    OndrejP likes this.
  12. OndrejP

    OndrejP

    Joined:
    Jul 19, 2017
    Posts:
    304
    I'm glad it works again, not sure why dependency was not resolved automatically. Anyone knows the reason?

    This is package.json:

    Code (JavaScript):
    1. {
    2.     "name": "package-manager-extra-settings",
    3.     "displayName": "Package Manager Extra Settings",
    4.     "version": "1.0.0",
    5.     "unity": "2019.3",
    6.     "unityRelease": "0f1",
    7.     "description": "Extra settings for Unity Package Manager (Project Settings/Package Manager/Extra Settings)\r\n - show hidden packages\r\n - disable warning on toolbar",
    8.     "dependencies": {
    9.         "com.unity.settings-manager": "1.0.3"
    10.     },
    11.     "keywords": [
    12.         "packages",
    13.         "package-manager",
    14.         "editor",
    15.         "unity",
    16.         "package"
    17.     ]
    18. }
     
  13. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,527
  14. OndrejP

    OndrejP

    Joined:
    Jul 19, 2017
    Posts:
    304
    Man, I need to update that again, what a pain o_O
    I wish Unity added native support for this...

    ...or at least some textfile where you could put list of packages and it would "show" them in PackageManager even when they're hidden
     
    Last edited: Sep 19, 2022
  15. Elapotp

    Elapotp

    Joined:
    May 14, 2014
    Posts:
    98
  16. Elapotp

    Elapotp

    Joined:
    May 14, 2014
    Posts:
    98
    Lars-Steenhoff likes this.
  17. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,527
    I'm looking for fixes to make it work in 2022, its giving an error, anyone have an idea?