LoadingView.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. m_Instance = null;
  30. SceneController.DestroyObjectFromView(_effectObj, _wrapper);
  31. if (_ui != null)
  32. {
  33. _ui.Dispose();
  34. _ui = null;
  35. }
  36. base.Dispose();
  37. }
  38. protected override void OnInit()
  39. {
  40. base.OnInit();
  41. packageName = UI_LoadingView.PACKAGE_NAME;
  42. _ui = UI_LoadingView.Create();
  43. this.viewCom = _ui.target;
  44. isfullScreen = true;
  45. string resPath1 = ResPathUtil.GetViewEffectPath("ui_dljm", "ui_dljm_jdt_tw");
  46. SceneController.AddObjectToView(null, null, _ui.m_holder, resPath1, out _effectObj, out _wrapper);
  47. }
  48. protected override void OnShown()
  49. {
  50. base.OnShown();//1;//
  51. SetProgress(0);
  52. int index = Random.Range(0, resNames.Length);
  53. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath(resNames[index]);
  54. }
  55. protected override void OnHide()
  56. {
  57. base.OnHide();
  58. }
  59. public void GetUI()
  60. {
  61. ET.Log.Debug("loadingui:" + _ui);
  62. }
  63. /// <summary>
  64. /// 设置描述文字
  65. /// </summary>
  66. /// <param name="desc"></param>
  67. public void SetDesc(string desc, string descRight = "")
  68. {
  69. if (!ViewManager.isViewOpen(typeof(LoadingView).Name))
  70. {
  71. return;
  72. }
  73. string str = string.Format("{0} {1}", desc, descRight);// + descRight;
  74. _ui.m_txtDescLeft.text = str;
  75. // _ui.m_txtDescLeft.text = desc ?? "";
  76. // _ui.m_txtDescRight.text = descRight ?? "";
  77. }
  78. /// <summary>
  79. /// 设置进度0-100
  80. /// </summary>
  81. /// <param name="progress"></param>
  82. /// <param name="callback"></param>
  83. public void SetProgress(long progress, GTweenCallback callback = null)
  84. {
  85. if (!ViewManager.isViewOpen(typeof(LoadingView).Name))
  86. {
  87. return;
  88. }
  89. double oldValule;
  90. GTweener twener = GTween.GetTween(_ui.m_progressBar1, TweenPropType.Progress);
  91. if (twener != null)
  92. {
  93. oldValule = twener.value.d;
  94. }
  95. else
  96. {
  97. oldValule = _ui.m_progressBar1.value;
  98. }
  99. if (progress < oldValule)
  100. {
  101. _ui.m_progressBar1.value = progress;
  102. float posX = _ui.m_progressBar1.width * (progress / 100) - 70;
  103. _ui.m_imgAni.x = Mathf.Min(posX, _ui.target.width - _ui.m_imgAni.width - 70);
  104. callback?.Invoke();
  105. }
  106. else
  107. {
  108. float duration = (float)(progress - oldValule) * SPEED;
  109. GTweener gtweener = _ui.m_progressBar1.TweenValue(progress, duration).OnUpdate((GTweener t) =>
  110. {
  111. float posX = _ui.m_progressBar1.width * (t.value.x / 100) - 70;
  112. _ui.m_imgAni.x = Mathf.Min(posX, _ui.target.width - _ui.m_imgAni.width - 70);
  113. });
  114. if (callback != null)
  115. {
  116. gtweener.OnComplete(callback);
  117. }
  118. }
  119. callback?.Invoke();
  120. }
  121. }
  122. }