145 lines
3.9 KiB
C#
145 lines
3.9 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
|
|
public enum CarType
|
|
{
|
|
首页,
|
|
车类型,
|
|
天气,
|
|
危险驾驶
|
|
}
|
|
|
|
|
|
public class GameManager : MonoBehaviour
|
|
{
|
|
public static GameManager instance;
|
|
|
|
// public List<BtClick> home; //首页
|
|
//
|
|
// // public List<BtClick> carType; //车类型
|
|
// public List<BtClick> weather; //天气
|
|
// public List<BtClick> dangerDriving; //危险驾驶
|
|
|
|
public GameObject[] uiGames;
|
|
|
|
private int currentStep = 0; // 当前步骤索引
|
|
public Dictionary<CarType, string> carSelectTypeInfo = new Dictionary<CarType, string>();
|
|
|
|
private void Awake()
|
|
{
|
|
instance = this;
|
|
|
|
// home = new List<BtClick>();
|
|
// // carType = new List<BtClick>();
|
|
// weather = new List<BtClick>();
|
|
// dangerDriving = new List<BtClick>();
|
|
|
|
DontDestroyOnLoad(this);
|
|
}
|
|
|
|
|
|
private void 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);
|
|
|
|
|
|
// GetComponent<SteeringWheelController>().buttons = home;
|
|
|
|
|
|
// UIClick(CarType.首页, "模拟驾驶体验");
|
|
// NextStep("3");
|
|
GetComponent<SteeringWheelController>().buttons = uiGames[currentStep].GetComponentsInChildren<Button>();
|
|
GetComponent<SteeringWheelController>().HighlightButton(0);
|
|
}
|
|
|
|
// private IEnumerator WaitForBtClickStarts()
|
|
// {
|
|
// // 获取所有 BtClick 实例
|
|
// BtClick[] btClicks = FindObjectsOfType<BtClick>();
|
|
// int completedCount = 0;
|
|
//
|
|
// // 为每个 BtClick 实例的 OnStartCompleted 事件添加监听器
|
|
// foreach (var btClick in btClicks)
|
|
// {
|
|
// btClick.OnStartCompleted += () => { completedCount++; };
|
|
// }
|
|
//
|
|
// // 等待直到所有 BtClick 实例的 Start 方法完成
|
|
// while (completedCount < btClicks.Length)
|
|
// {
|
|
// yield return null; // 等待一帧
|
|
// }
|
|
// }
|
|
|
|
|
|
public void OnBtClick(CarType carType, string btName)
|
|
{
|
|
carSelectTypeInfo.Add(carType, btName);
|
|
|
|
NextStep();
|
|
|
|
foreach (var v in carSelectTypeInfo)
|
|
{
|
|
Debug.Log(v.Key + "--->" + v.Value);
|
|
}
|
|
}
|
|
|
|
|
|
public void NextStep()
|
|
{
|
|
if (currentStep >= uiGames.Length - 1)
|
|
return;
|
|
|
|
for (int i = 0; i < uiGames.Length; i++)
|
|
{
|
|
uiGames[i].SetActive(false);
|
|
}
|
|
|
|
currentStep++;
|
|
uiGames[currentStep].SetActive(true);
|
|
|
|
uiGames[currentStep].transform.GetChild(0).GetComponent<BtClick>().OnClickSprite();
|
|
|
|
// Debug.Log(uiGames[currentStep].transform.GetChild(0).GetComponent<Button>());
|
|
GetComponent<SteeringWheelController>().buttons = uiGames[currentStep].GetComponentsInChildren<Button>();
|
|
}
|
|
|
|
// 调用这个方法来返回上一个步骤
|
|
public void PreviousStep()
|
|
{
|
|
if (currentStep > 0)
|
|
{
|
|
for (int i = 0; i < uiGames.Length; i++)
|
|
{
|
|
uiGames[i].SetActive(false);
|
|
}
|
|
|
|
var item = carSelectTypeInfo.ElementAt(carSelectTypeInfo.Count - 1);
|
|
carSelectTypeInfo.Remove(item.Key);
|
|
|
|
currentStep--;
|
|
uiGames[currentStep].SetActive(true);
|
|
}
|
|
|
|
uiGames[currentStep].transform.GetChild(0).GetComponent<BtClick>().OnClickSprite();
|
|
GetComponent<SteeringWheelController>().buttons = uiGames[currentStep].GetComponentsInChildren<Button>();
|
|
}
|
|
} |