OpenDialogueButton.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using UnityEditor;
  2. using UnityEngine;
  3. namespace SingularityGroup.HotReload.Editor {
  4. internal class OpenDialogueButton : IGUIComponent {
  5. public readonly string text;
  6. public readonly string url;
  7. public readonly string title;
  8. public readonly string message;
  9. public readonly string ok;
  10. public readonly string cancel;
  11. public OpenDialogueButton(string text, string url, string title, string message, string ok, string cancel) {
  12. this.text = text;
  13. this.url = url;
  14. this.title = title;
  15. this.message = message;
  16. this.ok = ok;
  17. this.cancel = cancel;
  18. }
  19. public void OnGUI() {
  20. Render(text, url, title, message, ok, cancel);
  21. }
  22. public static void Render(string text, string url, string title, string message, string ok, string cancel) {
  23. if (GUILayout.Button(new GUIContent(text.StartsWith(" ") ? text : " " + text))) {
  24. if (EditorUtility.DisplayDialog(title, message, ok, cancel)) {
  25. Application.OpenURL(url);
  26. }
  27. }
  28. }
  29. public static void RenderRaw(Rect rect, string text, string url, string title, string message, string ok, string cancel, GUIStyle style = null) {
  30. if (GUI.Button(rect, new GUIContent(text.StartsWith(" ") ? text : " " + text), style ?? GUI.skin.button)) {
  31. if (EditorUtility.DisplayDialog(title, message, ok, cancel)) {
  32. Application.OpenURL(url);
  33. }
  34. }
  35. }
  36. }
  37. }