GuideView.cs 8.8 KB

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