Bubble.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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 override void FirstInit()
  36. {
  37. LanguageManager.Add(ResourceManager.Get<Text>(CanvasLabel.K_CancelLab), new MulLanStr(LanguageLabel.Common__Cancel));
  38. LanguageManager.Add(ResourceManager.Get<Text>(CanvasLabel.K_ConfirmLab), new MulLanStr(LanguageLabel.Common__Confirm));
  39. }
  40. 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)
  41. {
  42. AudioManager.PlayClip(AudioLabel.Bubble);
  43. Box.TweenForScale();
  44. Background.TweenForGra();
  45. if (string.IsNullOrEmpty(tit))
  46. {
  47. Tit.SetActive(false);
  48. }
  49. else
  50. {
  51. Tit.SetActive(true);
  52. Tit.text = tit;
  53. }
  54. if (string.IsNullOrEmpty(lab))
  55. {
  56. Lab.SetActive(false);
  57. }
  58. else
  59. {
  60. Lab.SetActive(true);
  61. Lab.text = lab;
  62. }
  63. if (string.IsNullOrEmpty(notifyLab))
  64. {
  65. NotifyLab.SetActive(false);
  66. }
  67. else
  68. {
  69. NotifyLab.SetActive(true);
  70. NotifyLab.text = notifyLab;
  71. }
  72. if (sprite == null)
  73. {
  74. Icon.SetActive(false);
  75. }
  76. else
  77. {
  78. Icon.SetActive(true);
  79. Icon.sprite = sprite;
  80. }
  81. if (cancelAction == null && confirmAction == null)
  82. {
  83. Cancel.SetActive(false);
  84. Confirm.SetButtonEvent(Close);
  85. }
  86. else
  87. {
  88. Cancel.SetActive(true);
  89. Cancel.SetButtonEvent(Close);
  90. Cancel.AddButtonEvent
  91. (
  92. () =>
  93. {
  94. AudioManager.PlayClip(AudioLabel.ClickButton);
  95. }
  96. );
  97. if (cancelAction != null)
  98. {
  99. Cancel.AddButtonEvent(cancelAction);
  100. }
  101. else
  102. {
  103. if (!enableCancle)
  104. {
  105. Cancel.SetActive(false);
  106. }
  107. }
  108. Confirm.SetButtonEvent(Close);
  109. Confirm.AddButtonEvent(confirmAction);
  110. Confirm.AddButtonEvent
  111. (
  112. () =>
  113. {
  114. AudioManager.PlayClip(AudioLabel.ClickButton);
  115. }
  116. );
  117. }
  118. }
  119. public static void Close()
  120. {
  121. Box.TweenBacScale();
  122. Background.TweenBacGra();
  123. AudioManager.PlayClip(AudioLabel.Close);
  124. }
  125. }