123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine.UI;
- using UnityEngine;
- using UnityGameFramework.Runtime;
- public class FunctionGuideCanvas : MonoBehaviour
- {
- int _siblingIndex;
- YL_FunctionGuide.ClickType _clickType;
- Image _mask;
- Canvas _guideCanvas;
- GameObject _arrow;
- // Start is called before the first frame update
- void Start()
- {
-
- }
- private void OnEnable()
- {
-
- }
- private void Update()
- {
- if(_arrow)
- {
- _arrow.transform.position = this.transform.position;
- }
- }
- public void InitData(YL_FunctionGuide.ClickType clickType,Image mask, GameObject arrow)
- {
- this.gameObject.SetActive(true);
- if(this.transform.parent != null)
- {
- this.transform.parent.gameObject.SetActive(true);
- }
- _clickType = clickType;
- _mask = mask;
- _arrow = arrow;
- if (!this.gameObject.TryGetComponent<Canvas>(out _guideCanvas))
- {
- _guideCanvas = this.gameObject.AddComponent<Canvas>();
- }
- _guideCanvas.overrideSorting = true;
- _guideCanvas.sortingLayerName = "top";
- _guideCanvas.sortingOrder = 1001;
- GraphicRaycaster raycaster;
- if (!this.gameObject.TryGetComponent<GraphicRaycaster>(out raycaster))
- {
- raycaster = this.gameObject.AddComponent<GraphicRaycaster>();
- }
- _siblingIndex = this.transform.GetSiblingIndex();
- EventTriggerListener.Get(this.gameObject).onClick2 = ((_btn) =>
- {
- EventTriggerListener.Get(this.gameObject).onClick2 = null;
- GuideFunctionComplete();
- });
- if (clickType == YL_FunctionGuide.ClickType.Blank)
- {
- Button btn = null;
- if (mask.TryGetComponent<Button>(out btn))
- {
- btn = mask.GetComponent<Button>();
- }
- EventTriggerListener.Get(btn.gameObject).onClick2 = ((_btn) =>
- {
- EventTriggerListener.Get(btn.gameObject).onClick2 = null;
- GuideFunctionComplete();
- });
- }
- arrow.gameObject.SetActive(true);
- arrow.transform.position = this.transform.position;
- mask.gameObject.SetActive(true);
- clickType = clickType;
- }
- private void OnDestroy()
- {
- this.transform.SetSiblingIndex(_siblingIndex);
- Destroy(_guideCanvas);
-
- }
- private void GuideFunctionComplete()
- {
- gameObject.SetActive(true);
- _mask.gameObject.SetActive(false);
- _arrow.gameObject.SetActive(false);
- _arrow.transform.localPosition = Vector3.zero;
- // this.transform.parent.gameObject.SetActive(true);临时去掉测试一下,因为这个会拉起已经隐藏的界面
- _guideCanvas.sortingLayerName = "Default";
- _guideCanvas.overrideSorting = false;
- GraphicRaycaster raycaster = this.transform.GetComponent<GraphicRaycaster>();
- Destroy(raycaster);
- Destroy(this);
- EventComponent eventCmpt = GameEntry.GetComponent<EventComponent>();
- eventCmpt.FireNow(this, new GuideEventComplete());
- }
- }
|