LoadingView.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. isReturnView = true;
  45. _effectUI1 = EffectUIPool.CreateEffectUI(_ui.m_holder, "ui_dljm", "ui_dljm_jdt_tw");
  46. }
  47. protected override void OnShown()
  48. {
  49. base.OnShown();//1;//
  50. SetProgress(0);
  51. int index = Random.Range(0, resNames.Length);
  52. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath(resNames[index]);
  53. }
  54. protected override void OnHide()
  55. {
  56. base.OnHide();
  57. }
  58. /// <summary>
  59. /// 设置描述文字
  60. /// </summary>
  61. /// <param name="desc"></param>
  62. public void SetDesc(string desc, string descRight = "")
  63. {
  64. if (!ViewManager.isViewOpen(typeof(LoadingView).Name))
  65. {
  66. return;
  67. }
  68. string str = string.Format("{0} {1}", desc, descRight);// + descRight;
  69. _ui.m_txtDescLeft.text = str;
  70. // _ui.m_txtDescLeft.text = desc ?? "";
  71. // _ui.m_txtDescRight.text = descRight ?? "";
  72. }
  73. /// <summary>
  74. /// 设置进度0-100
  75. /// </summary>
  76. /// <param name="progress"></param>
  77. /// <param name="callback"></param>
  78. public void SetProgress(long progress, GTweenCallback callback = null)
  79. {
  80. if (!ViewManager.isViewOpen(typeof(LoadingView).Name))
  81. {
  82. return;
  83. }
  84. double oldValule;
  85. GTweener twener = GTween.GetTween(_ui.m_progressBar1, TweenPropType.Progress);
  86. if (twener != null)
  87. {
  88. oldValule = twener.value.d;
  89. }
  90. else
  91. {
  92. oldValule = _ui.m_progressBar1.value;
  93. }
  94. if (progress < oldValule)
  95. {
  96. _ui.m_progressBar1.value = progress;
  97. float posX = _ui.m_progressBar1.width * (progress / 100) + _ui.m_progressBar1.x;
  98. _ui.m_imgAni.x = Mathf.Min(posX, _ui.m_progressBar1.width + _ui.m_progressBar1.x);
  99. callback?.Invoke();
  100. }
  101. else
  102. {
  103. float duration = (float)(progress - oldValule) * SPEED;
  104. GTweener gtweener = _ui.m_progressBar1.TweenValue(progress, duration).OnUpdate((GTweener t) =>
  105. {
  106. float posX = _ui.m_progressBar1.width * (t.value.x / 100) + _ui.m_progressBar1.x;
  107. _ui.m_imgAni.x = Mathf.Min(posX, _ui.m_progressBar1.width + _ui.m_progressBar1.x);
  108. });
  109. if (callback != null)
  110. {
  111. gtweener.OnComplete(callback);
  112. }
  113. }
  114. callback?.Invoke();
  115. }
  116. }
  117. }