LoadingView.cs 4.0 KB

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