LoadingView.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. using System.Collections.Generic;
  2. using cfg.GfgCfg;
  3. using FairyGUI;
  4. using UI.Loading;
  5. using UnityEngine;
  6. namespace GFGGame
  7. {
  8. public class LoadingView : BaseWindow
  9. {
  10. private UI_LoadingView _ui;
  11. //每个进度需要的时间,单位为毫秒
  12. private const float TimePerProgress = 0.005f;
  13. private string[] resNames = { "11", "33" };
  14. private EffectUI _effectUI1;
  15. //每个进度需要的时间,单位为毫秒
  16. private float timePerProgress;
  17. private static LoadingView m_Instance = null;
  18. public static LoadingView Instance
  19. {
  20. get
  21. {
  22. if (m_Instance == null)
  23. {
  24. // m_Instance = new LauncherView();
  25. m_Instance = ViewManager.GetUIView(typeof(LoadingView).Name) as LoadingView;
  26. }
  27. return m_Instance;
  28. }
  29. }
  30. public override void Dispose()
  31. {
  32. m_Instance = null;
  33. EffectUIPool.Recycle(_effectUI1);
  34. _effectUI1 = null;
  35. if (_ui != null)
  36. {
  37. _ui.Dispose();
  38. _ui = null;
  39. }
  40. base.Dispose();
  41. }
  42. protected override void OnInit()
  43. {
  44. base.OnInit();
  45. packageName = UI_LoadingView.PACKAGE_NAME;
  46. _ui = UI_LoadingView.Create();
  47. this.viewCom = _ui.target;
  48. isfullScreen = true;
  49. _effectUI1 = EffectUIPool.CreateEffectUI(_ui.m_holder, "ui_dljm", "ui_dljm_jdt_tw");
  50. }
  51. protected override void OnShown()
  52. {
  53. base.OnShown();//1;//
  54. SetProgress(0);
  55. if(this.viewData != null)
  56. {
  57. timePerProgress = (float)this.viewData;
  58. }
  59. else
  60. {
  61. timePerProgress = TimePerProgress;
  62. }
  63. int index = Random.Range(0, resNames.Length);
  64. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath(resNames[index]);
  65. List<TipsDescCfg> tipsArray = CommonDataManager.Tables.TblTipsDescCfg.DataList;
  66. System.Random rand = new System.Random();
  67. _ui.m_txtDescTop.text = tipsArray[rand.Next(0, tipsArray.Count)].Text;
  68. }
  69. protected override void OnHide()
  70. {
  71. base.OnHide();
  72. }
  73. /// <summary>
  74. /// 设置描述文字
  75. /// </summary>
  76. /// <param name="desc"></param>
  77. public void SetDesc(string desc, string descRight = "")
  78. {
  79. if (!ViewManager.isViewOpen(typeof(LoadingView).Name))
  80. {
  81. return;
  82. }
  83. string str = string.Format("{0} {1}", desc, descRight);// + descRight;
  84. _ui.m_txtDescLeft.text = str;
  85. // _ui.m_txtDescLeft.text = desc ?? "";
  86. // _ui.m_txtDescRight.text = descRight ?? "";
  87. }
  88. /// <summary>
  89. /// 设置进度0-100
  90. /// </summary>
  91. /// <param name="progress"></param>
  92. /// <param name="callback"></param>
  93. public void SetProgress(long progress, GTweenCallback callback = null)
  94. {
  95. if (!ViewManager.isViewOpen(typeof(LoadingView).Name))
  96. {
  97. return;
  98. }
  99. double oldValule;
  100. GTweener twener = GTween.GetTween(_ui.m_progressBar1, TweenPropType.Progress);
  101. if (twener != null)
  102. {
  103. oldValule = twener.value.d;
  104. }
  105. else
  106. {
  107. oldValule = _ui.m_progressBar1.value;
  108. }
  109. if (progress < oldValule)
  110. {
  111. _ui.m_progressBar1.value = progress;
  112. float posX = _ui.m_progressBar1.width * (progress / 100) + _ui.m_progressBar1.x;
  113. _ui.m_imgAni.x = Mathf.Min(posX, _ui.m_progressBar1.width + _ui.m_progressBar1.x);
  114. callback?.Invoke();
  115. }
  116. else
  117. {
  118. float duration = (float)(progress - oldValule) * timePerProgress;
  119. GTweener gtweener = _ui.m_progressBar1.TweenValue(progress, duration).OnUpdate((GTweener t) =>
  120. {
  121. float posX = _ui.m_progressBar1.width * (t.value.x / 100) + _ui.m_progressBar1.x;
  122. _ui.m_imgAni.x = Mathf.Min(posX, _ui.m_progressBar1.width + _ui.m_progressBar1.x);
  123. });
  124. if (callback != null)
  125. {
  126. gtweener.OnComplete(callback);
  127. }
  128. }
  129. }
  130. }
  131. }