GuideView.cs 4.8 KB

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