GuideView.cs 8.2 KB

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