LauncherView.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. using FairyGUI;
  2. using UI.Launcher;
  3. using UnityEngine;
  4. namespace GFGGame
  5. {
  6. public class LauncherView
  7. {
  8. private static LauncherView m_Instance = null;
  9. /// <summary>
  10. /// 单例
  11. /// </summary>
  12. public static LauncherView Instance
  13. {
  14. get
  15. {
  16. if (m_Instance == null)
  17. {
  18. m_Instance = new LauncherView();
  19. }
  20. return m_Instance;
  21. }
  22. }
  23. private UI_LauncherUI _ui;
  24. /// <summary>
  25. /// 每1%耗时,单位秒
  26. /// </summary>
  27. private const float SPEED = 0.01f;
  28. /// <summary>
  29. /// 界面是否打开状态
  30. /// </summary>
  31. private bool isOpen = false;
  32. /// <summary>
  33. /// FairyGUI包名
  34. /// </summary>
  35. private string _packageName;
  36. #region private
  37. private void Dispose()
  38. {
  39. UIPackage.RemovePackage("UI/" + _packageName);
  40. _ui.Dispose(true);
  41. _ui = null;
  42. }
  43. #endregion
  44. public LauncherView()
  45. {
  46. _packageName = UI_LauncherUI.PACKAGE_NAME;
  47. UIPackage.AddPackage("UI/" + _packageName + "/" + _packageName);
  48. _ui = UI_LauncherUI.Create();
  49. _ui.target.MakeFullScreen();
  50. _ui.target.AddRelation(GRoot.inst, RelationType.Size);
  51. _ui.m_txtVersion.text = Application.version;
  52. _ui.m_imgLogo.visible = LauncherConfig.netType != LauncherConfig.EnumNetType.TEMP;
  53. }
  54. /// <summary>
  55. /// 设置版本号文字
  56. /// </summary>
  57. /// <param name="version"></param>
  58. public void SetVersion(string version)
  59. {
  60. if(!isOpen)
  61. {
  62. return;
  63. }
  64. _ui.m_txtVersion.text = version;
  65. }
  66. /// <summary>
  67. /// 设置描述文字
  68. /// </summary>
  69. /// <param name="desc"></param>
  70. public void SetDesc(string desc, string descRight = null)
  71. {
  72. if (!isOpen)
  73. {
  74. return;
  75. }
  76. _ui.m_txtDescLeft.text = desc??"";
  77. _ui.m_txtDescRight.text = descRight??"";
  78. }
  79. /// <summary>
  80. /// 设置进度0-100
  81. /// </summary>
  82. /// <param name="progress"></param>
  83. /// <param name="callback"></param>
  84. public void SetProgress(long progress, GTweenCallback callback = null)
  85. {
  86. if (!isOpen)
  87. {
  88. return;
  89. }
  90. GTweener twener = GTween.GetTween(_ui.m_progressBar, TweenPropType.Progress);
  91. if (twener != null)
  92. {
  93. twener.Kill(true);
  94. }
  95. if(progress < _ui.m_progressBar.value)
  96. {
  97. _ui.m_progressBar.value = progress;
  98. callback?.Invoke();
  99. }
  100. else
  101. {
  102. float duration = (float)(progress - _ui.m_progressBar.value) * SPEED;
  103. GTweener gtweener = _ui.m_progressBar.TweenValue(progress, duration);
  104. if (callback != null)
  105. {
  106. gtweener.OnComplete(callback);
  107. }
  108. }
  109. }
  110. /// <summary>
  111. /// 打开界面
  112. /// </summary>
  113. public void Open()
  114. {
  115. if (isOpen)
  116. {
  117. return;
  118. }
  119. #if (UNITY_5 || UNITY_5_3_OR_NEWER)
  120. //Use the font names directly
  121. UIConfig.defaultFont = "Microsoft YaHei";
  122. #else
  123. //Need to put a ttf file into Resources folder. Here is the file name of the ttf file.
  124. // UIExcelConfig.defaultFont = "afont";
  125. #endif
  126. _ui.m_progressBar.value = 0;
  127. _ui.m_txtDescLeft.text = "";
  128. _ui.m_txtDescRight.text = "";
  129. GRoot.inst.AddChild(_ui.target);
  130. isOpen = true;
  131. }
  132. /// <summary>
  133. /// 关闭界面
  134. /// </summary>
  135. /// <param name="toDestroy"></param>
  136. public void Close(bool toDestroy = false)
  137. {
  138. if (!isOpen)
  139. {
  140. return;
  141. }
  142. isOpen = false;
  143. _ui.target.RemoveFromParent();
  144. if (toDestroy)
  145. {
  146. Dispose();
  147. }
  148. }
  149. }
  150. }