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. }
  53. /// <summary>
  54. /// 设置版本号文字
  55. /// </summary>
  56. /// <param name="version"></param>
  57. public void SetVersion(string version)
  58. {
  59. if(!isOpen)
  60. {
  61. return;
  62. }
  63. _ui.m_txtVersion.text = version;
  64. }
  65. /// <summary>
  66. /// 设置描述文字
  67. /// </summary>
  68. /// <param name="desc"></param>
  69. public void SetDesc(string desc, string descRight = null)
  70. {
  71. if (!isOpen)
  72. {
  73. return;
  74. }
  75. _ui.m_txtDescLeft.text = desc??"";
  76. _ui.m_txtDescRight.text = descRight??"";
  77. }
  78. /// <summary>
  79. /// 设置进度0-100
  80. /// </summary>
  81. /// <param name="progress"></param>
  82. /// <param name="callback"></param>
  83. public void SetProgress(long progress, GTweenCallback callback = null)
  84. {
  85. if (!isOpen)
  86. {
  87. return;
  88. }
  89. GTweener twener = GTween.GetTween(_ui.m_progressBar, TweenPropType.Progress);
  90. if (twener != null)
  91. {
  92. twener.Kill(true);
  93. }
  94. if(progress < _ui.m_progressBar.value)
  95. {
  96. _ui.m_progressBar.value = progress;
  97. callback?.Invoke();
  98. }
  99. else
  100. {
  101. float duration = (float)(progress - _ui.m_progressBar.value) * SPEED;
  102. GTweener gtweener = _ui.m_progressBar.TweenValue(progress, duration);
  103. if (callback != null)
  104. {
  105. gtweener.OnComplete(callback);
  106. }
  107. }
  108. }
  109. /// <summary>
  110. /// 打开界面
  111. /// </summary>
  112. public void Open()
  113. {
  114. if (isOpen)
  115. {
  116. return;
  117. }
  118. #if (UNITY_5 || UNITY_5_3_OR_NEWER)
  119. //Use the font names directly
  120. UIConfig.defaultFont = "Microsoft YaHei";
  121. #else
  122. //Need to put a ttf file into Resources folder. Here is the file name of the ttf file.
  123. // UIExcelConfig.defaultFont = "afont";
  124. #endif
  125. _ui.m_progressBar.value = 0;
  126. _ui.m_txtDescLeft.text = "";
  127. _ui.m_txtDescRight.text = "";
  128. GRoot.inst.AddChild(_ui.target);
  129. isOpen = true;
  130. _ui.m_imgLogo.visible = LauncherConfig.netType != LauncherConfig.EnumNetType.TEMP;
  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. }