LoadingView.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. }
  64. protected override void OnHide()
  65. {
  66. base.OnHide();
  67. }
  68. /// <summary>
  69. /// 设置描述文字
  70. /// </summary>
  71. /// <param name="desc"></param>
  72. public void SetDesc(string desc, string descRight = "")
  73. {
  74. if (!ViewManager.isViewOpen(typeof(LoadingView).Name))
  75. {
  76. return;
  77. }
  78. string str = string.Format("{0} {1}", desc, descRight);// + descRight;
  79. _ui.m_txtDescLeft.text = str;
  80. // _ui.m_txtDescLeft.text = desc ?? "";
  81. // _ui.m_txtDescRight.text = descRight ?? "";
  82. }
  83. /// <summary>
  84. /// 设置进度0-100
  85. /// </summary>
  86. /// <param name="progress"></param>
  87. /// <param name="callback"></param>
  88. public void SetProgress(long progress, GTweenCallback callback = null)
  89. {
  90. if (!ViewManager.isViewOpen(typeof(LoadingView).Name))
  91. {
  92. return;
  93. }
  94. double oldValule;
  95. GTweener twener = GTween.GetTween(_ui.m_progressBar1, TweenPropType.Progress);
  96. if (twener != null)
  97. {
  98. oldValule = twener.value.d;
  99. }
  100. else
  101. {
  102. oldValule = _ui.m_progressBar1.value;
  103. }
  104. if (progress < oldValule)
  105. {
  106. _ui.m_progressBar1.value = progress;
  107. float posX = _ui.m_progressBar1.width * (progress / 100) + _ui.m_progressBar1.x;
  108. _ui.m_imgAni.x = Mathf.Min(posX, _ui.m_progressBar1.width + _ui.m_progressBar1.x);
  109. callback?.Invoke();
  110. }
  111. else
  112. {
  113. float duration = (float)(progress - oldValule) * timePerProgress;
  114. GTweener gtweener = _ui.m_progressBar1.TweenValue(progress, duration).OnUpdate((GTweener t) =>
  115. {
  116. float posX = _ui.m_progressBar1.width * (t.value.x / 100) + _ui.m_progressBar1.x;
  117. _ui.m_imgAni.x = Mathf.Min(posX, _ui.m_progressBar1.width + _ui.m_progressBar1.x);
  118. });
  119. if (callback != null)
  120. {
  121. gtweener.OnComplete(callback);
  122. }
  123. }
  124. }
  125. }
  126. }