GuideView.cs 8.2 KB

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