GuideView.cs 7.2 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 bool showEffect;
  18. private int guideId;
  19. private int guideIndex;
  20. private bool isOptionalGuide = false;//弱引导,点击任意地方都可关闭
  21. private GameObject _gameObject;
  22. private GoWrapper _wrapper;
  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.layer = ConstViewLayer.TOP;
  35. isfullScreen = true;
  36. _ui.m_rectFrameTemp.visible = false;
  37. _ui.m_rectFrame.target.visible = false;
  38. _ui.m_rectFrame.target.AddRelation(_ui.m_mask.m_guideArea, RelationType.Width);
  39. _ui.m_rectFrame.target.AddRelation(_ui.m_mask.m_guideArea, RelationType.Height);
  40. _ui.m_rectFrame.target.AddRelation(_ui.m_mask.m_guideArea, RelationType.Left_Left);
  41. _ui.m_rectFrame.target.AddRelation(_ui.m_mask.m_guideArea, RelationType.Top_Top);
  42. _ui.m_mask.target.onClick.Add(() =>
  43. {
  44. if (isOptionalGuide) this.OnClickTarget();
  45. });
  46. string resPath0 = ResPathUtil.GetViewEffectPath("ui_yd/ui_yd_y", "ui_yd_y");
  47. SceneController.AddObjectToView(_gameObject, _wrapper, _ui.m_comHolder.m_holder, resPath0, out _gameObject, out _wrapper);
  48. }
  49. protected override void OnShown()
  50. {
  51. base.OnShown();
  52. List<object> dataList = viewData as List<object>;
  53. guideTarget = dataList[0] as GObject;
  54. string txtContent = (string)dataList[1];
  55. yTxt = (int)dataList[2];
  56. isOptionalGuide = (bool)dataList[3];
  57. devWidth = (float)dataList[4];
  58. devHeight = (float)dataList[5];
  59. guideId = (int)dataList[6];
  60. guideIndex = (int)dataList[7];
  61. showAni = (bool)dataList[8];
  62. showEffect = (bool)dataList[9];
  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. _ui.m_rectFrameTemp.visible = showAni;
  86. if (guideTarget != null)
  87. {
  88. UpdateGuideRect();
  89. Timers.inst.AddUpdate(UpdateGuideRect);
  90. _ui.m_mask.target.visible = true;
  91. _ui.m_mask.m_guideArea.visible = false;
  92. guideTarget.onClick.Add(OnClickTarget);
  93. if (guideTarget == null) OnClickTarget();
  94. }
  95. else
  96. {
  97. _ui.m_comHolder.target.visible = false;
  98. _ui.m_mask.target.visible = false;
  99. _ui.m_rectFrameTemp.visible = false;
  100. }
  101. if (!showEffect)
  102. {
  103. _ui.m_comHolder.target.visible = showEffect;
  104. }
  105. _ui.m_compTxt.target.y = Math.Min(yTxt, GRoot.inst.height - _ui.m_compTxt.target.height - 3);
  106. }
  107. protected override void OnHide()
  108. {
  109. Timers.inst.Remove(UpdateGuideRect);
  110. base.OnHide();
  111. if (!isOptionalGuide && guideTarget == null)
  112. {
  113. OnClickTarget();
  114. }
  115. guideTarget = null;
  116. }
  117. private void UpdateGuideRect(object param = null)
  118. {
  119. if (guideTarget != null)
  120. {
  121. Rect rect = guideTarget.TransformRect(new Rect(0 + devWidth, devHeight, guideTarget.width, guideTarget.height), _ui.target);
  122. _ui.m_mask.m_guideArea.size = new Vector2((int)rect.size.x, (int)rect.size.y);
  123. _ui.m_mask.m_guideArea.position = new Vector2((int)rect.position.x, (int)rect.position.y);
  124. _ui.m_comHolder.target.position = _ui.m_mask.m_guideArea.position;
  125. _ui.m_comHolder.target.size = _ui.m_mask.m_guideArea.size;
  126. int padding = 90;
  127. bool atBottom = _ui.m_mask.m_guideArea.y + _ui.m_mask.m_guideArea.height + padding + _ui.m_compTxt.target.height + padding > GRoot.inst.height;
  128. if (yTxt == 0)
  129. {
  130. if (atBottom)
  131. {
  132. _ui.m_compTxt.target.y = _ui.m_mask.m_guideArea.y - _ui.m_compTxt.target.height - padding;
  133. }
  134. else
  135. {
  136. _ui.m_compTxt.target.y = _ui.m_mask.m_guideArea.y + _ui.m_mask.m_guideArea.height + padding;
  137. }
  138. }
  139. int targetWidth = 20;
  140. if (showAni)
  141. {
  142. 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)
  143. {
  144. // _ui.m_rectFrameTemp.visible = showAni;
  145. float duration = 0.5f;
  146. _ui.m_rectFrameTemp.TweenResize(new Vector2(_ui.m_rectFrame.target.width, _ui.m_rectFrame.target.height), duration);
  147. _ui.m_rectFrameTemp.TweenMove(new Vector2(_ui.m_rectFrame.target.x, _ui.m_rectFrame.target.y), duration);
  148. }
  149. else
  150. {
  151. _ui.m_comHolder.target.visible = true;
  152. _ui.m_rectFrameTemp.visible = false;
  153. _ui.m_mask.m_guideArea.visible = true;
  154. }
  155. }
  156. else
  157. {
  158. _ui.m_comHolder.target.visible = true;
  159. _ui.m_mask.m_guideArea.visible = true;
  160. }
  161. if (!showEffect)
  162. {
  163. _ui.m_comHolder.target.visible = showEffect;
  164. }
  165. }
  166. }
  167. private void OnClickTarget()
  168. {
  169. if (guideTarget != null) guideTarget.onClick.Remove(OnClickTarget);
  170. GuideController.TryCompleteGuideIndex(guideId, guideIndex);
  171. }
  172. }
  173. }