GuideView.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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 GameObject _gameObject;
  17. private GoWrapper _wrapper;
  18. public override void Dispose()
  19. {
  20. SceneController.DestroyObjectFromView(_gameObject, _wrapper);
  21. if (_ui != null)
  22. {
  23. _ui.Dispose();
  24. _ui = null;
  25. }
  26. base.Dispose();
  27. }
  28. protected override void OnInit()
  29. {
  30. base.OnInit();
  31. viewAnimationType = EnumViewAnimationType.None;
  32. packageName = UI_GuideUI.PACKAGE_NAME;
  33. _ui = UI_GuideUI.Create();
  34. this.viewCom = _ui.target;
  35. this.layer = ConstViewLayer.GUIDE;
  36. isfullScreen = true;
  37. // _ui.m_rectFrameTemp.visible = false;
  38. // _ui.m_rectFrame.target.visible = false;
  39. // _ui.m_rectFrame.target.AddRelation(_ui.m_mask.m_guideArea, RelationType.Width);
  40. // _ui.m_rectFrame.target.AddRelation(_ui.m_mask.m_guideArea, RelationType.Height);
  41. // _ui.m_rectFrame.target.AddRelation(_ui.m_mask.m_guideArea, RelationType.Left_Left);
  42. // _ui.m_rectFrame.target.AddRelation(_ui.m_mask.m_guideArea, RelationType.Top_Top);
  43. // _ui.m_mask.target.onClick.Add(() =>
  44. // {
  45. // if (ViewManager.isViewOpen(typeof(RoleLvUpView).Name))
  46. // {
  47. // ViewManager.Hide(typeof(RoleLvUpView).Name);
  48. // }
  49. // });
  50. _ui.m_loaMask.onClick.Add(OnClickTarget);
  51. }
  52. protected override void OnShown()
  53. {
  54. base.OnShown();
  55. List<object> dataList = viewData as List<object>;
  56. guideTarget = dataList[0] as GObject;
  57. string txtContent = (string)dataList[1];
  58. guideId = (int)dataList[2];
  59. guideIndex = (int)dataList[3];
  60. compTxtY = (float)dataList[4];
  61. // GRoot.inst.touchable = true;
  62. MainDataManager.Instance.CanSwipe = false;
  63. UpdateComTxt(txtContent);
  64. _ui.m_comHolder.target.visible = false;
  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_comHolder.target.visible = true;
  71. _ui.m_mask.target.visible = true;
  72. guideTarget.onClick.Add(OnClickTarget);
  73. }
  74. else
  75. {
  76. _ui.m_loaMask.visible = true;
  77. if (compTxtY > 0)
  78. {
  79. _ui.m_compTxt.target.y = compTxtY;
  80. }
  81. }
  82. }
  83. protected override void OnHide()
  84. {
  85. base.OnHide();
  86. guideTarget = null;
  87. Timers.inst.Remove(UpdateGuideRect);
  88. }
  89. private void UpdateComTxt(string txtContent)
  90. {
  91. if (String.IsNullOrEmpty(txtContent))
  92. {
  93. _ui.m_compTxt.target.visible = false;
  94. }
  95. else
  96. {
  97. _ui.m_compTxt.m_txt.text = txtContent;
  98. if (this._ui.m_compTxt.m_txt.textHeight > this._ui.m_compTxt.m_txt.textFormat.size * 2)
  99. {
  100. this._ui.m_compTxt.m_txt.align = AlignType.Left;
  101. }
  102. else
  103. {
  104. this._ui.m_compTxt.m_txt.align = AlignType.Center;
  105. }
  106. _ui.m_compTxt.target.visible = true;
  107. this._ui.m_compTxt.m_txtBg.height = this._ui.m_compTxt.m_txtBg.initHeight;
  108. if (this._ui.m_compTxt.m_txt.textHeight > this._ui.m_compTxt.m_txt.textFormat.size * 3)
  109. {
  110. this._ui.m_compTxt.m_txtBg.height = this._ui.m_compTxt.m_txtBg.height + this._ui.m_compTxt.m_txt.textFormat.size;
  111. }
  112. }
  113. }
  114. private void UpdateGuideRect(object param = null)
  115. {
  116. if (guideTarget != null)
  117. {
  118. Vector2 pos = guideTarget.LocalToGlobal(Vector2.zero);
  119. pos.x = pos.x + guideTarget.width / 2;
  120. pos.y = pos.y + guideTarget.height / 2;
  121. if (_ui.m_mask.m_guideArea.xy == pos)
  122. {
  123. Timers.inst.Remove(UpdateGuideRect);
  124. return;
  125. }
  126. _ui.m_mask.m_guideArea.SetXY(pos.x, pos.y);
  127. _ui.m_comHolder.target.position = _ui.m_mask.m_guideArea.position;
  128. if (pos.x > GRoot.inst.width / 2)
  129. {
  130. _ui.m_comHolder.m_c1.selectedIndex = 0;//手在左边
  131. }
  132. else
  133. {
  134. _ui.m_comHolder.m_c1.selectedIndex = 1;//手在右边
  135. }
  136. int padding = 200;
  137. if (pos.y < GRoot.inst.height - 700)
  138. {
  139. _ui.m_compTxt.target.y = pos.y + padding;
  140. }
  141. else
  142. {
  143. _ui.m_compTxt.target.y = pos.y - padding - _ui.m_compTxt.target.height;
  144. }
  145. if (compTxtY > 0)
  146. {
  147. _ui.m_compTxt.target.y = compTxtY;
  148. }
  149. }
  150. }
  151. private void OnClickTarget()
  152. {
  153. if (guideTarget != null) guideTarget.onClick.Remove(OnClickTarget);
  154. GuideController.TryCompleteGuideIndex(guideId, guideIndex);
  155. }
  156. }
  157. }