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