LauncherView.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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. // 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. _gameObject.transform.localScale = new Vector3(100, 100, 100);
  80. _wrapper = new GoWrapper(_gameObject);
  81. _ui.m_progressBar1.m_holder.SetNativeObject(_wrapper);
  82. string resPath1 = "Effect/ui_dljm/Game_Open_jindut";
  83. var prefab1 = Resources.Load<GameObject>(resPath1);
  84. _gameObject1 = GameObject.Instantiate(prefab1);
  85. _gameObject1.transform.localScale = new Vector3(100, 100, 100);
  86. _wrapper1 = new GoWrapper(_gameObject1);
  87. _bar = _ui.m_progressBar1.target.GetChild("bar").asCom;
  88. _bar.GetChild("holder").asGraph.SetNativeObject(_wrapper1);
  89. _ui.m_groupBar.visible = false;
  90. }
  91. /// <summary>
  92. /// 设置版本号文字
  93. /// </summary>
  94. /// <param name="version"></param>
  95. public void SetVersion(string version)
  96. {
  97. if (!isOpen)
  98. {
  99. return;
  100. }
  101. _ui.m_txtVersion.text = version;
  102. }
  103. /// <summary>
  104. /// 设置描述文字
  105. /// </summary>
  106. /// <param name="desc"></param>
  107. public void SetDesc(string desc, string descRight = "", bool showBar = false)
  108. {
  109. if (!isOpen)
  110. {
  111. return;
  112. }
  113. _ui.m_groupBar.visible = showBar;
  114. string str = string.Format("{0} {1}", desc, descRight);// + descRight;
  115. _ui.m_txtDescLeft.text = str;
  116. // _ui.m_txtDescLeft.text = desc ?? "";
  117. // _ui.m_txtDescRight.text = descRight ?? "";
  118. }
  119. /// <summary>
  120. /// 设置进度0-100
  121. /// </summary>
  122. /// <param name="progress"></param>
  123. /// <param name="callback"></param>
  124. public void SetProgress(long progress, GTweenCallback callback = null)
  125. {
  126. if (!isOpen)
  127. {
  128. return;
  129. }
  130. double oldValule;
  131. GTweener twener = GTween.GetTween(_ui.m_progressBar1, TweenPropType.Progress);
  132. if (twener != null)
  133. {
  134. oldValule = twener.value.d;
  135. }
  136. else
  137. {
  138. oldValule = _ui.m_progressBar1.target.value;
  139. }
  140. if (progress < oldValule)
  141. {
  142. _ui.m_progressBar1.target.value = progress;
  143. float posX = _ui.m_progressBar1.target.width * (progress / 100);
  144. // _ui.m_progressBar1.m_holder.x = Mathf.Min(posX, _ui.m_progressBar1.target.width);
  145. _bar.width = posX;
  146. callback?.Invoke();
  147. }
  148. else
  149. {
  150. float duration = (float)(progress - oldValule) * SPEED;
  151. GTweener gtweener = _ui.m_progressBar1.target.TweenValue(progress, duration).OnUpdate((GTweener t) =>
  152. {
  153. float posX = _ui.m_progressBar1.target.width * (t.value.x / 100);
  154. // _ui.m_progressBar1.m_holder.x = Mathf.Min(posX, _ui.m_progressBar1.target.width);
  155. _bar.width = posX;
  156. });
  157. if (callback != null)
  158. {
  159. gtweener.OnComplete(callback);
  160. }
  161. }
  162. }
  163. /// <summary>
  164. /// 打开界面
  165. /// </summary>
  166. public void Open()
  167. {
  168. if (isOpen)
  169. {
  170. return;
  171. }
  172. _ui.m_progressBar1.target.value = 0;
  173. _ui.m_txtDescLeft.text = "";
  174. _ui.m_txtDescRight.text = "";
  175. GRoot.inst.AddChild(_ui.target);
  176. isOpen = true;
  177. }
  178. /// <summary>
  179. /// 关闭界面
  180. /// </summary>
  181. /// <param name="toDestroy"></param>
  182. public void Close(bool toDestroy = true)
  183. {
  184. if (!isOpen)
  185. {
  186. return;
  187. }
  188. isOpen = false;
  189. _ui.target.RemoveFromParent();
  190. if (toDestroy)
  191. {
  192. Dispose();
  193. }
  194. }
  195. }
  196. }