GuideView.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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.target.onClick.Add(() =>
  42. {
  43. if (isOptionalGuide) this.Hide();
  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. if (guideTarget != null)
  84. {
  85. UpdateGuideRect();
  86. Timers.inst.AddUpdate(UpdateGuideRect);
  87. _ui.m_mask.target.visible = true;
  88. _ui.m_mask.m_guideArea.visible = false;
  89. guideTarget.onClick.Add(OnClickTarget);
  90. if (guideTarget == null) OnClickTarget();
  91. }
  92. else
  93. {
  94. _ui.m_comHolder.target.visible = false;
  95. _ui.m_mask.target.visible = false;
  96. _ui.m_rectFrameTemp.visible = false;
  97. }
  98. _ui.m_compTxt.target.y = Math.Min(yTxt, GRoot.inst.height - _ui.m_compTxt.target.height - 3);
  99. }
  100. protected override void OnHide()
  101. {
  102. Timers.inst.Remove(UpdateGuideRect);
  103. base.OnHide();
  104. if (isOptionalGuide || guideTarget == null)
  105. {
  106. OnClickTarget();
  107. }
  108. guideTarget = null;
  109. }
  110. private void UpdateGuideRect(object param = null)
  111. {
  112. if (guideTarget != null)
  113. {
  114. Rect rect = guideTarget.TransformRect(new Rect(0 + devWidth, devHeight, guideTarget.width, guideTarget.height), _ui.target);
  115. _ui.m_mask.m_guideArea.size = new Vector2((int)rect.size.x, (int)rect.size.y);
  116. _ui.m_mask.m_guideArea.position = new Vector2((int)rect.position.x, (int)rect.position.y);
  117. _ui.m_comHolder.target.position = _ui.m_mask.m_guideArea.position;
  118. _ui.m_comHolder.target.size = _ui.m_mask.m_guideArea.size;
  119. int padding = 90;
  120. bool atBottom = _ui.m_mask.m_guideArea.y + _ui.m_mask.m_guideArea.height + padding + _ui.m_compTxt.target.height + padding > GRoot.inst.height;
  121. if (yTxt == 0)
  122. {
  123. if (atBottom)
  124. {
  125. _ui.m_compTxt.target.y = _ui.m_mask.m_guideArea.y - _ui.m_compTxt.target.height - padding;
  126. }
  127. else
  128. {
  129. _ui.m_compTxt.target.y = _ui.m_mask.m_guideArea.y + _ui.m_mask.m_guideArea.height + padding;
  130. }
  131. }
  132. int targetWidth = 20;
  133. if (showAni)
  134. {
  135. 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)
  136. {
  137. _ui.m_rectFrameTemp.visible = true;
  138. float duration = 0.5f;
  139. _ui.m_rectFrameTemp.TweenResize(new Vector2(_ui.m_rectFrame.target.width, _ui.m_rectFrame.target.height), duration);
  140. _ui.m_rectFrameTemp.TweenMove(new Vector2(_ui.m_rectFrame.target.x, _ui.m_rectFrame.target.y), duration);
  141. }
  142. else
  143. {
  144. _ui.m_comHolder.target.visible = true;
  145. _ui.m_rectFrameTemp.visible = false;
  146. _ui.m_mask.m_guideArea.visible = true;
  147. }
  148. }
  149. else
  150. {
  151. _ui.m_comHolder.target.visible = true;
  152. _ui.m_mask.m_guideArea.visible = true;
  153. }
  154. }
  155. }
  156. private void OnClickTarget()
  157. {
  158. if (guideTarget != null) guideTarget.onClick.Remove(OnClickTarget);
  159. GuideController.TryCompleteGuideIndex(guideId, guideIndex);
  160. }
  161. }
  162. }