GuideView.cs 6.0 KB

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