1118OPSSNew/Assets/Zion/Scripts//UISwitch.cs

49 lines
1.4 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class UISwitch : MonoBehaviour
{
protected GameObject nextPage;
protected GameObject backPage;
protected Button nextBtn;
protected Button backBtn;
public string triggerName;
public bool hideSelf = true;
// Start is called before the first frame update
public void OnEnable()
{
nextBtn = transform.Find("nextBtn")?.GetComponent<Button>();
backBtn = transform.Find("backBtn")?.GetComponent<Button>();
int index = this.transform.GetSiblingIndex();
if (index < this.transform.parent.childCount - 1)
nextPage = this.transform.parent.GetChild(index + 1).gameObject;
if (index > 0)
backPage = this.transform.parent.GetChild(index - 1).gameObject;
if (nextBtn != null)
nextBtn.onClick.AddListener(() => {
if (hideSelf) this.gameObject.SetActive(false);
if (nextPage != null)nextPage.SetActive(true);
StepManager.Instance.FinishStep(triggerName);
});
if (backBtn != null)
backBtn.onClick.AddListener(() =>{
if (hideSelf) this.gameObject.SetActive(false);
if (backPage != null) backPage.SetActive(true);
});
}
// Update is called once per frame
void Update()
{
}
}