GuideView.cs 7.5 KB

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