GuideView.cs 4.9 KB

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