LauncherView.cs 6.4 KB

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