DropdownMenu.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using UnityEngine;
  2. using UnityEngine.UIElements;
  3. namespace UnityEditor.U2D.Layout
  4. {
  5. internal class DropdownMenu : VisualElement
  6. {
  7. public class DropdownMenuFactory : UxmlFactory<DropdownMenu, DropdownMenuUxmlTraits> {}
  8. public class DropdownMenuUxmlTraits : UxmlTraits {}
  9. /*
  10. private ButtonGroup m_ButtonGroup;
  11. public DropdownMenu()
  12. {
  13. RegisterCallback<FocusOutEvent>(OnFocusOut, Capture.NoCapture);
  14. RegisterCallback<MouseLeaveEvent>(OnMouseLeaveEvent);
  15. }
  16. public void InitialiseWithButtonGroup(ButtonGroup buttonGroup)
  17. {
  18. if (m_ButtonGroup == buttonGroup)
  19. return;
  20. m_ButtonGroup = buttonGroup;
  21. var buttonGroupLocalPosition = parent.WorldToLocal(new Vector2(buttonGroup.worldBound.x, buttonGroup.worldBound.y));
  22. style.positionType = PositionType.Absolute;
  23. style.positionLeft = buttonGroupLocalPosition.x;
  24. style.positionTop = buttonGroupLocalPosition.y;
  25. style.flexDirection = buttonGroup.isHorizontal ? FlexDirection.Row : FlexDirection.Column;
  26. foreach (var element in buttonGroup.elements)
  27. Add(element);
  28. }
  29. private void OnMouseLeaveEvent(MouseLeaveEvent evt)
  30. {
  31. Close();
  32. }
  33. private void OnFocusOut(FocusOutEvent evt)
  34. {
  35. Close();
  36. }
  37. private void Close()
  38. {
  39. foreach (var element in contentContainer.Children())
  40. m_ButtonGroup.elements.Add(element);
  41. this.contentContainer.Clear();
  42. style.width = 0;
  43. style.height = 0;
  44. m_ButtonGroup = null;
  45. }
  46. */
  47. }
  48. }