FunctionGuideCanvas.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine.UI;
  4. using UnityEngine;
  5. using UnityGameFramework.Runtime;
  6. public class FunctionGuideCanvas : MonoBehaviour
  7. {
  8. int _siblingIndex;
  9. YL_FunctionGuide.ClickType _clickType;
  10. Image _mask;
  11. Canvas _guideCanvas;
  12. GameObject _arrow;
  13. // Start is called before the first frame update
  14. void Start()
  15. {
  16. }
  17. private void OnEnable()
  18. {
  19. }
  20. private void Update()
  21. {
  22. if(_arrow)
  23. {
  24. _arrow.transform.position = this.transform.position;
  25. }
  26. }
  27. public void InitData(YL_FunctionGuide.ClickType clickType,Image mask, GameObject arrow)
  28. {
  29. this.gameObject.SetActive(true);
  30. if(this.transform.parent != null)
  31. {
  32. this.transform.parent.gameObject.SetActive(true);
  33. }
  34. _clickType = clickType;
  35. _mask = mask;
  36. _arrow = arrow;
  37. if (!this.gameObject.TryGetComponent<Canvas>(out _guideCanvas))
  38. {
  39. _guideCanvas = this.gameObject.AddComponent<Canvas>();
  40. }
  41. _guideCanvas.overrideSorting = true;
  42. _guideCanvas.sortingLayerName = "top";
  43. _guideCanvas.sortingOrder = 1001;
  44. GraphicRaycaster raycaster;
  45. if (!this.gameObject.TryGetComponent<GraphicRaycaster>(out raycaster))
  46. {
  47. raycaster = this.gameObject.AddComponent<GraphicRaycaster>();
  48. }
  49. _siblingIndex = this.transform.GetSiblingIndex();
  50. EventTriggerListener.Get(this.gameObject).onClick2 = ((_btn) =>
  51. {
  52. EventTriggerListener.Get(this.gameObject).onClick2 = null;
  53. GuideFunctionComplete();
  54. });
  55. if (clickType == YL_FunctionGuide.ClickType.Blank)
  56. {
  57. Button btn = null;
  58. if (mask.TryGetComponent<Button>(out btn))
  59. {
  60. btn = mask.GetComponent<Button>();
  61. }
  62. EventTriggerListener.Get(btn.gameObject).onClick2 = ((_btn) =>
  63. {
  64. EventTriggerListener.Get(btn.gameObject).onClick2 = null;
  65. GuideFunctionComplete();
  66. });
  67. }
  68. arrow.gameObject.SetActive(true);
  69. arrow.transform.position = this.transform.position;
  70. mask.gameObject.SetActive(true);
  71. clickType = clickType;
  72. }
  73. private void OnDestroy()
  74. {
  75. this.transform.SetSiblingIndex(_siblingIndex);
  76. Destroy(_guideCanvas);
  77. }
  78. private void GuideFunctionComplete()
  79. {
  80. gameObject.SetActive(true);
  81. _mask.gameObject.SetActive(false);
  82. _arrow.gameObject.SetActive(false);
  83. _arrow.transform.localPosition = Vector3.zero;
  84. // this.transform.parent.gameObject.SetActive(true);临时去掉测试一下,因为这个会拉起已经隐藏的界面
  85. _guideCanvas.sortingLayerName = "Default";
  86. _guideCanvas.overrideSorting = false;
  87. GraphicRaycaster raycaster = this.transform.GetComponent<GraphicRaycaster>();
  88. Destroy(raycaster);
  89. Destroy(this);
  90. EventComponent eventCmpt = GameEntry.GetComponent<EventComponent>();
  91. eventCmpt.FireNow(this, new GuideEventComplete());
  92. }
  93. }