GuideView.cs 6.8 KB

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