LauncherView.cs 6.3 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. 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 + "/" + _packageName);
  60. _ui.Dispose(true);
  61. _ui = null;
  62. }
  63. #endregion
  64. public LauncherView()
  65. {
  66. _packageName = UI_LauncherUI.PACKAGE_NAME;
  67. UIPackage.AddPackage("UI/" + _packageName + "/" + _packageName);
  68. _ui = UI_LauncherUI.Create();
  69. _ui.target.MakeFullScreen();
  70. _ui.target.AddRelation(GRoot.inst, RelationType.Size);
  71. _ui.m_txtVersion.text = Application.version;
  72. string resPath = "Effect/ui_dljm/Game_Open_jindut_T";
  73. var prefab = Resources.Load<GameObject>(resPath);
  74. _gameObject = GameObject.Instantiate(prefab);
  75. _gameObject.transform.localScale = new Vector3(100, 100, 100);
  76. _wrapper = new GoWrapper(_gameObject);
  77. _ui.m_progressBar1.m_holder.SetNativeObject(_wrapper);
  78. string resPath1 = "Effect/ui_dljm/Game_Open_jindut";
  79. var prefab1 = Resources.Load<GameObject>(resPath1);
  80. _gameObject1 = GameObject.Instantiate(prefab1);
  81. _gameObject1.transform.localScale = new Vector3(100, 100, 100);
  82. _wrapper1 = new GoWrapper(_gameObject1);
  83. _bar = _ui.m_progressBar1.target.GetChild("bar").asCom;
  84. _bar.GetChild("holder").asGraph.SetNativeObject(_wrapper1);
  85. _ui.m_groupBar.visible = false;
  86. }
  87. /// <summary>
  88. /// 设置版本号文字
  89. /// </summary>
  90. /// <param name="version"></param>
  91. public void SetVersion(string version)
  92. {
  93. if (!isOpen)
  94. {
  95. return;
  96. }
  97. _ui.m_txtVersion.text = version;
  98. }
  99. /// <summary>
  100. /// 设置描述文字
  101. /// </summary>
  102. /// <param name="desc"></param>
  103. public void SetDesc(string desc, string descRight = "", bool showBar = false)
  104. {
  105. if (!isOpen)
  106. {
  107. return;
  108. }
  109. _ui.m_groupBar.visible = showBar;
  110. string str = string.Format("{0} {1}", desc, descRight);// + descRight;
  111. _ui.m_txtDescLeft.text = str;
  112. // _ui.m_txtDescLeft.text = desc ?? "";
  113. // _ui.m_txtDescRight.text = descRight ?? "";
  114. }
  115. /// <summary>
  116. /// 设置进度0-100
  117. /// </summary>
  118. /// <param name="progress"></param>
  119. /// <param name="callback"></param>
  120. public void SetProgress(long progress, GTweenCallback callback = null)
  121. {
  122. if (!isOpen)
  123. {
  124. return;
  125. }
  126. double oldValule;
  127. GTweener twener = GTween.GetTween(_ui.m_progressBar1, TweenPropType.Progress);
  128. if (twener != null)
  129. {
  130. oldValule = twener.value.d;
  131. }
  132. else
  133. {
  134. oldValule = _ui.m_progressBar1.target.value;
  135. }
  136. if (progress < oldValule)
  137. {
  138. _ui.m_progressBar1.target.value = progress;
  139. float posX = _ui.m_progressBar1.target.width * (progress / 100);
  140. // _ui.m_progressBar1.m_holder.x = Mathf.Min(posX, _ui.m_progressBar1.target.width);
  141. _bar.width = posX;
  142. callback?.Invoke();
  143. }
  144. else
  145. {
  146. float duration = (float)(progress - oldValule) * SPEED;
  147. GTweener gtweener = _ui.m_progressBar1.target.TweenValue(progress, duration).OnUpdate((GTweener t) =>
  148. {
  149. float posX = _ui.m_progressBar1.target.width * (t.value.x / 100);
  150. // _ui.m_progressBar1.m_holder.x = Mathf.Min(posX, _ui.m_progressBar1.target.width);
  151. _bar.width = 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. }