GuideView.cs 5.4 KB

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