LoadingView.cs 4.5 KB

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