LoadingView.cs 4.1 KB

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