LoadingView.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. private const float SPEED = 0.01f;
  10. private string[] resNames = { "11", "33" };
  11. private EffectUI _effectUI1;
  12. private static LoadingView m_Instance = null;
  13. public static LoadingView Instance
  14. {
  15. get
  16. {
  17. if (m_Instance == null)
  18. {
  19. // m_Instance = new LauncherView();
  20. m_Instance = ViewManager.GetUIView(typeof(LoadingView).Name) as LoadingView;
  21. }
  22. return m_Instance;
  23. }
  24. }
  25. public override void Dispose()
  26. {
  27. m_Instance = null;
  28. EffectUIPool.Recycle(_effectUI1);
  29. _effectUI1 = null;
  30. if (_ui != null)
  31. {
  32. _ui.Dispose();
  33. _ui = null;
  34. }
  35. base.Dispose();
  36. }
  37. protected override void OnInit()
  38. {
  39. base.OnInit();
  40. packageName = UI_LoadingView.PACKAGE_NAME;
  41. _ui = UI_LoadingView.Create();
  42. this.viewCom = _ui.target;
  43. isfullScreen = true;
  44. _effectUI1 = EffectUIPool.CreateEffectUI(_ui.m_holder, "ui_dljm", "ui_dljm_jdt_tw");
  45. }
  46. protected override void OnShown()
  47. {
  48. base.OnShown();//1;//
  49. SetProgress(0);
  50. int index = Random.Range(0, resNames.Length);
  51. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath(resNames[index]);
  52. }
  53. protected override void OnHide()
  54. {
  55. base.OnHide();
  56. }
  57. /// <summary>
  58. /// 设置描述文字
  59. /// </summary>
  60. /// <param name="desc"></param>
  61. public void SetDesc(string desc, string descRight = "")
  62. {
  63. if (!ViewManager.isViewOpen(typeof(LoadingView).Name))
  64. {
  65. return;
  66. }
  67. string str = string.Format("{0} {1}", desc, descRight);// + descRight;
  68. _ui.m_txtDescLeft.text = str;
  69. // _ui.m_txtDescLeft.text = desc ?? "";
  70. // _ui.m_txtDescRight.text = descRight ?? "";
  71. }
  72. /// <summary>
  73. /// 设置进度0-100
  74. /// </summary>
  75. /// <param name="progress"></param>
  76. /// <param name="callback"></param>
  77. public void SetProgress(long progress, GTweenCallback callback = null)
  78. {
  79. if (!ViewManager.isViewOpen(typeof(LoadingView).Name))
  80. {
  81. return;
  82. }
  83. double oldValule;
  84. GTweener twener = GTween.GetTween(_ui.m_progressBar1, TweenPropType.Progress);
  85. if (twener != null)
  86. {
  87. oldValule = twener.value.d;
  88. }
  89. else
  90. {
  91. oldValule = _ui.m_progressBar1.value;
  92. }
  93. if (progress < oldValule)
  94. {
  95. _ui.m_progressBar1.value = progress;
  96. float posX = _ui.m_progressBar1.width * (progress / 100) + _ui.m_progressBar1.x;
  97. _ui.m_imgAni.x = Mathf.Min(posX, _ui.m_progressBar1.width + _ui.m_progressBar1.x);
  98. callback?.Invoke();
  99. }
  100. else
  101. {
  102. float duration = (float)(progress - oldValule) * SPEED;
  103. GTweener gtweener = _ui.m_progressBar1.TweenValue(progress, duration).OnUpdate((GTweener t) =>
  104. {
  105. float posX = _ui.m_progressBar1.width * (t.value.x / 100) + _ui.m_progressBar1.x;
  106. _ui.m_imgAni.x = Mathf.Min(posX, _ui.m_progressBar1.width + _ui.m_progressBar1.x);
  107. });
  108. if (callback != null)
  109. {
  110. gtweener.OnComplete(callback);
  111. }
  112. }
  113. callback?.Invoke();
  114. }
  115. }
  116. }