暂无描述
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

TilePaletteActivePaletteDropdownMenu.cs 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. using UnityEngine;
  2. using UnityEngine.UIElements;
  3. namespace UnityEditor.Tilemaps
  4. {
  5. internal class TilePaletteActivePaletteDropdownMenu : IGenericMenu
  6. {
  7. private const float k_DropdownWidth = 156f;
  8. private GridPalettesDropdown m_Dropdown;
  9. private TilePaletteWhiteboxPaletteDropdownMenu m_Menu;
  10. public TilePaletteActivePaletteDropdownMenu()
  11. {
  12. int index = GridPaintingState.palettes != null ? GridPaintingState.palettes.IndexOf(GridPaintingState.palette) : 0;
  13. var menuData = new GridPalettesDropdown.MenuItemProvider();
  14. m_Dropdown = new GridPalettesDropdown(menuData, index, null, SelectPalette, HoverPalette, k_DropdownWidth);
  15. }
  16. private void HoverPalette(int index, Rect itemRect)
  17. {
  18. if (index <= GridPalettes.palettes.Count )
  19. {
  20. if (m_Menu != null)
  21. {
  22. m_Menu.Close();
  23. m_Menu = null;
  24. }
  25. return;
  26. }
  27. if (!GridPaletteWhiteboxPalettesDropdown.IsOpen)
  28. {
  29. m_Menu = new TilePaletteWhiteboxPaletteDropdownMenu(OnClose);
  30. var popupRect = itemRect;
  31. popupRect.x += itemRect.width;
  32. popupRect.y -= itemRect.height;
  33. m_Menu.DropDown(popupRect);
  34. }
  35. }
  36. private void OnClose()
  37. {
  38. m_Dropdown.editorWindow.Close();
  39. }
  40. public void AddItem(string itemName, bool isChecked, System.Action action)
  41. {
  42. }
  43. public void AddItem(string itemName, bool isChecked, System.Action<object> action, object data)
  44. {
  45. }
  46. public void AddDisabledItem(string itemName, bool isChecked)
  47. {
  48. }
  49. public void AddSeparator(string path)
  50. {
  51. }
  52. public void DropDown(Rect position, VisualElement targetElement = null, bool anchored = false)
  53. {
  54. PopupWindow.Show(position, m_Dropdown);
  55. }
  56. private void SelectPalette(int i, object o)
  57. {
  58. if (i < GridPaintingState.palettes.Count)
  59. {
  60. GridPaintingState.palette = GridPaintingState.palettes[i];
  61. }
  62. else if (i == GridPaintingState.palettes.Count)
  63. {
  64. m_Dropdown.editorWindow.Close();
  65. OpenAddPalettePopup(new Rect());
  66. }
  67. }
  68. private void OpenAddPalettePopup(Rect rect)
  69. {
  70. bool popupOpened = GridPaletteAddPopup.ShowAtPosition(rect);
  71. if (popupOpened)
  72. GUIUtility.ExitGUI();
  73. }
  74. }
  75. }