LoadingView.cs 3.8 KB

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