com.alicizax.unity.packagem.../Editor/PackageManager/Window/PackageBottomStateBar.cs

88 lines
2.6 KiB
C#

using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;
namespace AlicizaX.PackageManager.Editor
{
internal class PackageBottomStateBar : VisualElement
{
private readonly FrameworkPackageManagerWindow window;
private readonly Button refreshButton;
private readonly Button updateAllButton;
private readonly VisualElement spacer;
public PackageBottomStateBar(FrameworkPackageManagerWindow window)
{
this.window = window;
style.flexDirection = FlexDirection.Row;
style.flexShrink = 1;
style.justifyContent = Justify.FlexEnd;
style.alignItems = Align.Center;
style.height = Length.Percent(5);
style.backgroundColor = new Color(0.2509804f, 0.2509804f, 0.2509804f);
style.borderTopWidth = 1;
style.paddingLeft = 4;
style.paddingRight = 4;
spacer = new VisualElement();
spacer.style.flexGrow = 1;
Add(spacer);
refreshButton = CreateIconButton("btnRefresh", "d_Refresh", "Refresh", OnRefreshClicked);
Add(refreshButton);
updateAllButton = CreateIconButton("btnUpdateAll", "Update-Available", "Update All", OnUpdateAllClicked);
updateAllButton.style.marginLeft = 6;
Add(updateAllButton);
}
public void SetStateText(string text)
{
}
private static Button CreateIconButton(string name, string iconName, string tooltip, System.Action clickAction)
{
var button = new Button(clickAction)
{
name = name,
tooltip = tooltip
};
button.style.width = 26;
button.style.height = 22;
button.style.paddingLeft = 0;
button.style.paddingRight = 0;
button.style.paddingTop = 2;
button.style.paddingBottom = 0;
button.style.unityTextAlign = TextAnchor.MiddleCenter;
var icon = new Image
{
image = EditorGUIUtility.IconContent(iconName).image
};
icon.style.width = 16;
icon.style.height = 16;
icon.style.alignSelf = Align.Center;
button.Add(icon);
return button;
}
private void OnRefreshClicked()
{
if (window.IsBusy())
{
return;
}
window.Refresh();
}
private void OnUpdateAllClicked()
{
UpdateAllPackageHelper.UpdatePackages(window);
}
}
}