QuestionDialog.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #if ENABLE_MONO && (DEVELOPMENT_BUILD || UNITY_EDITOR)
  2. using System;
  3. using System.Threading.Tasks;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. namespace SingularityGroup.HotReload {
  7. class QuestionDialog : MonoBehaviour {
  8. [Header("Information")]
  9. public Text textSummary;
  10. public Text textSuggestion;
  11. [Header("UI controls")]
  12. public Button buttonContinue;
  13. public Button buttonCancel;
  14. public Button buttonMoreInfo;
  15. public TaskCompletionSource<bool> completion = new TaskCompletionSource<bool>();
  16. public void UpdateView(Config config) {
  17. textSummary.text = config.summary;
  18. textSuggestion.text = config.suggestion;
  19. if (string.IsNullOrEmpty(config.continueButtonText)) {
  20. buttonContinue.enabled = false;
  21. } else {
  22. buttonContinue.GetComponentInChildren<Text>().text = config.continueButtonText;
  23. buttonContinue.onClick.AddListener(() => {
  24. completion.TrySetResult(true);
  25. Hide();
  26. });
  27. }
  28. if (string.IsNullOrEmpty(config.cancelButtonText)) {
  29. buttonCancel.enabled = false;
  30. } else {
  31. buttonCancel.GetComponentInChildren<Text>().text = config.cancelButtonText;
  32. buttonCancel.onClick.AddListener(() => {
  33. completion.TrySetResult(false);
  34. Hide();
  35. });
  36. }
  37. buttonMoreInfo.onClick.AddListener(() => {
  38. Application.OpenURL(config.moreInfoUrl);
  39. });
  40. }
  41. internal class Config {
  42. public string summary;
  43. public string suggestion;
  44. public string continueButtonText = "Continue";
  45. public string cancelButtonText = "Cancel";
  46. public string moreInfoUrl = "https://hotreload.net/documentation#handling-different-commits";
  47. }
  48. /// hide this dialog
  49. void Hide() {
  50. gameObject.SetActive(false); // this should disable the Update loop?
  51. }
  52. }
  53. }
  54. #endif