LoadingView.cs 3.0 KB

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