暫無描述
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.

IMGUIContainerPopupAdapter.cs 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using System;
  2. using UnityEngine;
  3. using UnityEngine.UIElements;
  4. namespace UnityEditor.Purchasing
  5. {
  6. class IMGUIContainerPopupAdapter
  7. {
  8. public int index;
  9. public string[] options;
  10. public Action<string> popupValueChangedAction { get; set; }
  11. public IMGUIContainer container
  12. {
  13. get => m_Container;
  14. set
  15. {
  16. m_Container = value;
  17. if (m_Container != null)
  18. {
  19. m_Container.onGUIHandler = OnGUI;
  20. }
  21. }
  22. }
  23. Rect m_Position;
  24. IMGUIContainer m_Container;
  25. void OnGUI()
  26. {
  27. Layout();
  28. var choice = DrawPopup();
  29. HandleChoice(choice);
  30. }
  31. void Layout()
  32. {
  33. if (m_Position.width == 0 || m_Position.height == 0)
  34. {
  35. m_Position = new Rect(0, 0, m_Container.resolvedStyle.width, m_Container
  36. .resolvedStyle.height);
  37. }
  38. }
  39. int DrawPopup()
  40. {
  41. return EditorGUI.Popup(
  42. m_Position,
  43. index,
  44. options);
  45. }
  46. void HandleChoice(int choice)
  47. {
  48. if (choice != index)
  49. {
  50. index = choice;
  51. popupValueChangedAction(options[index]);
  52. }
  53. }
  54. }
  55. }