GuideView.cs 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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 EffectUI _effectUI1;
  20. public override void Dispose()
  21. {
  22. EffectUIPool.Recycle(_effectUI1);
  23. _effectUI1 = null;
  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. //this.viewCom.sortingOrder = ConstSortingOrder.Guide;
  40. isfullScreen = true;
  41. _ui.m_loaMask.onClick.Add(OnClickTarget);
  42. _effectUI1 = EffectUIPool.CreateEffectUI(_ui.m_comHolder.m_holder, "ui_zjm", "ui_zjm_xszy", 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. GuideCfg cfg5 = GuideCfgArray.Instance.GetCfg(ConstGuideId.FREEDOM_DRESS); //换装和拍照
  97. 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)
  98. {
  99. _ui.m_loaMask.visible = false;
  100. MainDataManager.Instance.CanSwipe = true;
  101. Timers.inst.AddUpdate(UpdateStudioMetalGuide);
  102. }
  103. GuideCfg cfg3 = GuideCfgArray.Instance.GetCfg(ConstGuideId.LUCKY_BOX_LINE); // 引导抽奖连线
  104. if (guideId == cfg3.id && guideIndex == 1)
  105. {
  106. _ui.m_mask.target.visible = false;
  107. _ui.m_loaMask.visible = false;
  108. }
  109. }
  110. protected override void OnHide()
  111. {
  112. base.OnHide();
  113. _ui.m_comHolder.target.visible = false;
  114. _ui.m_compTxt.target.visible = false;
  115. _ui.m_grhMask.visible = true;
  116. guideTarget = null;
  117. Timers.inst.Remove(UpdateTime);
  118. Timers.inst.Remove(UpdateGuideRect);
  119. Timers.inst.Remove(UpdateStudioMetalGuide);
  120. // EventAgent.DispatchEvent(ConstMessage.GUIDE_VIEW_HIDE);
  121. }
  122. private void UpdateComTxt(string txtContent)
  123. {
  124. if (String.IsNullOrEmpty(txtContent))
  125. {
  126. _ui.m_compTxt.target.visible = false;
  127. }
  128. else
  129. {
  130. _ui.m_compTxt.m_txt.text = txtContent;
  131. if (this._ui.m_compTxt.m_txt.textHeight > this._ui.m_compTxt.m_txt.textFormat.size * 2)
  132. {
  133. this._ui.m_compTxt.m_txt.align = AlignType.Left;
  134. }
  135. else
  136. {
  137. this._ui.m_compTxt.m_txt.align = AlignType.Center;
  138. }
  139. this._ui.m_compTxt.m_txtBg.height = this._ui.m_compTxt.m_txtBg.initHeight;
  140. if (this._ui.m_compTxt.m_txt.textHeight > this._ui.m_compTxt.m_txt.textFormat.size * 3)
  141. {
  142. this._ui.m_compTxt.m_txtBg.height = this._ui.m_compTxt.m_txtBg.height + this._ui.m_compTxt.m_txt.textFormat.size;
  143. }
  144. }
  145. }
  146. private void UpdateTime(object param = null)
  147. {
  148. Timers.inst.AddUpdate(UpdateGuideRect);
  149. }
  150. private void UpdateGuideRect(object param = null)
  151. {
  152. if (guideTarget != null)
  153. {
  154. Vector2 pos = guideTarget.LocalToGlobal(Vector2.zero);
  155. Vector2 logicScreenPos = GRoot.inst.GlobalToLocal(pos);
  156. // pos = _ui.m_mask.target.GlobalToLocal(pos);
  157. logicScreenPos.x = logicScreenPos.x + guideTarget.width / 2;
  158. logicScreenPos.y = logicScreenPos.y + guideTarget.height / 2;
  159. if (_ui.m_mask.m_guideArea.xy == logicScreenPos)
  160. {
  161. //Timers.inst.Remove(UpdateGuideRect);
  162. _ui.m_comHolder.target.xy = _ui.m_mask.m_guideArea.xy;
  163. if (logicScreenPos.x > GRoot.inst.width / 2)
  164. {
  165. _ui.m_comHolder.m_c1.selectedIndex = 0;//手在左边
  166. }
  167. else
  168. {
  169. _ui.m_comHolder.m_c1.selectedIndex = 1;//手在右边
  170. }
  171. _ui.m_comHolder.target.visible = !NoTips;
  172. _ui.m_mask.target.visible = !NoTips;
  173. _ui.m_grhMask.visible = false;
  174. _ui.m_compTxt.target.visible = !String.IsNullOrEmpty(txtContent);
  175. int padding = 100;
  176. if (logicScreenPos.y < GRoot.inst.height - 700)
  177. {
  178. _ui.m_compTxt.target.y = logicScreenPos.y + _ui.m_comHolder.target.height + padding;//在下
  179. }
  180. else
  181. {
  182. _ui.m_compTxt.target.y = logicScreenPos.y - _ui.m_comHolder.target.height - _ui.m_compTxt.target.height - padding;//在上
  183. }
  184. if (compTxtY > 0)
  185. {
  186. _ui.m_compTxt.target.y = compTxtY;
  187. }
  188. return;
  189. }
  190. _ui.m_mask.m_guideArea.SetXY(logicScreenPos.x, logicScreenPos.y);
  191. }
  192. }
  193. private void UpdateStudioMetalGuide(object param)
  194. {
  195. if (MainDataManager.Instance.ViewType == 1)
  196. {
  197. OnClickTarget();
  198. }
  199. }
  200. private void OnClickTarget()
  201. {
  202. if (guideTarget != null) guideTarget.onClick.Remove(OnClickTarget);
  203. GuideController.TryCompleteGuideIndex(guideKey, guideIndex);
  204. }
  205. }
  206. }