LoadingView.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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 GameObject _effectObj;
  12. private GoWrapper _wrapper;
  13. private static LoadingView m_Instance = null;
  14. public static LoadingView Instance
  15. {
  16. get
  17. {
  18. if (m_Instance == null)
  19. {
  20. // m_Instance = new LauncherView();
  21. m_Instance = ViewManager.GetUIView(typeof(LoadingView).Name) as LoadingView;
  22. }
  23. return m_Instance;
  24. }
  25. }
  26. public override void Dispose()
  27. {
  28. base.Dispose();
  29. m_Instance = null;
  30. SceneController.DestroyObjectFromView(_effectObj, _wrapper);
  31. if (_ui != null)
  32. {
  33. _ui.Dispose();
  34. _ui = null;
  35. }
  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. string resPath1 = ResPathUtil.GetViewEffectPath("ui_dljm", "ui_dljm_jdt_tw");
  45. SceneController.AddObjectToView(null, null, _ui.m_holder, resPath1, out _effectObj, out _wrapper);
  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. public void GetUI()
  59. {
  60. ET.Log.Debug("loadingui:" + _ui);
  61. }
  62. /// <summary>
  63. /// 设置描述文字
  64. /// </summary>
  65. /// <param name="desc"></param>
  66. public void SetDesc(string desc, string descRight = "")
  67. {
  68. if (!ViewManager.isViewOpen(typeof(LoadingView).Name))
  69. {
  70. return;
  71. }
  72. string str = string.Format("{0} {1}", desc, descRight);// + descRight;
  73. _ui.m_txtDescLeft.text = str;
  74. // _ui.m_txtDescLeft.text = desc ?? "";
  75. // _ui.m_txtDescRight.text = descRight ?? "";
  76. }
  77. /// <summary>
  78. /// 设置进度0-100
  79. /// </summary>
  80. /// <param name="progress"></param>
  81. /// <param name="callback"></param>
  82. public void SetProgress(long progress, GTweenCallback callback = null)
  83. {
  84. if (!ViewManager.isViewOpen(typeof(LoadingView).Name))
  85. {
  86. return;
  87. }
  88. double oldValule;
  89. GTweener twener = GTween.GetTween(_ui.m_progressBar1, TweenPropType.Progress);
  90. if (twener != null)
  91. {
  92. oldValule = twener.value.d;
  93. }
  94. else
  95. {
  96. oldValule = _ui.m_progressBar1.value;
  97. }
  98. if (progress < oldValule)
  99. {
  100. _ui.m_progressBar1.value = progress;
  101. float posX = _ui.m_progressBar1.width * (progress / 100) - 70;
  102. _ui.m_imgAni.x = Mathf.Min(posX, _ui.target.width - _ui.m_imgAni.width - 70);
  103. callback?.Invoke();
  104. }
  105. else
  106. {
  107. float duration = (float)(progress - oldValule) * SPEED;
  108. GTweener gtweener = _ui.m_progressBar1.TweenValue(progress, duration).OnUpdate((GTweener t) =>
  109. {
  110. float posX = _ui.m_progressBar1.width * (t.value.x / 100) - 70;
  111. _ui.m_imgAni.x = Mathf.Min(posX, _ui.target.width - _ui.m_imgAni.width - 70);
  112. });
  113. if (callback != null)
  114. {
  115. gtweener.OnComplete(callback);
  116. }
  117. }
  118. callback?.Invoke();
  119. }
  120. }
  121. }