LoadingView.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. EffectUIPool.CreateEffectUI(_ui.m_holder, "ui_dljm", "ui_dljm_jdt_tw",
  50. onComplete: (effect) =>
  51. {
  52. if (effect != null)
  53. {
  54. _effectUI1 = effect;
  55. }
  56. });
  57. }
  58. protected override void OnShown()
  59. {
  60. base.OnShown(); //1;//
  61. SetProgress(0);
  62. if (this.viewData != null)
  63. {
  64. timePerProgress = (float)this.viewData;
  65. }
  66. else
  67. {
  68. timePerProgress = TimePerProgress;
  69. }
  70. int index = Random.Range(0, resNames.Length);
  71. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath(resNames[index]);
  72. List<TipsDescCfg> tipsArray = CommonDataManager.Tables.TblTipsDescCfg.DataList;
  73. System.Random rand = new System.Random();
  74. _ui.m_txtDescTop.text = tipsArray[rand.Next(0, tipsArray.Count)].Text;
  75. }
  76. protected override void OnHide()
  77. {
  78. base.OnHide();
  79. }
  80. /// <summary>
  81. /// 设置描述文字
  82. /// </summary>
  83. /// <param name="desc"></param>
  84. public void SetDesc(string desc, string descRight = "")
  85. {
  86. if (!ViewManager.isViewOpen(typeof(LoadingView).Name))
  87. {
  88. return;
  89. }
  90. string str = string.Format("{0} {1}", desc, descRight); // + descRight;
  91. _ui.m_txtDescLeft.text = str;
  92. // _ui.m_txtDescLeft.text = desc ?? "";
  93. // _ui.m_txtDescRight.text = descRight ?? "";
  94. }
  95. /// <summary>
  96. /// 设置进度0-100
  97. /// </summary>
  98. /// <param name="progress"></param>
  99. /// <param name="callback"></param>
  100. public void SetProgress(long progress, GTweenCallback callback = null)
  101. {
  102. if (!ViewManager.isViewOpen(typeof(LoadingView).Name))
  103. {
  104. return;
  105. }
  106. double oldValule;
  107. GTweener twener = GTween.GetTween(_ui.m_progressBar1, TweenPropType.Progress);
  108. if (twener != null)
  109. {
  110. oldValule = twener.value.d;
  111. }
  112. else
  113. {
  114. oldValule = _ui.m_progressBar1.value;
  115. }
  116. if (progress < oldValule)
  117. {
  118. _ui.m_progressBar1.value = progress;
  119. float posX = _ui.m_progressBar1.width * (progress / 100) + _ui.m_progressBar1.x;
  120. _ui.m_imgAni.x = Mathf.Min(posX, _ui.m_progressBar1.width + _ui.m_progressBar1.x);
  121. callback?.Invoke();
  122. }
  123. else
  124. {
  125. float duration = (float)(progress - oldValule) * timePerProgress;
  126. GTweener gtweener = _ui.m_progressBar1.TweenValue(progress, duration).OnUpdate((GTweener t) =>
  127. {
  128. float posX = _ui.m_progressBar1.width * (t.value.x / 100) + _ui.m_progressBar1.x;
  129. _ui.m_imgAni.x = Mathf.Min(posX, _ui.m_progressBar1.width + _ui.m_progressBar1.x);
  130. });
  131. if (callback != null)
  132. {
  133. gtweener.OnComplete(callback);
  134. }
  135. }
  136. }
  137. }
  138. }