GuideView.cs 6.0 KB

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