Bubble.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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 Lab1;
  11. public static Text Lab2;
  12. public static Text NotifyLab;
  13. public static Image Icon;
  14. public static Button Cancel;
  15. public static Button Confirm;
  16. public static Button LinkButton;
  17. public static Transform Box;
  18. public static Transform Background;
  19. #endregion
  20. public override bool InitAtOnce()
  21. {
  22. if (base.InitAtOnce())
  23. {
  24. return true;
  25. }
  26. Box = ResourceManager.Get(CanvasLabel.K_Bubble0);
  27. Background = ResourceManager.Get(CanvasLabel.K_Bubble);
  28. Tit = ResourceManager.Get<Text>(CanvasLabel.K_Tit);
  29. Lab = ResourceManager.Get<Text>(CanvasLabel.K_Lab);
  30. Lab1 = ResourceManager.Get<Text>(CanvasLabel.K_Lab1);
  31. Lab2 = ResourceManager.Get<Text>(CanvasLabel.K_Lab2);
  32. NotifyLab = ResourceManager.Get<Text>(CanvasLabel.K_NotifyLab);
  33. Icon = ResourceManager.Get<Image>(CanvasLabel.K_Icon);
  34. Cancel = ResourceManager.Get<Button>(CanvasLabel.K_Cancel);
  35. Confirm = ResourceManager.Get<Button>(CanvasLabel.K_Confirm);
  36. LinkButton = ResourceManager.Get<Button>(CanvasLabel.K_LinkButton);
  37. Box.CreateTweenScale(Vector3.zero, Vector3.one, 0.25f, false, true, Curve.EaseOutQuad);
  38. Background.CreateTweenGra(0, 180 / 255f, 0.25f, false, true, Curve.EaseOutQuad, true);
  39. return false;
  40. }
  41. public override void FirstInit()
  42. {
  43. LanguageManager.Add(ResourceManager.Get<Text>(CanvasLabel.K_CancelLab), new MulLanStr(LanguageLabel.Common__Cancel));
  44. LanguageManager.Add(ResourceManager.Get<Text>(CanvasLabel.K_ConfirmLab), new MulLanStr(LanguageLabel.Common__Confirm));
  45. }
  46. 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)
  47. {
  48. Lab1.SetActive(false);
  49. Lab2.SetActive(false);
  50. LinkButton.SetActive(false);
  51. AudioManager.PlayClip(AudioLabel.Bubble);
  52. Box.TweenForScale();
  53. Background.TweenForGra();
  54. if (string.IsNullOrEmpty(tit))
  55. {
  56. Tit.SetActive(false);
  57. }
  58. else
  59. {
  60. Tit.SetActive(true);
  61. Tit.text = tit;
  62. }
  63. if (string.IsNullOrEmpty(lab))
  64. {
  65. Lab.SetActive(false);
  66. }
  67. else
  68. {
  69. Lab.SetActive(true);
  70. Lab.text = lab;
  71. }
  72. if (string.IsNullOrEmpty(notifyLab))
  73. {
  74. NotifyLab.SetActive(false);
  75. }
  76. else
  77. {
  78. NotifyLab.SetActive(true);
  79. NotifyLab.text = notifyLab;
  80. }
  81. if (sprite == null)
  82. {
  83. Icon.SetActive(false);
  84. }
  85. else
  86. {
  87. Icon.SetActive(true);
  88. Icon.sprite = sprite;
  89. }
  90. if (cancelAction == null && confirmAction == null)
  91. {
  92. Cancel.SetActive(false);
  93. Confirm.SetButtonEvent(Close);
  94. }
  95. else
  96. {
  97. Cancel.SetActive(true);
  98. Cancel.SetButtonEvent(Close);
  99. Cancel.AddButtonEvent
  100. (
  101. () =>
  102. {
  103. AudioManager.PlayClip(AudioLabel.ClickButton);
  104. }
  105. );
  106. if (cancelAction != null)
  107. {
  108. Cancel.AddButtonEvent(cancelAction);
  109. }
  110. else
  111. {
  112. if (!enableCancle)
  113. {
  114. Cancel.SetActive(false);
  115. }
  116. }
  117. Confirm.SetButtonEvent(Close);
  118. Confirm.AddButtonEvent(confirmAction);
  119. Confirm.AddButtonEvent
  120. (
  121. () =>
  122. {
  123. AudioManager.PlayClip(AudioLabel.ClickButton);
  124. }
  125. );
  126. }
  127. }
  128. public static void Close()
  129. {
  130. Box.TweenBacScale();
  131. Background.TweenBacGra();
  132. AudioManager.PlayClip(AudioLabel.Close);
  133. }
  134. }