GuideView.cs 9.1 KB

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