MessagePanel.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. namespace LoyalSoftSDK
  7. {
  8. public class MessagePanel : BaseUIForm
  9. {
  10. private Text messageText;
  11. private Animator animator;
  12. // Use this for initialization
  13. private int showTime;
  14. private DateTime disTime;
  15. private bool isEnd = false;
  16. public override void Init()
  17. {
  18. curUIType = UIType.Loading;
  19. messageText= this.transform.Find("BackPanel/Text").gameObject.GetComponent<Text>();
  20. animator = this.transform.Find("BackPanel").gameObject.GetComponent<Animator>();
  21. }
  22. public override void Display(BaseUIForm _parent, Dictionary<string, string> data)
  23. {
  24. string message;
  25. data.TryGetValue("message", out message);
  26. messageText.text = message;
  27. isEnd = false;
  28. showTime = 2;
  29. disTime = DateTime.Now;
  30. base.Display(_parent, data);
  31. animator.Play("MsgOAnimation");
  32. }
  33. // Update is called once per frame
  34. void Update() {
  35. if (isEnd)
  36. {
  37. AnimatorStateInfo info = animator.GetCurrentAnimatorStateInfo(0);
  38. // 判断动画是否播放完成
  39. if (info.normalizedTime >= 1.0f)
  40. {
  41. //播放完毕,要执行的内容
  42. Hiding();
  43. }
  44. }
  45. TimeSpan toNow = DateTime.Now - disTime;
  46. int leftTime = showTime - (int)toNow.TotalSeconds;
  47. if (leftTime <= 0)
  48. {
  49. animator.Play("MsgCAnimation");
  50. isEnd = true;
  51. }
  52. }
  53. }
  54. }