using System; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; /// /// 新手引导管理 /// public class GuideManagers : MonoBehaviour { /// /// 引导步骤数组(如:第一步-》第二步。。。。) /// public List guideList = new List(); /// /// 当前数组索引 /// private int currentIndex = 0; /// /// 是否完成所有的新手引导 /// private bool isFinish = false; /// /// 遮罩对象 /// private GameObject maskPrefabs; /// /// /// public void Next() { if (isFinish || currentIndex > guideList.Count) { return; } //注销上一步按钮点击事件 if (currentIndex != 0 && guideList[currentIndex - 1].go.GetComponent() != null) { EventTriggerListener.GetListener(guideList[currentIndex - 1].go).onClick -= null; } if (maskPrefabs == null) { maskPrefabs = Instantiate(Resources.Load("GuideFile/RectGuidance_Panel"), this.transform); } //初始化遮罩 maskPrefabs.GetComponent().Init(guideList[currentIndex].go.GetComponent()); ; currentIndex++; //给当前按钮添加点击事件 if (currentIndex < guideList.Count) { EventTriggerListener.GetListener(guideList[currentIndex - 1].go).onClick += (go) => { Next(); }; } //最后一个按钮点击事件处理 else if (currentIndex == guideList.Count) { EventTriggerListener.GetListener(guideList[currentIndex - 1].go).onClick += (go) => { maskPrefabs.gameObject.SetActive(false); //注销最后一个按钮的点击事件 EventTriggerListener.GetListener(guideList[currentIndex - 1].go).onClick -= null; }; isFinish = true; } } } /// /// 引导ui数组 /// [Serializable] public class GuideUIList { /// /// 引导步骤对象 /// public GameObject go; public GuideUIList(GameObject go) { this.go = go; } }