OpenURLButton.cs 931 B

1234567891011121314151617181920212223242526272829
  1. using UnityEditor;
  2. using UnityEngine;
  3. namespace SingularityGroup.HotReload.Editor {
  4. internal class OpenURLButton : IGUIComponent {
  5. public readonly string text;
  6. public readonly string url;
  7. public OpenURLButton(string text, string url) {
  8. this.text = text;
  9. this.url = url;
  10. }
  11. public void OnGUI() {
  12. Render(text, url);
  13. }
  14. public static void Render(string text, string url) {
  15. if (GUILayout.Button(new GUIContent(text.StartsWith(" ") ? text : " " + text))) {
  16. Application.OpenURL(url);
  17. }
  18. }
  19. public static void RenderRaw(Rect rect, string text, string url, GUIStyle style = null) {
  20. if (GUI.Button(rect, new GUIContent(text.StartsWith(" ") ? text : " " + text), style ?? GUI.skin.button)) {
  21. Application.OpenURL(url);
  22. }
  23. }
  24. }
  25. }