LauncherView.cs 5.3 KB

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