LoadingView.cs 3.8 KB

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