Unity中设置tip的动画

客官°小女子只卖身不卖艺 2021-09-18 12:20 397阅读 0赞
  1. /****************************************************
  2. 文件:WndDynamic.cs
  3. 作者:李疆
  4. 邮箱: 2906718132@qq.com
  5. 日期:2019/3/13 21:24:10
  6. 功能:Nothing
  7. *****************************************************/
  8. using System;
  9. using System.Collections;
  10. using System.Collections.Generic;
  11. using UnityEngine;
  12. using UnityEngine.UI;
  13. public class WndDynamic : WindowRoot
  14. {
  15. public Text txtTips;
  16. public Animation aniTip;
  17. private bool isTipsShow = false;
  18. private Queue<string> tipsQuene = new Queue<string>();
  19. private void Start()
  20. {
  21. SetText(txtTips, "");
  22. }
  23. private void Update()
  24. {
  25. if(tipsQuene .Count >0&&isTipsShow ==false )
  26. {
  27. lock (tipsQuene)
  28. {
  29. string tips = tipsQuene.Dequeue();
  30. isTipsShow = true;
  31. SetTips(tips);
  32. }
  33. }
  34. }
  35. public void AddTips(string tips)
  36. {
  37. lock(tipsQuene)
  38. {
  39. tipsQuene.Enqueue(tips);
  40. }
  41. }
  42. private void SetTips(string tips)
  43. {
  44. SetActive(txtTips, true);
  45. SetText(txtTips, tips);
  46. AnimationClip clip = aniTip.GetClip("AniTips");
  47. aniTip.Play();
  48. //延时关闭激活状态
  49. StartCoroutine(AniPlayDone(clip.length, () =>
  50. {
  51. SetActive(txtTips, false);
  52. isTipsShow = false;
  53. }));
  54. }
  55. private IEnumerator AniPlayDone(float time ,Action loaded)
  56. {
  57. yield return new WaitForSeconds(time);
  58. if(loaded !=null)
  59. {
  60. loaded();
  61. }
  62. }
  63. }

发表评论

表情:
评论列表 (有 0 条评论,397人围观)

还没有评论,来说两句吧...

相关阅读