Search Unity

How do I programmatically interact with the PackageManager?

Discussion in 'Package Manager' started by jimmio92, Sep 7, 2018.

  1. jimmio92

    jimmio92

    Joined:
    Nov 3, 2009
    Posts:
    31
    Hello all,

    I'm basically making an editor script that trys to way-over-simplify the process of adding PostProcessing Stack v2 to a project and empty scene. Basically what I want to do, is ask the PackageManager if PostProcessing is installed. If it's not installed, tell it to install it, then once that has been confirmed completed, perform a task. I cannot for the life of me seem to figure out a good way to handle that. Should I be storing requests and polling to see if complete? Is there some built-in timer mechanism, maybe coroutines to wait for ListRequests and the like?

    Thanks,
    Jim
     
  2. DanielTG

    DanielTG

    Joined:
    Feb 15, 2018
    Posts:
    111
    Hi Jimmio92,

    These doc links should help give you a good baseline on how to interact with Package Manager outside of the UI

    https://docs.unity3d.com/ScriptReference/
    (check under UnityEditor > UnityEditor.PackageManager for the a list of the various API calls)

    or alternatively a bit higher level
    https://docs.unity3d.com/Packages/com.unity.package-manager-ui@1.8/manual/index.html

    Look for the Advanced Package topics to review how you manage the manifest.json (project side) to track which packages and version are installed. This doc was last update for the 2018.1 release and some changes were introduced in 2018.2 but the core concepts still apply.

    Hope this helps

    Thanks
    Daniel
     
  3. jimmio92

    jimmio92

    Joined:
    Nov 3, 2009
    Posts:
    31
    You provide a way to list the current packages as I read from the documentation, and you provide a way to add a package as I also gathered from the docs. I'm trying to figure out how to request the list, wait for it to be ready, then actually act on it. Should I be polling the status(es) in OnInspectorUpdate or is there a better mechanism with which to catch a list-results-ready-to-read event?
     
  4. jimmio92

    jimmio92

    Joined:
    Nov 3, 2009
    Posts:
    31
    I've got it working. I use OnInspectorUpdate to poll to see if IsCompleted is true or not. It's a mess of jumping back and forth, but it works so whatever. Thanks.