ProjectExporterUI.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. using UnityEditor;
  2. using UnityEngine;
  3. using UnityEngine.UIElements;
  4. namespace ProjectExporter
  5. {
  6. // This class provides static methods to create styled visual elements for the editor window.
  7. public static class ProjectExporterUI
  8. {
  9. // Creates a main container for a tab's content.
  10. public static VisualElement CreateMainContainer()
  11. {
  12. return new VisualElement
  13. {
  14. style =
  15. {
  16. paddingLeft = 10,
  17. paddingRight = 10,
  18. paddingTop = 10,
  19. paddingBottom = 10
  20. }
  21. };
  22. }
  23. // Creates a tab button.
  24. public static Button CreateTab(string label)
  25. {
  26. var button = new Button
  27. {
  28. text = label,
  29. style =
  30. {
  31. flexGrow = 1,
  32. borderBottomWidth = 1,
  33. borderBottomColor = Color.gray,
  34. marginLeft = 0,
  35. marginRight = 0
  36. }
  37. };
  38. return button;
  39. }
  40. // Creates a Foldout element for hierarchical display.
  41. public static Foldout CreateFoldout(string text)
  42. {
  43. var foldout = new Foldout
  44. {
  45. text = text,
  46. value = false, // Start collapsed
  47. style =
  48. {
  49. marginTop = 5
  50. }
  51. };
  52. return foldout;
  53. }
  54. // Creates a Toggle for selecting an asset.
  55. public static Toggle CreateToggle(string label)
  56. {
  57. var toggle = new Toggle
  58. {
  59. text = label,
  60. style =
  61. {
  62. marginTop = 2
  63. }
  64. };
  65. return toggle;
  66. }
  67. // Overload for creating a Toggle with an initial value and a callback.
  68. public static Toggle CreateToggle(string label, bool value, System.Action<ChangeEvent<bool>> callback)
  69. {
  70. var toggle = new Toggle(label)
  71. {
  72. value = value,
  73. style =
  74. {
  75. marginTop = 2
  76. }
  77. };
  78. toggle.RegisterValueChangedCallback(evt => callback(evt));
  79. return toggle;
  80. }
  81. // Creates the "Generate" button.
  82. public static Button CreateGenerateButton(bool showGenerateAll = false)
  83. {
  84. var button = new Button
  85. {
  86. text = showGenerateAll ? "Generate All" : "Generate",
  87. style =
  88. {
  89. height = 30,
  90. marginTop = 20,
  91. backgroundColor = new StyleColor(new Color(0.2f, 0.6f, 0.2f))
  92. }
  93. };
  94. return button;
  95. }
  96. }
  97. }