ProjectExporterUI.cs 2.9 KB

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