You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.7 KiB
55 lines
1.7 KiB
|
|
using System;
|
|
using UnityEditor.PackageManager;
|
|
using UnityEditor.PackageManager.UI;
|
|
using UnityEngine;
|
|
using UnityEngine.UIElements;
|
|
|
|
[UnityEditor.InitializeOnLoad]
|
|
internal class SamplesLinkPackageManagerExtension : IPackageManagerExtension
|
|
{
|
|
VisualElement rootVisualElement;
|
|
const string SAMPLEBUTTON_TEXT = "open VFX Graph Samples project on Github";
|
|
const string GITHUB_URL = "https://github.com/Unity-Technologies/VisualEffectGraph-Samples";
|
|
const string VFX_GRAPH_NAME = "com.unity.visualeffectgraph";
|
|
|
|
private Button samplesButton;
|
|
private VisualElement parent;
|
|
|
|
public VisualElement CreateExtensionUI()
|
|
{
|
|
samplesButton = new Button();
|
|
samplesButton.text = SAMPLEBUTTON_TEXT;
|
|
samplesButton.clickable.clicked += () => Application.OpenURL(GITHUB_URL);
|
|
return samplesButton;
|
|
}
|
|
|
|
static SamplesLinkPackageManagerExtension()
|
|
{
|
|
PackageManagerExtensions.RegisterExtension(new SamplesLinkPackageManagerExtension());
|
|
}
|
|
|
|
void IPackageManagerExtension.OnPackageSelectionChange(PackageInfo packageInfo)
|
|
{
|
|
if (samplesButton == null)
|
|
return;
|
|
|
|
// Prevent the button from rendering on other packages
|
|
if (samplesButton.parent != null)
|
|
parent = samplesButton.parent;
|
|
|
|
bool shouldRender = packageInfo?.name == VFX_GRAPH_NAME;
|
|
if (!shouldRender)
|
|
{
|
|
samplesButton.RemoveFromHierarchy();
|
|
}
|
|
else
|
|
{
|
|
parent.Add(samplesButton);
|
|
}
|
|
}
|
|
|
|
void IPackageManagerExtension.OnPackageAddedOrUpdated(PackageInfo packageInfo) { }
|
|
|
|
void IPackageManagerExtension.OnPackageRemoved(PackageInfo packageInfo) { }
|
|
}
|