LayoutOverlayUtility.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. using System;
  2. using UnityEditor.U2D.Animation;
  3. using UnityEngine;
  4. using UnityEngine.UIElements;
  5. namespace UnityEditor.U2D.Layout
  6. {
  7. internal static class LayoutOverlayUtility
  8. {
  9. public static Button CreateButton(string name, Action clickEvent, string tooltip = null, string text = null, string imageResourcePath = null, string stylesheetPath = null)
  10. {
  11. Button button = new Button(clickEvent);
  12. button.name = name;
  13. button.tooltip = tooltip;
  14. if (!String.IsNullOrEmpty(text))
  15. button.text = text;
  16. if (!String.IsNullOrEmpty(imageResourcePath))
  17. {
  18. var texture = ResourceLoader.Load<Texture>(imageResourcePath);
  19. if (texture != null)
  20. {
  21. Image image = new Image();
  22. image.image = texture;
  23. button.Add(image);
  24. }
  25. }
  26. if (!String.IsNullOrEmpty(stylesheetPath))
  27. button.styleSheets.Add(ResourceLoader.Load<StyleSheet>(stylesheetPath));
  28. return button;
  29. }
  30. }
  31. }