GuideView.cs 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. using UI.Guide;
  2. using FairyGUI;
  3. using UnityEngine;
  4. using System.Collections.Generic;
  5. using System;
  6. namespace GFGGame
  7. {
  8. public class GuideView : BaseView
  9. {
  10. private UI_GuideUI _ui;
  11. private GObject guideTarget = null;
  12. private int guideId;
  13. private int guideIndex;
  14. private bool justHint;//仅提示,无遮罩,点击任何地方可关闭引导
  15. private float compTxtY = 0;//提示语位置
  16. private string txtContent = "";
  17. private GameObject _gameObject;
  18. private GoWrapper _wrapper;
  19. public override void Dispose()
  20. {
  21. SceneController.DestroyObjectFromView(_gameObject, _wrapper);
  22. if (_ui != null)
  23. {
  24. _ui.Dispose();
  25. _ui = null;
  26. }
  27. base.Dispose();
  28. }
  29. protected override void OnInit()
  30. {
  31. base.OnInit();
  32. viewAnimationType = EnumViewAnimationType.None;
  33. packageName = UI_GuideUI.PACKAGE_NAME;
  34. _ui = UI_GuideUI.Create();
  35. this.viewCom = _ui.target;
  36. this.layer = ConstViewLayer.GUIDE;
  37. isfullScreen = true;
  38. _ui.m_loaMask.onClick.Add(OnClickTarget);
  39. string resPath1 = ResPathUtil.GetViewEffectPath("ui_zjm", "ui_zjm_xszy");
  40. SceneController.AddObjectToView(_gameObject, _wrapper, _ui.m_comHolder.m_holder, resPath1, out _gameObject, out _wrapper, 90);
  41. }
  42. protected override void OnShown()
  43. {
  44. base.OnShown();
  45. List<object> dataList = viewData as List<object>;
  46. guideTarget = dataList[0] as GObject;
  47. txtContent = (string)dataList[1];
  48. guideId = (int)dataList[2];
  49. guideIndex = (int)dataList[3];
  50. compTxtY = (float)dataList[4];
  51. justHint = (bool)dataList[5];
  52. GRoot.inst.touchable = true;
  53. MainDataManager.Instance.CanSwipe = false;
  54. UpdateComTxt(txtContent);
  55. _ui.m_mask.target.visible = false;
  56. _ui.m_loaMask.visible = false;
  57. if (guideTarget != null)
  58. {
  59. Timers.inst.AddUpdate(UpdateGuideRect);
  60. _ui.m_mask.target.visible = true;
  61. guideTarget.onClick.Add(OnClickTarget);
  62. }
  63. else
  64. {
  65. _ui.m_loaMask.visible = true;
  66. if (compTxtY > 0)
  67. {
  68. _ui.m_compTxt.target.y = compTxtY;
  69. }
  70. _ui.m_comHolder.target.visible = false;
  71. _ui.m_compTxt.target.visible = !String.IsNullOrEmpty(txtContent);
  72. }
  73. if (justHint)
  74. {
  75. _ui.m_mask.target.visible = false;
  76. _ui.m_loaMask.visible = true;
  77. }
  78. //一些特殊引导
  79. GuideCfg cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.STUDIO_METAL);
  80. GuideCfg cfg1 = GuideCfgArray.Instance.GetCfg(ConstGuideId.STUDIO_FILING);
  81. GuideCfg cfg2 = GuideCfgArray.Instance.GetCfg(ConstGuideId.FIELD);
  82. if (guideId == cfg.id && guideIndex == 2 || guideId == cfg1.id && guideIndex == 2 || guideId == cfg2.id && guideIndex == 1)
  83. {
  84. _ui.m_loaMask.visible = false;
  85. MainDataManager.Instance.CanSwipe = true;
  86. Timers.inst.AddUpdate(UpdateStudioMetalGuide);
  87. }
  88. GuideCfg cfg3 = GuideCfgArray.Instance.GetCfg(ConstGuideId.LUCKY_BOX_LINE);
  89. if (guideId == cfg3.id && guideIndex == 1)
  90. {
  91. _ui.m_mask.target.visible = false;
  92. _ui.m_loaMask.visible = false;
  93. }
  94. }
  95. protected override void OnHide()
  96. {
  97. base.OnHide();
  98. _ui.m_comHolder.target.visible = false;
  99. _ui.m_compTxt.target.visible = false;
  100. guideTarget = null;
  101. Timers.inst.Remove(UpdateGuideRect);
  102. Timers.inst.Remove(UpdateStudioMetalGuide);
  103. }
  104. private void UpdateComTxt(string txtContent)
  105. {
  106. if (String.IsNullOrEmpty(txtContent))
  107. {
  108. _ui.m_compTxt.target.visible = false;
  109. }
  110. else
  111. {
  112. _ui.m_compTxt.m_txt.text = txtContent;
  113. if (this._ui.m_compTxt.m_txt.textHeight > this._ui.m_compTxt.m_txt.textFormat.size * 2)
  114. {
  115. this._ui.m_compTxt.m_txt.align = AlignType.Left;
  116. }
  117. else
  118. {
  119. this._ui.m_compTxt.m_txt.align = AlignType.Center;
  120. }
  121. this._ui.m_compTxt.m_txtBg.height = this._ui.m_compTxt.m_txtBg.initHeight;
  122. if (this._ui.m_compTxt.m_txt.textHeight > this._ui.m_compTxt.m_txt.textFormat.size * 3)
  123. {
  124. this._ui.m_compTxt.m_txtBg.height = this._ui.m_compTxt.m_txtBg.height + this._ui.m_compTxt.m_txt.textFormat.size;
  125. }
  126. }
  127. }
  128. private void UpdateGuideRect(object param = null)
  129. {
  130. if (guideTarget != null)
  131. {
  132. Vector2 pos = guideTarget.LocalToGlobal(Vector2.zero);
  133. Vector2 logicScreenPos = GRoot.inst.GlobalToLocal(pos);
  134. // pos = _ui.m_mask.target.GlobalToLocal(pos);
  135. logicScreenPos.x = logicScreenPos.x + guideTarget.width / 2;
  136. logicScreenPos.y = logicScreenPos.y + guideTarget.height / 2;
  137. if (_ui.m_mask.m_guideArea.xy == logicScreenPos)
  138. {
  139. Timers.inst.Remove(UpdateGuideRect);
  140. _ui.m_comHolder.target.xy = _ui.m_mask.m_guideArea.xy;
  141. if (logicScreenPos.x > GRoot.inst.width / 2)
  142. {
  143. _ui.m_comHolder.m_c1.selectedIndex = 0;//手在左边
  144. }
  145. else
  146. {
  147. _ui.m_comHolder.m_c1.selectedIndex = 1;//手在右边
  148. }
  149. _ui.m_comHolder.target.visible = true;
  150. _ui.m_compTxt.target.visible = !String.IsNullOrEmpty(txtContent);
  151. int padding = 100;
  152. if (logicScreenPos.y < GRoot.inst.height - 700)
  153. {
  154. _ui.m_compTxt.target.y = logicScreenPos.y + _ui.m_comHolder.target.height + padding;//在下
  155. }
  156. else
  157. {
  158. _ui.m_compTxt.target.y = logicScreenPos.y - _ui.m_comHolder.target.height - _ui.m_compTxt.target.height - padding;//在上
  159. }
  160. if (compTxtY > 0)
  161. {
  162. _ui.m_compTxt.target.y = compTxtY;
  163. }
  164. return;
  165. }
  166. _ui.m_mask.m_guideArea.SetXY(logicScreenPos.x, logicScreenPos.y);
  167. }
  168. }
  169. private void UpdateStudioMetalGuide(object param)
  170. {
  171. if (MainDataManager.Instance.ViewType == 1)
  172. {
  173. OnClickTarget();
  174. }
  175. }
  176. private void OnClickTarget()
  177. {
  178. if (guideTarget != null) guideTarget.onClick.Remove(OnClickTarget);
  179. GuideController.TryCompleteGuideIndex(guideId, guideIndex);
  180. }
  181. }
  182. }