LauncherView.cs 6.7 KB

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