GuideView.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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 int guideId;
  13. private int guideIndex;
  14. private bool justHint;//仅提示,不提示点击,无遮罩,点击任何地方可关闭引导
  15. private float compTxtY = 0;//提示语位置
  16. private string txtContent = "";
  17. private GameObject _gameObject;
  18. private GoWrapper _wrapper;
  19. public override void Dispose()
  20. {
  21. SceneController.DestroyObjectFromView(_gameObject, _wrapper);
  22. if (_ui != null)
  23. {
  24. _ui.Dispose();
  25. _ui = null;
  26. }
  27. base.Dispose();
  28. }
  29. protected override void OnInit()
  30. {
  31. base.OnInit();
  32. viewAnimationType = EnumViewAnimationType.None;
  33. packageName = UI_GuideUI.PACKAGE_NAME;
  34. _ui = UI_GuideUI.Create();
  35. this.viewCom = _ui.target;
  36. this.layer = ConstViewLayer.GUIDE;
  37. isfullScreen = true;
  38. // _ui.m_rectFrameTemp.visible = false;
  39. // _ui.m_rectFrame.target.visible = false;
  40. // _ui.m_rectFrame.target.AddRelation(_ui.m_mask.m_guideArea, RelationType.Width);
  41. // _ui.m_rectFrame.target.AddRelation(_ui.m_mask.m_guideArea, RelationType.Height);
  42. // _ui.m_rectFrame.target.AddRelation(_ui.m_mask.m_guideArea, RelationType.Left_Left);
  43. // _ui.m_rectFrame.target.AddRelation(_ui.m_mask.m_guideArea, RelationType.Top_Top);
  44. // _ui.m_mask.target.onClick.Add(() =>
  45. // {
  46. // if (ViewManager.isViewOpen(typeof(RoleLvUpView).Name))
  47. // {
  48. // ViewManager.Hide(typeof(RoleLvUpView).Name);
  49. // }
  50. // });
  51. _ui.m_loaMask.onClick.Add(OnClickTarget);
  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. txtContent = (string)dataList[1];
  59. guideId = (int)dataList[2];
  60. guideIndex = (int)dataList[3];
  61. compTxtY = (float)dataList[4];
  62. // GRoot.inst.touchable = true;
  63. MainDataManager.Instance.CanSwipe = false;
  64. UpdateComTxt(txtContent);
  65. _ui.m_mask.target.visible = false;
  66. _ui.m_loaMask.visible = false;
  67. if (guideTarget != null)
  68. {
  69. Timers.inst.AddUpdate(UpdateGuideRect);
  70. _ui.m_mask.target.visible = true;
  71. guideTarget.onClick.Add(OnClickTarget);
  72. }
  73. else
  74. {
  75. _ui.m_loaMask.visible = true;
  76. if (compTxtY > 0)
  77. {
  78. _ui.m_compTxt.target.y = compTxtY;
  79. }
  80. _ui.m_comHolder.target.visible = false;
  81. _ui.m_compTxt.target.visible = !String.IsNullOrEmpty(txtContent);
  82. }
  83. GuideCfg cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.STUDIO_METAL);
  84. if (guideId == cfg.id && guideIndex == 2)
  85. {
  86. _ui.m_loaMask.visible = false;
  87. MainDataManager.Instance.CanSwipe = true;
  88. Timers.inst.AddUpdate(UpdateStudioMetalGuide);
  89. }
  90. }
  91. protected override void OnHide()
  92. {
  93. base.OnHide();
  94. _ui.m_comHolder.target.visible = false;
  95. _ui.m_compTxt.target.visible = false;
  96. guideTarget = null;
  97. Timers.inst.Remove(UpdateGuideRect);
  98. Timers.inst.Remove(UpdateStudioMetalGuide);
  99. }
  100. private void UpdateComTxt(string txtContent)
  101. {
  102. if (String.IsNullOrEmpty(txtContent))
  103. {
  104. _ui.m_compTxt.target.visible = false;
  105. }
  106. else
  107. {
  108. _ui.m_compTxt.m_txt.text = txtContent;
  109. if (this._ui.m_compTxt.m_txt.textHeight > this._ui.m_compTxt.m_txt.textFormat.size * 2)
  110. {
  111. this._ui.m_compTxt.m_txt.align = AlignType.Left;
  112. }
  113. else
  114. {
  115. this._ui.m_compTxt.m_txt.align = AlignType.Center;
  116. }
  117. this._ui.m_compTxt.m_txtBg.height = this._ui.m_compTxt.m_txtBg.initHeight;
  118. if (this._ui.m_compTxt.m_txt.textHeight > this._ui.m_compTxt.m_txt.textFormat.size * 3)
  119. {
  120. this._ui.m_compTxt.m_txtBg.height = this._ui.m_compTxt.m_txtBg.height + this._ui.m_compTxt.m_txt.textFormat.size;
  121. }
  122. }
  123. }
  124. private void UpdateGuideRect(object param = null)
  125. {
  126. if (guideTarget != null)
  127. {
  128. Vector2 pos = guideTarget.LocalToGlobal(Vector2.zero);
  129. pos.x = pos.x + guideTarget.width / 2;
  130. pos.y = pos.y + guideTarget.height / 2;
  131. if (_ui.m_mask.m_guideArea.xy == pos)
  132. {
  133. Timers.inst.Remove(UpdateGuideRect);
  134. _ui.m_comHolder.target.position = _ui.m_mask.m_guideArea.position;
  135. if (pos.x > GRoot.inst.width / 2)
  136. {
  137. _ui.m_comHolder.m_c1.selectedIndex = 0;//手在左边
  138. }
  139. else
  140. {
  141. _ui.m_comHolder.m_c1.selectedIndex = 1;//手在右边
  142. }
  143. _ui.m_comHolder.target.visible = true;
  144. _ui.m_compTxt.target.visible = !String.IsNullOrEmpty(txtContent);
  145. int padding = 200;
  146. if (pos.y < GRoot.inst.height - 700)
  147. {
  148. _ui.m_compTxt.target.y = pos.y + padding;
  149. }
  150. else
  151. {
  152. _ui.m_compTxt.target.y = pos.y - padding - _ui.m_compTxt.target.height;
  153. }
  154. if (compTxtY > 0)
  155. {
  156. _ui.m_compTxt.target.y = compTxtY;
  157. }
  158. return;
  159. }
  160. _ui.m_mask.m_guideArea.SetXY(pos.x, pos.y);
  161. }
  162. }
  163. private void UpdateStudioMetalGuide(object param)
  164. {
  165. if (MainDataManager.Instance.ViewType == 1)
  166. {
  167. OnClickTarget();
  168. }
  169. }
  170. private void OnClickTarget()
  171. {
  172. if (guideTarget != null) guideTarget.onClick.Remove(OnClickTarget);
  173. GuideController.TryCompleteGuideIndex(guideId, guideIndex);
  174. }
  175. }
  176. }