GuideView.cs 5.2 KB

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