using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public enum CarType { 首页, 车类型, 天气, 危险驾驶 } public class GameManager : MonoBehaviour { public static GameManager instance; public List home; //首页 public List carType; //车类型 public List weather; //天气 public List dangerDriving; //危险驾驶 public GameObject[] uiGames; private List stepValues = new List(); // 保存每个步骤的值 private int currentStep = 0; // 当前步骤索引 private void Awake() { instance = this; home = new List(); carType = new List(); weather = new List(); dangerDriving = new List(); DontDestroyOnLoad(this); } private IEnumerator Start() { // 等待所有 BtClick 对象的 Start 方法完成 yield return StartCoroutine(WaitForBtClickStarts()); // 所有 BtClick 的 Start 方法已完成,继续执行其他代码 Debug.Log("All BtClick Start methods completed."); // 执行其他方法 for (int i = 0; i < uiGames.Length; i++) { uiGames[i].SetActive(false); } uiGames[0].SetActive(true); } private IEnumerator WaitForBtClickStarts() { // 获取所有 BtClick 实例 BtClick[] btClicks = FindObjectsOfType(); int completedCount = 0; // 为每个 BtClick 实例的 OnStartCompleted 事件添加监听器 foreach (var btClick in btClicks) { btClick.OnStartCompleted += () => { completedCount++; }; } // 等待直到所有 BtClick 实例的 Start 方法完成 while (completedCount < btClicks.Length) { yield return null; // 等待一帧 } } public void UIClick(string name, CarType ct) { List btList = null; switch (ct) { case CarType.首页: btList = home; break; case CarType.车类型: btList = carType; break; case CarType.天气: btList = weather; break; case CarType.危险驾驶: btList = dangerDriving; break; } Reset(btList); foreach (var v in btList) { Debug.Log(v.name); } } /// /// 重置UI状态 /// /// private void Reset(List list) { foreach (var v in list) { v.Cancel(); } } public void NextStep(string value) { if (currentStep >= uiGames.Length - 1) return; if (currentStep < stepValues.Count) { // 更新当前步骤的值 stepValues[currentStep] = value; } else { // 添加新步骤的值 stepValues.Add(value); } for (int i = 0; i < uiGames.Length; i++) { uiGames[i].SetActive(false); } currentStep++; uiGames[currentStep].SetActive(true); DisplayCurrentStepValue(); } // 调用这个方法来返回上一个步骤 public void PreviousStep() { if (currentStep > 0) { for (int i = 0; i < uiGames.Length; i++) { uiGames[i].SetActive(false); } currentStep--; uiGames[currentStep].SetActive(true); // 移除当前步骤的值 if (currentStep < stepValues.Count) { stepValues.RemoveAt(currentStep); } DisplayCurrentStepValue(); } } // 显示当前步骤的值(仅为示例) private void DisplayCurrentStepValue() { if (currentStep < stepValues.Count) { Debug.Log("Current Step: " + currentStep + ", Value: " + stepValues[currentStep]); } else { Debug.Log("Current Step: " + currentStep + ", No Value Yet"); } } }