LoadingView.cs 3.0 KB

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