Nessuna descrizione
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.

TilePaletteActivePaletteDropdownMenu.cs 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using UnityEngine;
  2. using UnityEngine.UIElements;
  3. namespace UnityEditor.Tilemaps
  4. {
  5. internal class TilePaletteActivePaletteDropdownMenu : IGenericMenu
  6. {
  7. private const float k_DropdownWidth = 150f;
  8. private GridPalettesDropdown m_Dropdown;
  9. public TilePaletteActivePaletteDropdownMenu()
  10. {
  11. int index = GridPaintingState.palettes != null ? GridPaintingState.palettes.IndexOf(GridPaintingState.palette) : 0;
  12. var menuData = new GridPalettesDropdown.MenuItemProvider();
  13. m_Dropdown = new GridPalettesDropdown(menuData, index, null, SelectPalette, k_DropdownWidth);
  14. }
  15. public void AddItem(string itemName, bool isChecked, System.Action action)
  16. {
  17. }
  18. public void AddItem(string itemName, bool isChecked, System.Action<object> action, object data)
  19. {
  20. }
  21. public void AddDisabledItem(string itemName, bool isChecked)
  22. {
  23. }
  24. public void AddSeparator(string path)
  25. {
  26. }
  27. public void DropDown(Rect position, VisualElement targetElement = null, bool anchored = false)
  28. {
  29. PopupWindow.Show(position, m_Dropdown);
  30. }
  31. private void SelectPalette(int i, object o)
  32. {
  33. if (i < GridPaintingState.palettes.Count)
  34. {
  35. GridPaintingState.palette = GridPaintingState.palettes[i];
  36. }
  37. else
  38. {
  39. m_Dropdown.editorWindow.Close();
  40. OpenAddPalettePopup(new Rect(0, 0, 0, 0));
  41. }
  42. }
  43. private void OpenAddPalettePopup(Rect rect)
  44. {
  45. bool popupOpened = GridPaletteAddPopup.ShowAtPosition(rect);
  46. if (popupOpened)
  47. GUIUtility.ExitGUI();
  48. }
  49. }
  50. }