No Description
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.

TilePaletteWhiteboxPaletteDropdownMenu.cs 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using System;
  2. using UnityEngine;
  3. using UnityEngine.UIElements;
  4. namespace UnityEditor.Tilemaps
  5. {
  6. internal class TilePaletteWhiteboxPaletteDropdownMenu : IGenericMenu
  7. {
  8. private const float k_DropdownWidth = 156f;
  9. private GridPaletteWhiteboxPalettesDropdown m_Dropdown;
  10. private Action m_OnClose;
  11. public TilePaletteWhiteboxPaletteDropdownMenu(Action onClose)
  12. {
  13. int index = -1;
  14. var menuData = new GridPaletteWhiteboxPalettesDropdown.MenuItemProvider();
  15. m_Dropdown = new GridPaletteWhiteboxPalettesDropdown(menuData, index, null, SelectWhiteboxPalette, k_DropdownWidth);
  16. m_OnClose = onClose;
  17. }
  18. public void AddItem(string itemName, bool isChecked, System.Action action)
  19. {
  20. }
  21. public void AddItem(string itemName, bool isChecked, System.Action<object> action, object data)
  22. {
  23. }
  24. public void AddDisabledItem(string itemName, bool isChecked)
  25. {
  26. }
  27. public void AddSeparator(string path)
  28. {
  29. }
  30. public void DropDown(Rect position, VisualElement targetElement = null, bool anchored = false)
  31. {
  32. PopupWindow.Show(position, m_Dropdown, null, ShowMode.PopupMenu);
  33. }
  34. public void Close()
  35. {
  36. PopupWindow.Show(default, m_Dropdown, null, ShowMode.PopupMenu);
  37. }
  38. private void SelectWhiteboxPalette(int i, object o)
  39. {
  40. m_Dropdown.editorWindow.Close();
  41. m_OnClose?.Invoke();
  42. var paletteCount = GridPalettes.palettes.Count;
  43. TilePaletteWhiteboxSamplesUtility.DuplicateWhiteboxSample(i);
  44. if (paletteCount > 0 && GridPaintPaletteClipboard.instances is { Count: > 0 })
  45. {
  46. var clipboard = GridPaintPaletteClipboard.instances[0];
  47. clipboard.PickFirstFromPalette();
  48. }
  49. }
  50. }
  51. }