LoadingView.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 = string.Format("ui://Loading/{0}", resNames[index]);
  47. }
  48. protected override void OnHide()
  49. {
  50. base.OnHide();
  51. }
  52. /// <summary>
  53. /// 设置进度0-100
  54. /// </summary>
  55. /// <param name="progress"></param>
  56. /// <param name="callback"></param>
  57. public void SetProgress(long progress, GTweenCallback callback = null)
  58. {
  59. if (!ViewManager.isViewOpen(typeof(LoadingView).Name))
  60. {
  61. return;
  62. }
  63. GTweener twener = GTween.GetTween(_ui.m_progressBar1, TweenPropType.Progress);
  64. if (twener != null)
  65. {
  66. twener.Kill(true);
  67. }
  68. if (progress < _ui.m_progressBar1.value)
  69. {
  70. _ui.m_progressBar1.value = progress;
  71. _ui.m_imgAni.x = _ui.m_progressBar1.width * (progress / 100) - 120;
  72. callback?.Invoke();
  73. }
  74. else
  75. {
  76. float duration = (float)(progress - _ui.m_progressBar1.value) * SPEED;
  77. GTweener gtweener = _ui.m_progressBar1.TweenValue(progress, duration).OnUpdate((GTweener t) =>
  78. {
  79. _ui.m_imgAni.x = _ui.m_progressBar1.width * (t.value.x / 100) - 120;
  80. });
  81. if (callback != null)
  82. {
  83. gtweener.OnComplete(callback);
  84. }
  85. }
  86. }
  87. }
  88. }