GuideView.cs 6.0 KB

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