GuideView.cs 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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. SceneController.DestroyObjectFromView(_gameObject, _wrapper);
  26. if (_ui != null)
  27. {
  28. _ui.Dispose();
  29. _ui = null;
  30. }
  31. base.Dispose();
  32. }
  33. protected override void OnInit()
  34. {
  35. base.OnInit();
  36. viewAnimationType = EnumViewAnimationType.None;
  37. packageName = UI_GuideUI.PACKAGE_NAME;
  38. _ui = UI_GuideUI.Create();
  39. this.viewCom = _ui.target;
  40. this.layer = ConstViewLayer.GUIDE;
  41. isfullScreen = true;
  42. _ui.m_rectFrameTemp.visible = false;
  43. _ui.m_rectFrame.target.visible = false;
  44. _ui.m_rectFrame.target.AddRelation(_ui.m_mask.m_guideArea, RelationType.Width);
  45. _ui.m_rectFrame.target.AddRelation(_ui.m_mask.m_guideArea, RelationType.Height);
  46. _ui.m_rectFrame.target.AddRelation(_ui.m_mask.m_guideArea, RelationType.Left_Left);
  47. _ui.m_rectFrame.target.AddRelation(_ui.m_mask.m_guideArea, RelationType.Top_Top);
  48. _ui.m_mask.target.onClick.Add(() =>
  49. {
  50. if (ViewManager.isViewOpen(typeof(RoleLvUpView).Name))
  51. {
  52. ViewManager.Hide(typeof(RoleLvUpView).Name);
  53. }
  54. if (isOptionalGuide) this.OnClickTarget();
  55. });
  56. string resPath0 = ResPathUtil.GetViewEffectPath("ui_yd/ui_yd_y", "ui_yd_y");
  57. SceneController.AddObjectToView(_gameObject, _wrapper, _ui.m_comHolder.m_holder, resPath0, out _gameObject, out _wrapper);
  58. }
  59. protected override void OnShown()
  60. {
  61. base.OnShown();
  62. List<object> dataList = viewData as List<object>;
  63. guideTarget = dataList[0] as GObject;
  64. string txtContent = (string)dataList[1];
  65. yTxt = (int)dataList[2];
  66. isOptionalGuide = (bool)dataList[3];
  67. devWidth = (float)dataList[4];
  68. devHeight = (float)dataList[5];
  69. guideId = (int)dataList[6];
  70. guideIndex = (int)dataList[7];
  71. showAni = (bool)dataList[8];
  72. showEffect = (bool)dataList[9];
  73. if (txtContent != null && txtContent.Length > 0)
  74. {
  75. _ui.m_compTxt.m_txt.text = txtContent;
  76. if (this._ui.m_compTxt.m_txt.textHeight > this._ui.m_compTxt.m_txt.textFormat.size * 2)
  77. {
  78. this._ui.m_compTxt.m_txt.align = AlignType.Left;
  79. }
  80. else
  81. {
  82. this._ui.m_compTxt.m_txt.align = AlignType.Center;
  83. }
  84. _ui.m_compTxt.target.visible = true;
  85. }
  86. else
  87. {
  88. _ui.m_compTxt.target.visible = false;
  89. }
  90. _ui.m_comHolder.target.visible = false;
  91. _ui.m_rectFrameTemp.width = _ui.m_mask.target.width;
  92. _ui.m_rectFrameTemp.height = _ui.m_mask.target.height;
  93. _ui.m_rectFrameTemp.x = 0;
  94. _ui.m_rectFrameTemp.y = 0;
  95. _ui.m_rectFrameTemp.visible = showAni;
  96. GRoot.inst.touchable = true;
  97. if (guideTarget != null)
  98. {
  99. UpdateGuideRect();
  100. Timers.inst.AddUpdate(UpdateGuideRect);
  101. _ui.m_mask.target.visible = true;
  102. _ui.m_mask.m_guideArea.visible = false;
  103. guideTarget.onClick.Add(OnClickTarget);
  104. if (guideTarget == null) OnClickTarget();
  105. }
  106. else
  107. {
  108. _ui.m_comHolder.target.visible = false;
  109. _ui.m_mask.target.visible = false;
  110. _ui.m_rectFrameTemp.visible = false;
  111. }
  112. if (!showEffect)
  113. {
  114. _ui.m_comHolder.target.visible = showEffect;
  115. }
  116. _ui.m_compTxt.target.y = Math.Min(yTxt, GRoot.inst.height - _ui.m_compTxt.target.height - 3);
  117. }
  118. protected override void OnHide()
  119. {
  120. Timers.inst.Remove(UpdateGuideRect);
  121. base.OnHide();
  122. if (!isOptionalGuide && guideTarget == null)
  123. {
  124. OnClickTarget();
  125. }
  126. guideTarget = null;
  127. }
  128. private void UpdateGuideRect(object param = null)
  129. {
  130. if (guideTarget != null)
  131. {
  132. Rect rect = guideTarget.TransformRect(new Rect(0 + devWidth, devHeight, guideTarget.width, guideTarget.height), _ui.target);
  133. _ui.m_mask.m_guideArea.size = new Vector2((int)rect.size.x, (int)rect.size.y);
  134. _ui.m_mask.m_guideArea.position = new Vector2((int)rect.position.x, (int)rect.position.y);
  135. _ui.m_comHolder.target.position = _ui.m_mask.m_guideArea.position;
  136. _ui.m_comHolder.target.size = _ui.m_mask.m_guideArea.size;
  137. int padding = 90;
  138. bool atBottom = _ui.m_mask.m_guideArea.y + _ui.m_mask.m_guideArea.height + padding + _ui.m_compTxt.target.height + padding > GRoot.inst.height;
  139. if (yTxt == 0)
  140. {
  141. if (atBottom)
  142. {
  143. _ui.m_compTxt.target.y = _ui.m_mask.m_guideArea.y - _ui.m_compTxt.target.height - padding;
  144. }
  145. else
  146. {
  147. _ui.m_compTxt.target.y = _ui.m_mask.m_guideArea.y + _ui.m_mask.m_guideArea.height + padding;
  148. }
  149. }
  150. int targetWidth = 20;
  151. if (showAni)
  152. {
  153. 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)
  154. {
  155. // _ui.m_rectFrameTemp.visible = showAni;
  156. float duration = 0.5f;
  157. _ui.m_rectFrameTemp.TweenResize(new Vector2(_ui.m_rectFrame.target.width, _ui.m_rectFrame.target.height), duration);
  158. _ui.m_rectFrameTemp.TweenMove(new Vector2(_ui.m_rectFrame.target.x, _ui.m_rectFrame.target.y), duration);
  159. }
  160. else
  161. {
  162. _ui.m_comHolder.target.visible = true;
  163. _ui.m_rectFrameTemp.visible = false;
  164. _ui.m_mask.m_guideArea.visible = true;
  165. }
  166. }
  167. else
  168. {
  169. _ui.m_comHolder.target.visible = true;
  170. _ui.m_mask.m_guideArea.visible = true;
  171. }
  172. if (!showEffect)
  173. {
  174. _ui.m_comHolder.target.visible = showEffect;
  175. }
  176. }
  177. }
  178. private void OnClickTarget()
  179. {
  180. if (guideTarget != null) guideTarget.onClick.Remove(OnClickTarget);
  181. GuideController.TryCompleteGuideIndex(guideId, guideIndex);
  182. }
  183. }
  184. }