Skip to content

Instantly share code, notes, and snippets.

@LotteMakesStuff
Last active July 23, 2024 03:25
Show Gist options
  • Save LotteMakesStuff/2247e8a7743a1ceb52331f8e2f5531f7 to your computer and use it in GitHub Desktop.
Save LotteMakesStuff/2247e8a7743a1ceb52331f8e2f5531f7 to your computer and use it in GitHub Desktop.

Revisions

  1. LotteMakesStuff revised this gist Apr 1, 2018. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions z_self_promotion_sorry.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    Always thankful for your support,
    Lotte💖

    <a href='https://ko-fi.com/A08215TT' target='_blank'><img height='46' style='border:0px;height:46px;' src='https://az743702.vo.msecnd.net/cdn/kofi3.png?v=0' border='0' alt='Buy Me a Coffee at ko-fi.com' /></a> <a href='https://www.patreon.com/bePatron?u=7061709' target='_blank'><img height='46' style='border:0px;height:46px;' src='https://c5.patreon.com/external/logo/[email protected]' border='0' alt='Become a Patron!' /></a>
  2. LotteMakesStuff created this gist Apr 1, 2018.
    105 changes: 105 additions & 0 deletions PackageManagerExtentionExample.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,105 @@
    using System.Linq;
    using UnityEditor;
    using UnityEditor.PackageManager.UI;
    using UnityEngine;
    using UnityEngine.Experimental.UIElements;
    using UnityEngine.Experimental.UIElements.StyleEnums;
    using PackageInfo = UnityEditor.PackageManager.PackageInfo;

    [InitializeOnLoad]
    public class PackageManagerExtentionExample : IPackageManagerExtension
    {
    // This class implments the new IPackageManagerExtension interface, allowing us to plug it
    // into the package manager window. this feature is still very much under development

    static PackageManagerExtentionExample()
    {
    Debug.Log("CALLED STATIC CTOR");

    // This static constructor gets called becuase we have the InitializeOnLoad attribute
    // on our class. Here we register this PackageManager extention so our exta version list
    // shows up in the manager window
    PackageManagerExtensions.RegisterExtension(new PackageManagerExtentionExample());
    }

    // this is the scrollview were going to put the version list into
    ScrollView tasksContainer;

    public VisualElement CreateExtensionUI()
    {
    Debug.Log("CALLED CreateExtensionUI");

    VisualContainer root = new VisualContainer()
    {
    style =
    {
    backgroundColor = Color.grey,
    alignSelf = Align.FlexStart,
    flexDirection = FlexDirection.Row
    }
    };

    tasksContainer = new ScrollView()
    {
    style =
    {
    width = 400,
    height = 100,
    flexDirection = FlexDirection.Column,
    }
    };
    tasksContainer.showHorizontal = false;
    root.Add(tasksContainer);

    return root;
    }

    public void OnPackageSelectionChange(PackageInfo packageInfo)
    {
    // setup the version list for the currently selected package
    Debug.Log("CALLED OnPackageSelectionChange");

    tasksContainer.contentContainer.Clear();

    foreach (var version in packageInfo.versions.all.Reverse())
    {
    tasksContainer.contentContainer.Add(NewVersion(version, packageInfo));
    }
    }

    private VisualElement NewVersion(string version, PackageInfo packageInfo)
    {
    // create a list item for the passed in version
    var versionElement = new VisualContainer()
    {
    style =
    {
    width = 400,
    flexDirection = FlexDirection.Row
    }
    };
    versionElement.name = version;

    // fist, lets put in the version name
    versionElement.Add(new Label(version));

    // annnd now a bunch of interesting info
    versionElement.Add(new Toggle(null){text = "Recomended", on = (packageInfo.versions.recommended == version)});
    versionElement.Add(new Toggle(null){text = "Compatible", on = (packageInfo.versions.compatible.Contains(version))});
    versionElement.Add(new Toggle(null){text = "Latest Compatible", on = (packageInfo.versions.latestCompatible == version)});

    Debug.Log("ADDED " + version);

    return versionElement;
    }

    public void OnPackageAddedOrUpdated(PackageInfo packageInfo)
    {
    Debug.Log("CALLED OnPackageAddedOrUpdated");
    }

    public void OnPackageRemoved(PackageInfo packageInfo)
    {
    Debug.Log("CALLED OnPackageRemoved");
    }
    }