GuideView.cs 6.9 KB

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