Bubble.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using UnityEngine.Events;
  4. using System.Collections;
  5. public class Bubble : Regist
  6. {
  7. #region 变量
  8. public static Text Tit;
  9. public static Text Lab;
  10. public static Text NotifyLab;
  11. public static Image Icon;
  12. public static Button Cancel;
  13. public static Button Confirm;
  14. public static Transform Box;
  15. public static Transform Background;
  16. #endregion
  17. public override bool InitAtOnce()
  18. {
  19. if (base.InitAtOnce())
  20. {
  21. return true;
  22. }
  23. Box = ResourceManager.Get(CanvasLabel.K_Bubble0);
  24. Background = ResourceManager.Get(CanvasLabel.K_Bubble);
  25. Tit = ResourceManager.Get<Text>(CanvasLabel.K_Tit);
  26. Lab = ResourceManager.Get<Text>(CanvasLabel.K_Lab);
  27. NotifyLab = ResourceManager.Get<Text>(CanvasLabel.K_NotifyLab);
  28. Icon = ResourceManager.Get<Image>(CanvasLabel.K_Icon);
  29. Cancel = ResourceManager.Get<Button>(CanvasLabel.K_Cancel);
  30. Confirm = ResourceManager.Get<Button>(CanvasLabel.K_Confirm);
  31. Box.CreateTweenScale(Vector3.zero, Vector3.one, 0.25f, false, true, Curve.EaseOutQuad);
  32. Background.CreateTweenGra(0, 180 / 255f, 0.25f, false, true, Curve.EaseOutQuad, true);
  33. return false;
  34. }
  35. public static void Show(string tit = null, string lab = null, string notifyLab = null, Sprite sprite = null, UnityAction confirmAction = null, UnityAction cancelAction = null, bool enableCancle = true)
  36. {
  37. AudioManager.PlayClip(AudioLabel.Bubble);
  38. Box.TweenForScale();
  39. Background.TweenForGra();
  40. if (string.IsNullOrEmpty(tit))
  41. {
  42. Tit.SetActive(false);
  43. }
  44. else
  45. {
  46. Tit.SetActive(true);
  47. Tit.text = tit;
  48. }
  49. if (string.IsNullOrEmpty(lab))
  50. {
  51. Lab.SetActive(false);
  52. }
  53. else
  54. {
  55. Lab.SetActive(true);
  56. Lab.text = lab;
  57. }
  58. if (string.IsNullOrEmpty(notifyLab))
  59. {
  60. NotifyLab.SetActive(false);
  61. }
  62. else
  63. {
  64. NotifyLab.SetActive(true);
  65. NotifyLab.text = notifyLab;
  66. }
  67. if (sprite == null)
  68. {
  69. Icon.SetActive(false);
  70. }
  71. else
  72. {
  73. Icon.SetActive(true);
  74. Icon.sprite = sprite;
  75. }
  76. if (cancelAction == null && confirmAction == null)
  77. {
  78. Cancel.SetActive(false);
  79. Confirm.SetButtonEvent(Close);
  80. }
  81. else
  82. {
  83. Cancel.SetActive(true);
  84. Cancel.SetButtonEvent(Close);
  85. Cancel.AddButtonEvent
  86. (
  87. () =>
  88. {
  89. AudioManager.PlayClip(AudioLabel.ClickButton);
  90. }
  91. );
  92. if (cancelAction != null)
  93. {
  94. Cancel.AddButtonEvent(cancelAction);
  95. }
  96. else
  97. {
  98. if (!enableCancle)
  99. {
  100. Cancel.SetActive(false);
  101. }
  102. }
  103. Confirm.SetButtonEvent(Close);
  104. Confirm.AddButtonEvent(confirmAction);
  105. Confirm.AddButtonEvent
  106. (
  107. () =>
  108. {
  109. AudioManager.PlayClip(AudioLabel.ClickButton);
  110. }
  111. );
  112. }
  113. }
  114. public static void Close()
  115. {
  116. Box.TweenBacScale();
  117. Background.TweenBacGra();
  118. AudioManager.PlayClip(AudioLabel.Close);
  119. }
  120. }