GuideView.cs 8.3 KB

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