wuxianshengcong/Library/PackageCache/com.unity.2d.tilemap@1.0.0/Editor/UI/TilePaletteActivePaletteDropdownMenu.cs

61 lines
1.8 KiB
C#
Raw Normal View History

2025-01-02 14:49:00 +08:00
using UnityEngine;
using UnityEngine.UIElements;
namespace UnityEditor.Tilemaps
{
internal class TilePaletteActivePaletteDropdownMenu : IGenericMenu
{
private const float k_DropdownWidth = 150f;
private GridPalettesDropdown m_Dropdown;
public TilePaletteActivePaletteDropdownMenu()
{
int index = GridPaintingState.palettes != null ? GridPaintingState.palettes.IndexOf(GridPaintingState.palette) : 0;
var menuData = new GridPalettesDropdown.MenuItemProvider();
m_Dropdown = new GridPalettesDropdown(menuData, index, null, SelectPalette, k_DropdownWidth);
}
public void AddItem(string itemName, bool isChecked, System.Action action)
{
}
public void AddItem(string itemName, bool isChecked, System.Action<object> action, object data)
{
}
public void AddDisabledItem(string itemName, bool isChecked)
{
}
public void AddSeparator(string path)
{
}
public void DropDown(Rect position, VisualElement targetElement = null, bool anchored = false)
{
PopupWindow.Show(position, m_Dropdown);
}
private void SelectPalette(int i, object o)
{
if (i < GridPaintingState.palettes.Count)
{
GridPaintingState.palette = GridPaintingState.palettes[i];
}
else
{
m_Dropdown.editorWindow.Close();
OpenAddPalettePopup(new Rect(0, 0, 0, 0));
}
}
private void OpenAddPalettePopup(Rect rect)
{
bool popupOpened = GridPaletteAddPopup.ShowAtPosition(rect);
if (popupOpened)
GUIUtility.ExitGUI();
}
}
}