GuideView.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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 bool _needUpdate;
  12. private GObject guideTarget = null;
  13. private float devWidth;
  14. private float devHeight;
  15. private int yTxt;
  16. private bool showAni;
  17. private int guideId;
  18. private int guideIndex;
  19. private bool isOptionalGuide = false;//弱引导,点击任意地方都可关闭
  20. private GameObject _gameObject;
  21. private GoWrapper _wrapper;
  22. private int sortingOrder;
  23. public override void Dispose()
  24. {
  25. base.Dispose();
  26. }
  27. protected override void OnInit()
  28. {
  29. base.OnInit();
  30. viewAnimationType = EnumViewAnimationType.None;
  31. packageName = UI_GuideUI.PACKAGE_NAME;
  32. _ui = UI_GuideUI.Create();
  33. this.viewCom = _ui.target;
  34. // this.clickBlankToClose = false;
  35. this.layer = ConstViewLayer.TOP;
  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.target.onClick.Add(() =>
  44. {
  45. if (isOptionalGuide) this.Hide();
  46. });
  47. string resPath0 = ResPathUtil.GetViewEffectPath("ui_yd/ui_yd_y", "ui_yd_y");
  48. SceneController.AddObjectToView(_gameObject, _wrapper, _ui.m_comHolder.m_holder, resPath0, out _gameObject, out _wrapper);
  49. }
  50. protected override void OnShown()
  51. {
  52. base.OnShown();
  53. List<object> dataList = viewData as List<object>;
  54. guideTarget = dataList[0] as GObject;
  55. string txtContent = (string)dataList[1];
  56. yTxt = (int)dataList[2];
  57. isOptionalGuide = (bool)dataList[3];
  58. devWidth = (float)dataList[4];
  59. devHeight = (float)dataList[5];
  60. guideId = (int)dataList[6];
  61. guideIndex = (int)dataList[7];
  62. showAni = (bool)dataList[8];
  63. if (txtContent != null && txtContent.Length > 0)
  64. {
  65. _ui.m_compTxt.m_txt.text = txtContent;
  66. if (this._ui.m_compTxt.m_txt.textHeight > this._ui.m_compTxt.m_txt.textFormat.size * 2)
  67. {
  68. this._ui.m_compTxt.m_txt.align = AlignType.Left;
  69. }
  70. else
  71. {
  72. this._ui.m_compTxt.m_txt.align = AlignType.Center;
  73. }
  74. _ui.m_compTxt.target.visible = true;
  75. }
  76. else
  77. {
  78. _ui.m_compTxt.target.visible = false;
  79. }
  80. _ui.m_comHolder.target.visible = false;
  81. _ui.m_rectFrameTemp.width = _ui.m_mask.target.width;
  82. _ui.m_rectFrameTemp.height = _ui.m_mask.target.height;
  83. _ui.m_rectFrameTemp.x = 0;
  84. _ui.m_rectFrameTemp.y = 0;
  85. if (guideTarget != null)
  86. {
  87. UpdateGuideRect();
  88. Timers.inst.AddUpdate(UpdateGuideRect);
  89. _ui.m_mask.target.visible = true;
  90. guideTarget.touchable = false;
  91. guideTarget.onClick.Add(OnClickTarget);
  92. if (guideTarget == null) OnClickTarget();
  93. }
  94. else
  95. {
  96. _ui.m_comHolder.target.visible = false;
  97. _ui.m_mask.target.visible = false;
  98. _ui.m_rectFrameTemp.visible = false;
  99. }
  100. _ui.m_compTxt.target.y = Math.Min(yTxt, GRoot.inst.height - _ui.m_compTxt.target.height - 3);
  101. // _ui.m_rectFrame.target.visible = true;
  102. }
  103. protected override void OnHide()
  104. {
  105. Timers.inst.Remove(UpdateGuideRect);
  106. base.OnHide();
  107. if (isOptionalGuide || guideTarget == null)
  108. {
  109. OnClickTarget();
  110. }
  111. guideTarget = null;
  112. }
  113. private void UpdateGuideRect(object param = null)
  114. {
  115. if (guideTarget != null)
  116. {
  117. Rect rect = guideTarget.TransformRect(new Rect(0 + devWidth, devHeight, guideTarget.width, guideTarget.height), _ui.target);
  118. _ui.m_mask.m_guideArea.size = new Vector2((int)rect.size.x, (int)rect.size.y);
  119. _ui.m_mask.m_guideArea.position = new Vector2((int)rect.position.x, (int)rect.position.y);
  120. Debug.Log("zoya000:" + _ui.m_mask.m_guideArea.position);
  121. _ui.m_comHolder.target.position = _ui.m_mask.m_guideArea.position;
  122. Debug.Log("zoya111:" + _ui.m_comHolder.target.position);
  123. _ui.m_comHolder.target.size = _ui.m_mask.m_guideArea.size;
  124. int padding = 90;
  125. bool atBottom = _ui.m_mask.m_guideArea.y + _ui.m_mask.m_guideArea.height + padding + _ui.m_compTxt.target.height + padding > GRoot.inst.height;
  126. if (yTxt == 0)
  127. {
  128. if (atBottom)
  129. {
  130. _ui.m_compTxt.target.y = _ui.m_mask.m_guideArea.y - _ui.m_compTxt.target.height - padding;
  131. }
  132. else
  133. {
  134. _ui.m_compTxt.target.y = _ui.m_mask.m_guideArea.y + _ui.m_mask.m_guideArea.height + padding;
  135. }
  136. Debug.Log("zoya222:" + _ui.m_compTxt.target.y);
  137. }
  138. int targetWidth = 20;
  139. if (showAni)
  140. {
  141. if (Mathf.Abs(_ui.m_rectFrameTemp.width - _ui.m_rectFrame.target.width) > targetWidth && Mathf.Abs(_ui.m_rectFrameTemp.height - _ui.m_rectFrame.target.height) > targetWidth)
  142. {
  143. _ui.m_rectFrameTemp.visible = true;
  144. float duration = 0.5f;
  145. _ui.m_rectFrameTemp.TweenResize(new Vector2(_ui.m_rectFrame.target.width, _ui.m_rectFrame.target.height), duration);
  146. _ui.m_rectFrameTemp.TweenMove(new Vector2(_ui.m_rectFrame.target.x, _ui.m_rectFrame.target.y), duration);
  147. }
  148. else
  149. {
  150. guideTarget.touchable = true;
  151. _ui.m_comHolder.target.visible = true;
  152. _ui.m_rectFrameTemp.visible = false;
  153. }
  154. }
  155. else
  156. {
  157. // if (Mathf.Abs(_ui.m_rectFrameTemp.width - _ui.m_rectFrame.target.width) <= targetWidth && Mathf.Abs(_ui.m_rectFrameTemp.height - _ui.m_rectFrame.target.height) <= targetWidth)
  158. // {
  159. // Timers.inst.Remove(UpdateGuideRect);
  160. // }
  161. _ui.m_comHolder.target.visible = true;
  162. guideTarget.touchable = true;
  163. }
  164. }
  165. }
  166. private void OnClickTarget()
  167. {
  168. // if (guideTarget == null) return;
  169. // if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  170. if (guideTarget != null) guideTarget.onClick.Remove(OnClickTarget);
  171. GuideController.TryCompleteGuideIndex(guideId, guideIndex);
  172. }
  173. }
  174. }