LauncherView.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. private GameObject _gameObject;
  25. private GoWrapper _wrapper;
  26. /// <summary>
  27. /// 每1%耗时,单位秒
  28. /// </summary>
  29. private const float SPEED = 0.01f;
  30. /// <summary>
  31. /// 界面是否打开状态
  32. /// </summary>
  33. private bool isOpen = false;
  34. /// <summary>
  35. /// FairyGUI包名
  36. /// </summary>
  37. private string _packageName;
  38. #region private
  39. private void Dispose()
  40. {
  41. if (_gameObject != null)
  42. {
  43. GameObject.Destroy(_gameObject);
  44. _gameObject = null;
  45. }
  46. if (_wrapper != null)
  47. {
  48. _wrapper.Dispose();
  49. _wrapper = null;
  50. }
  51. UIPackage.RemovePackage("UI/" + _packageName);
  52. _ui.Dispose(true);
  53. _ui = null;
  54. if (_gameObject != null)
  55. {
  56. GameObject.Destroy(_gameObject);
  57. }
  58. }
  59. #endregion
  60. public LauncherView()
  61. {
  62. _packageName = UI_LauncherUI.PACKAGE_NAME;
  63. UIPackage.AddPackage("UI/" + _packageName + "/" + _packageName);
  64. _ui = UI_LauncherUI.Create();
  65. _ui.target.MakeFullScreen();
  66. _ui.target.AddRelation(GRoot.inst, RelationType.Size);
  67. _ui.m_txtVersion.text = Application.version;
  68. string resPath = "Effect/ui_dljm/ui_dljm_jdt_tw";
  69. var prefab = Resources.Load<GameObject>(resPath);
  70. _gameObject = GameObject.Instantiate(prefab);
  71. var assetDisposer = _gameObject.AddComponent<AssetReleaser>();
  72. assetDisposer.resPath = resPath;
  73. _gameObject.transform.localScale = new Vector3(100, 100, 100);
  74. _wrapper = new GoWrapper(_gameObject);
  75. _ui.m_holder.SetNativeObject(_wrapper);
  76. }
  77. /// <summary>
  78. /// 设置版本号文字
  79. /// </summary>
  80. /// <param name="version"></param>
  81. public void SetVersion(string version)
  82. {
  83. if (!isOpen)
  84. {
  85. return;
  86. }
  87. _ui.m_txtVersion.text = version;
  88. }
  89. /// <summary>
  90. /// 设置描述文字
  91. /// </summary>
  92. /// <param name="desc"></param>
  93. public void SetDesc(string desc, string descRight = "")
  94. {
  95. if (!isOpen)
  96. {
  97. return;
  98. }
  99. string str = string.Format("{0} {1}", desc, descRight);// + descRight;
  100. _ui.m_txtDescLeft.text = str;
  101. // _ui.m_txtDescLeft.text = desc ?? "";
  102. // _ui.m_txtDescRight.text = descRight ?? "";
  103. }
  104. /// <summary>
  105. /// 设置进度0-100
  106. /// </summary>
  107. /// <param name="progress"></param>
  108. /// <param name="callback"></param>
  109. public void SetProgress(long progress, GTweenCallback callback = null)
  110. {
  111. if (!isOpen)
  112. {
  113. return;
  114. }
  115. double oldValule;
  116. GTweener twener = GTween.GetTween(_ui.m_progressBar1, TweenPropType.Progress);
  117. if (twener != null)
  118. {
  119. oldValule = twener.value.d;
  120. }
  121. else
  122. {
  123. oldValule = _ui.m_progressBar1.value;
  124. }
  125. if (progress < oldValule)
  126. {
  127. _ui.m_progressBar1.value = progress;
  128. float posX = _ui.m_progressBar1.width * (progress / 100) - 70;
  129. _ui.m_imgAni.x = Mathf.Min(posX, _ui.target.width - _ui.m_imgAni.width - 70);
  130. callback?.Invoke();
  131. }
  132. else
  133. {
  134. float duration = (float)(progress - oldValule) * SPEED;
  135. GTweener gtweener = _ui.m_progressBar1.TweenValue(progress, duration).OnUpdate((GTweener t) =>
  136. {
  137. float posX = _ui.m_progressBar1.width * (t.value.x / 100) - 70;
  138. _ui.m_imgAni.x = Mathf.Min(posX, _ui.target.width - _ui.m_imgAni.width - 70);
  139. });
  140. if (callback != null)
  141. {
  142. gtweener.OnComplete(callback);
  143. }
  144. }
  145. }
  146. /// <summary>
  147. /// 打开界面
  148. /// </summary>
  149. public void Open()
  150. {
  151. if (isOpen)
  152. {
  153. return;
  154. }
  155. _ui.m_progressBar1.value = 0;
  156. _ui.m_txtDescLeft.text = "";
  157. _ui.m_txtDescRight.text = "";
  158. GRoot.inst.AddChild(_ui.target);
  159. isOpen = true;
  160. _ui.m_imgLogo.visible = LauncherConfig.netType != LauncherConfig.EnumNetType.TEMP;
  161. }
  162. /// <summary>
  163. /// 关闭界面
  164. /// </summary>
  165. /// <param name="toDestroy"></param>
  166. public void Close(bool toDestroy = false)
  167. {
  168. if (!isOpen)
  169. {
  170. return;
  171. }
  172. isOpen = false;
  173. _ui.target.RemoveFromParent();
  174. if (toDestroy)
  175. {
  176. Dispose();
  177. }
  178. }
  179. }
  180. }