UICommonServerMsgComponentSystem.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using DG.Tweening;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace ET.Client
  5. {
  6. [FriendOf(typeof(UICommonServerMsgComponent))]
  7. public static class UICommonServerMsgComponentSystem
  8. {
  9. [ObjectSystem]
  10. public class UICommonServerMsgComponentAwakeSystem : AwakeSystem<UICommonServerMsgComponent>
  11. {
  12. protected override void Awake(UICommonServerMsgComponent self, params object[] param)
  13. {
  14. ReferenceCollector rc = self.GetParent<UI>().GameObject.GetComponent<ReferenceCollector>();
  15. self.msg_bg = rc.Get<GameObject>("msg_bg");
  16. self.msg_txt = rc.Get<GameObject>("msg_txt").GetComponent<UnityEngine.UI.Text>();
  17. string txt = "";
  18. if (param != null && param.Length > 0)
  19. {
  20. Dictionary<string, object> dic = param[0] as Dictionary<string, object>;
  21. txt = dic["content"] as string;
  22. }
  23. self.Init(txt);
  24. }
  25. }
  26. private static void Init(this UICommonServerMsgComponent self,string txt)
  27. {
  28. if (string.IsNullOrEmpty(txt))
  29. {
  30. Log.Error("txt == null");
  31. return;
  32. }
  33. self.listTask.Add(txt);
  34. self.PopTask();
  35. }
  36. public static void PushTask(this UICommonServerMsgComponent self,string txt)
  37. {
  38. if (self.isShowingMsg && txt == self.msg_txt.text)
  39. {
  40. return;
  41. }
  42. self.listTask.Add(txt);
  43. }
  44. public static void PopTask(this UICommonServerMsgComponent self)
  45. {
  46. if (self.listTask.Count <= 0)
  47. {
  48. self.OnCloseAsync();
  49. return;
  50. }
  51. string content = self.listTask[0];
  52. self.listTask.RemoveAt(0);
  53. self.msg_txt.text = content;
  54. self.isShowingMsg = true;
  55. self.msg_bg.transform.localPosition = Vector2.zero;
  56. self.msg_bg.transform.localScale = new Vector2(0.6f,0.6f);
  57. self.msg_bg.transform.DOKill();
  58. self.twScale = self.msg_bg.transform.DOScale(1, 0.3f).onComplete = () =>
  59. {
  60. self.twScale = null;
  61. self.twMove = self.msg_bg.transform.DOLocalMoveY(60, 0.8f).onComplete = () =>
  62. {
  63. self.twMove = null;
  64. self.PopTask();
  65. };
  66. };
  67. }
  68. public static async void OnCloseAsync(this UICommonServerMsgComponent self)
  69. {
  70. await UIHelper.Remove(self.ClientScene(),UIType.UICommonServerMsg);
  71. }
  72. }
  73. }