GuideView.cs 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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. EffectUIPool.CreateEffectUI(_ui.m_comHolder.m_holder, "ui_zjm", "ui_zjm_xszy", 90,
  45. onComplete: (effect) =>
  46. {
  47. if (effect != null)
  48. {
  49. _effectUI1 = effect;
  50. }
  51. });
  52. }
  53. protected override void OnShown()
  54. {
  55. base.OnShown();
  56. List<object> dataList = viewData as List<object>;
  57. guideTarget = dataList[0] as GObject;
  58. guideKey = (string)dataList[1];
  59. txtContent = (string)dataList[2];
  60. guideId = (int)dataList[3];
  61. guideIndex = (int)dataList[4];
  62. compTxtY = (float)dataList[5];
  63. justHint = (bool)dataList[6];
  64. NoTips = (bool)dataList[7];
  65. GRoot.inst.touchable = true;
  66. MainDataManager.Instance.CanSwipe = false;
  67. UpdateComTxt(txtContent);
  68. _ui.m_maskCom.target.visible = false;
  69. _ui.m_loaMask.visible = false;
  70. _ui.m_mask.visible = false;
  71. if (guideTarget != null)
  72. {
  73. _ui.m_mask.visible = true;
  74. _ui.m_comHolder.target.visible = false;
  75. Timers.inst.Add(0.3f, 1, UpdateTime);
  76. // _ui.m_mask.target.visible = true;
  77. // _ui.m_comHolder.target.visible = true;
  78. guideTarget.onClick.Add(OnClickTarget);
  79. }
  80. else
  81. {
  82. _ui.m_loaMask.visible = true;
  83. if (compTxtY > 0)
  84. {
  85. _ui.m_compTxt.target.y = compTxtY;
  86. }
  87. _ui.m_comHolder.target.visible = false;
  88. _ui.m_compTxt.target.visible = !String.IsNullOrEmpty(txtContent);
  89. }
  90. if (justHint)
  91. {
  92. _ui.m_maskCom.target.visible = false;
  93. _ui.m_loaMask.visible = true;
  94. }
  95. if (NoTips)
  96. {
  97. _ui.m_maskCom.target.visible = false;
  98. _ui.m_comHolder.target.visible = false;
  99. }
  100. //一些特殊引导
  101. GuideCfg cfg = CommonDataManager.Tables.TblGuideCfg.GetOrDefault(ConstGuideId.STUDIO_PORCELAIN); //作室书简修复
  102. GuideCfg cfg1 = CommonDataManager.Tables.TblGuideCfg.GetOrDefault(ConstGuideId.STUDIO_FILING); //引导查阅建档
  103. GuideCfg cfg2 = CommonDataManager.Tables.TblGuideCfg.GetOrDefault(ConstGuideId.FIELD); //田野调查
  104. GuideCfg cfg4 = CommonDataManager.Tables.TblGuideCfg.GetOrDefault(ConstGuideId.STUDIO_PROPERTY); //书简修复
  105. GuideCfg cfg5 = CommonDataManager.Tables.TblGuideCfg.GetOrDefault(ConstGuideId.FREEDOM_DRESS); //换装和拍照
  106. if (guideId == cfg.Id && guideIndex == 2 || guideId == cfg1.Id && guideIndex == 2 ||
  107. guideId == cfg2.Id && guideIndex == 1 || guideId == cfg4.Id && guideIndex == 1 ||
  108. guideId == cfg5.Id && guideIndex == 1)
  109. {
  110. _ui.m_loaMask.visible = false;
  111. MainDataManager.Instance.CanSwipe = true;
  112. Timers.inst.AddUpdate(UpdateStudioMetalGuide);
  113. }
  114. GuideCfg cfg3 = CommonDataManager.Tables.TblGuideCfg.GetOrDefault(ConstGuideId.LUCKY_BOX_LINE); // 引导抽奖连线
  115. if (guideId == cfg3.Id && guideIndex == 1)
  116. {
  117. _ui.m_maskCom.target.visible = false;
  118. _ui.m_loaMask.visible = false;
  119. }
  120. }
  121. protected override void OnHide()
  122. {
  123. Timers.inst.Remove(UpdateTime);
  124. Timers.inst.Remove(UpdateGuideRect);
  125. Timers.inst.Remove(UpdateStudioMetalGuide);
  126. _ui.m_comHolder.target.visible = false;
  127. _ui.m_compTxt.target.visible = false;
  128. _ui.m_mask.visible = true;
  129. guideTarget = null;
  130. base.OnHide();
  131. // EventAgent.DispatchEvent(ConstMessage.GUIDE_VIEW_HIDE);
  132. }
  133. private void UpdateComTxt(string txtContent)
  134. {
  135. if (String.IsNullOrEmpty(txtContent))
  136. {
  137. _ui.m_compTxt.target.visible = false;
  138. }
  139. else
  140. {
  141. _ui.m_compTxt.m_txt.text = txtContent;
  142. if (this._ui.m_compTxt.m_txt.textHeight > this._ui.m_compTxt.m_txt.textFormat.size * 2)
  143. {
  144. this._ui.m_compTxt.m_txt.align = AlignType.Left;
  145. }
  146. else
  147. {
  148. this._ui.m_compTxt.m_txt.align = AlignType.Center;
  149. }
  150. this._ui.m_compTxt.m_txtBg.height = this._ui.m_compTxt.m_txtBg.initHeight;
  151. if (this._ui.m_compTxt.m_txt.textHeight > this._ui.m_compTxt.m_txt.textFormat.size * 3)
  152. {
  153. this._ui.m_compTxt.m_txtBg.height =
  154. this._ui.m_compTxt.m_txtBg.height + this._ui.m_compTxt.m_txt.textFormat.size;
  155. }
  156. }
  157. }
  158. private void UpdateTime(object param = null)
  159. {
  160. _countGuideRect = 0;
  161. Timers.inst.AddUpdate(UpdateGuideRect);
  162. }
  163. private void UpdateGuideRect(object param = null)
  164. {
  165. if (!isShowing)
  166. {
  167. Timers.inst.Remove(UpdateGuideRect);
  168. return;
  169. }
  170. if (guideTarget != null)
  171. {
  172. Vector2 pos = guideTarget.LocalToGlobal(Vector2.zero);
  173. Vector2 logicScreenPos = _ui.target.GlobalToLocal(pos);
  174. // pos = _ui.m_mask.target.GlobalToLocal(pos);
  175. logicScreenPos.x = logicScreenPos.x + guideTarget.width / 2;
  176. logicScreenPos.y = logicScreenPos.y + guideTarget.height / 2;
  177. if (_ui.m_maskCom.m_guideArea.xy == logicScreenPos)
  178. {
  179. //Timers.inst.Remove(UpdateGuideRect);
  180. _ui.m_comHolder.target.xy = _ui.m_maskCom.m_guideArea.xy;
  181. if (logicScreenPos.x > GRoot.inst.width / 2)
  182. {
  183. _ui.m_comHolder.m_c1.selectedIndex = 0; //手在左边
  184. }
  185. else
  186. {
  187. _ui.m_comHolder.m_c1.selectedIndex = 1; //手在右边
  188. }
  189. _ui.m_comHolder.target.visible = !NoTips;
  190. _ui.m_maskCom.target.visible = !NoTips;
  191. _ui.m_mask.visible = false;
  192. _ui.m_compTxt.target.visible = !String.IsNullOrEmpty(txtContent);
  193. int padding = 100;
  194. if (logicScreenPos.y < GRoot.inst.height - 700)
  195. {
  196. _ui.m_compTxt.target.y = logicScreenPos.y + _ui.m_comHolder.target.height + padding; //在下
  197. }
  198. else
  199. {
  200. _ui.m_compTxt.target.y = logicScreenPos.y - _ui.m_comHolder.target.height -
  201. _ui.m_compTxt.target.height - padding; //在上
  202. }
  203. if (compTxtY > 0)
  204. {
  205. _ui.m_compTxt.target.y = compTxtY;
  206. }
  207. return;
  208. }
  209. _ui.m_maskCom.m_guideArea.SetXY(logicScreenPos.x, logicScreenPos.y);
  210. }
  211. else
  212. {
  213. _countGuideRect += 1;
  214. //找不到引导对象3秒后关闭引导界面
  215. if (_countGuideRect > 3 * 60)
  216. {
  217. this.Hide();
  218. }
  219. }
  220. }
  221. private void UpdateStudioMetalGuide(object param)
  222. {
  223. if (MainDataManager.Instance.ViewType == 1)
  224. {
  225. OnClickTarget();
  226. }
  227. }
  228. private void OnClickTarget()
  229. {
  230. if (guideTarget != null) guideTarget.onClick.Remove(OnClickTarget);
  231. GuideController.TryCompleteGuideIndex(guideKey, guideIndex);
  232. }
  233. }
  234. }