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.

TilePaletteCreateTargetsDropdownMenu.cs 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using System;
  2. using UnityEngine;
  3. using UnityEngine.UIElements;
  4. namespace UnityEditor.Tilemaps
  5. {
  6. internal class TilePaletteCreateTargetsDropdownMenu : IGenericMenu
  7. {
  8. private const float k_DropdownWidth = 156f;
  9. private GridPaintCreateTargetsDropdown m_Dropdown;
  10. private Action m_OnClose;
  11. private bool m_HasTilePalette;
  12. public TilePaletteCreateTargetsDropdownMenu(Action onClose)
  13. {
  14. m_HasTilePalette = GridPaintingState.palette != null;
  15. var index = -1;
  16. var menuData = new GridPaintCreateTargetsDropdown.MenuItemProvider(m_HasTilePalette);
  17. m_Dropdown = new GridPaintCreateTargetsDropdown(menuData, index, null, CreateTilemapTarget, k_DropdownWidth);
  18. m_OnClose = onClose;
  19. }
  20. public void AddItem(string itemName, bool isChecked, System.Action action)
  21. {
  22. }
  23. public void AddItem(string itemName, bool isChecked, System.Action<object> action, object data)
  24. {
  25. }
  26. public void AddDisabledItem(string itemName, bool isChecked)
  27. {
  28. }
  29. public void AddSeparator(string path)
  30. {
  31. }
  32. public void DropDown(Rect position, VisualElement targetElement = null, bool anchored = false)
  33. {
  34. PopupWindow.Show(position, m_Dropdown, null, ShowMode.PopupMenu);
  35. }
  36. public void Close()
  37. {
  38. PopupWindow.Show(default, m_Dropdown, null, ShowMode.PopupMenu);
  39. }
  40. private void CreateTilemapTarget(int i, object o)
  41. {
  42. m_Dropdown.editorWindow.Close();
  43. if (!m_HasTilePalette)
  44. i += 1;
  45. GameObjectCreation.CreateTilemapTargets(i);
  46. m_OnClose?.Invoke();
  47. GUIUtility.ExitGUI();
  48. }
  49. }
  50. }