GuideView.cs 7.5 KB

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