GuideView.cs 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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 GameObject _gameObject;
  20. private GoWrapper _wrapper;
  21. public override void Dispose()
  22. {
  23. SceneController.DestroyObjectFromView(_gameObject, _wrapper);
  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. string resPath1 = ResPathUtil.GetViewEffectPath("ui_zjm", "ui_zjm_xszy");
  42. SceneController.AddObjectToView(_gameObject, _wrapper, _ui.m_comHolder.m_holder, resPath1, out _gameObject, out _wrapper, 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. if (guideTarget != null)
  62. {
  63. Timers.inst.AddUpdate(UpdateGuideRect);
  64. _ui.m_mask.target.visible = true;
  65. _ui.m_comHolder.target.visible = true;
  66. guideTarget.onClick.Add(OnClickTarget);
  67. }
  68. else
  69. {
  70. _ui.m_loaMask.visible = true;
  71. if (compTxtY > 0)
  72. {
  73. _ui.m_compTxt.target.y = compTxtY;
  74. }
  75. _ui.m_comHolder.target.visible = false;
  76. _ui.m_compTxt.target.visible = !String.IsNullOrEmpty(txtContent);
  77. }
  78. if (justHint)
  79. {
  80. _ui.m_mask.target.visible = false;
  81. _ui.m_loaMask.visible = true;
  82. }
  83. if (NoTips)
  84. {
  85. _ui.m_mask.target.visible = false;
  86. _ui.m_comHolder.target.visible = false;
  87. }
  88. //一些特殊引导
  89. GuideCfg cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.STUDIO_PORCELAIN);
  90. GuideCfg cfg1 = GuideCfgArray.Instance.GetCfg(ConstGuideId.STUDIO_FILING);
  91. GuideCfg cfg2 = GuideCfgArray.Instance.GetCfg(ConstGuideId.FIELD);
  92. GuideCfg cfg4 = GuideCfgArray.Instance.GetCfg(ConstGuideId.STUDIO_PROPERTY);
  93. if (guideId == cfg.id && guideIndex == 2 || guideId == cfg1.id && guideIndex == 2 || guideId == cfg2.id && guideIndex == 1 || guideId == cfg4.id && guideIndex == 1)
  94. {
  95. _ui.m_loaMask.visible = false;
  96. MainDataManager.Instance.CanSwipe = true;
  97. Timers.inst.AddUpdate(UpdateStudioMetalGuide);
  98. }
  99. GuideCfg cfg3 = GuideCfgArray.Instance.GetCfg(ConstGuideId.LUCKY_BOX_LINE);
  100. if (guideId == cfg3.id && guideIndex == 1)
  101. {
  102. _ui.m_mask.target.visible = false;
  103. _ui.m_loaMask.visible = false;
  104. }
  105. }
  106. protected override void OnHide()
  107. {
  108. base.OnHide();
  109. _ui.m_comHolder.target.visible = false;
  110. _ui.m_compTxt.target.visible = false;
  111. guideTarget = null;
  112. Timers.inst.Remove(UpdateGuideRect);
  113. Timers.inst.Remove(UpdateStudioMetalGuide);
  114. // EventAgent.DispatchEvent(ConstMessage.GUIDE_VIEW_HIDE);
  115. }
  116. private void UpdateComTxt(string txtContent)
  117. {
  118. if (String.IsNullOrEmpty(txtContent))
  119. {
  120. _ui.m_compTxt.target.visible = false;
  121. }
  122. else
  123. {
  124. _ui.m_compTxt.m_txt.text = txtContent;
  125. if (this._ui.m_compTxt.m_txt.textHeight > this._ui.m_compTxt.m_txt.textFormat.size * 2)
  126. {
  127. this._ui.m_compTxt.m_txt.align = AlignType.Left;
  128. }
  129. else
  130. {
  131. this._ui.m_compTxt.m_txt.align = AlignType.Center;
  132. }
  133. this._ui.m_compTxt.m_txtBg.height = this._ui.m_compTxt.m_txtBg.initHeight;
  134. if (this._ui.m_compTxt.m_txt.textHeight > this._ui.m_compTxt.m_txt.textFormat.size * 3)
  135. {
  136. this._ui.m_compTxt.m_txtBg.height = this._ui.m_compTxt.m_txtBg.height + this._ui.m_compTxt.m_txt.textFormat.size;
  137. }
  138. }
  139. }
  140. private void UpdateGuideRect(object param = null)
  141. {
  142. if (guideTarget != null)
  143. {
  144. Vector2 pos = guideTarget.LocalToGlobal(Vector2.zero);
  145. Vector2 logicScreenPos = GRoot.inst.GlobalToLocal(pos);
  146. // pos = _ui.m_mask.target.GlobalToLocal(pos);
  147. logicScreenPos.x = logicScreenPos.x + guideTarget.width / 2;
  148. logicScreenPos.y = logicScreenPos.y + guideTarget.height / 2;
  149. if (_ui.m_mask.m_guideArea.xy == logicScreenPos)
  150. {
  151. Timers.inst.Remove(UpdateGuideRect);
  152. _ui.m_comHolder.target.xy = _ui.m_mask.m_guideArea.xy;
  153. if (logicScreenPos.x > GRoot.inst.width / 2)
  154. {
  155. _ui.m_comHolder.m_c1.selectedIndex = 0;//手在左边
  156. }
  157. else
  158. {
  159. _ui.m_comHolder.m_c1.selectedIndex = 1;//手在右边
  160. }
  161. _ui.m_comHolder.target.visible = !NoTips;
  162. _ui.m_compTxt.target.visible = !String.IsNullOrEmpty(txtContent);
  163. int padding = 100;
  164. if (logicScreenPos.y < GRoot.inst.height - 700)
  165. {
  166. _ui.m_compTxt.target.y = logicScreenPos.y + _ui.m_comHolder.target.height + padding;//在下
  167. }
  168. else
  169. {
  170. _ui.m_compTxt.target.y = logicScreenPos.y - _ui.m_comHolder.target.height - _ui.m_compTxt.target.height - padding;//在上
  171. }
  172. if (compTxtY > 0)
  173. {
  174. _ui.m_compTxt.target.y = compTxtY;
  175. }
  176. return;
  177. }
  178. _ui.m_mask.m_guideArea.SetXY(logicScreenPos.x, logicScreenPos.y);
  179. }
  180. }
  181. private void UpdateStudioMetalGuide(object param)
  182. {
  183. if (MainDataManager.Instance.ViewType == 1)
  184. {
  185. OnClickTarget();
  186. }
  187. }
  188. private void OnClickTarget()
  189. {
  190. if (guideTarget != null) guideTarget.onClick.Remove(OnClickTarget);
  191. GuideController.TryCompleteGuideIndex(guideKey, guideIndex);
  192. }
  193. }
  194. }