GuideView.cs 7.4 KB

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