H_SafeExperienceDrivingSystem/U3D_DrivingSystem/Assets/Script/Manaegr/GameManager.cs

200 lines
5.0 KiB
C#

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<BtClick> home; //首页
//
// // public List<BtClick> carType; //车类型
// public List<BtClick> weather; //天气
// public List<BtClick> dangerDriving; //危险驾驶
public GameObject[] uiGames;
public Button[] btList = new Button[] { };
private List<string> stepValues = new List<string>(); // 保存每个步骤的值
private int currentStep = 0; // 当前步骤索引
private CarType carType;
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., "");
}
// 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 SceneBts()
{
Button[] buttonArray = new Button[] { };
switch (carType)
{
case CarType.:
buttonArray = uiGames[0].GetComponentsInChildren<Button>();
break;
case CarType.:
break;
case CarType.:
buttonArray = uiGames[1].GetComponentsInChildren<Button>();
break;
case CarType.:
buttonArray = uiGames[2].GetComponentsInChildren<Button>();
break;
}
btList = buttonArray;
}
public void UIClick(CarType ct, string btName)
{
carType = ct;
SceneBts();
for (int i = 0; i < btList.Length; i++)
{
if (btList[i].name == btName)
{
btList[i].GetComponent<BtClick>().OnClickSprite();
}
else
{
btList[i].GetComponent<BtClick>().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();
uiGames[currentStep].transform.GetChild(0).GetComponent<BtClick>().OnClickSprite();
// Debug.Log(uiGames[currentStep].transform.GetChild(0).GetComponent<Button>());
GetComponent<SteeringWheelController>().buttons = btList;
}
// 调用这个方法来返回上一个步骤
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();
}
uiGames[currentStep].transform.GetChild(0).GetComponent<BtClick>().OnClickSprite();
}
private void DisplayCurrentStepValue()
{
if (currentStep < stepValues.Count)
{
Debug.Log("Current Step: " + currentStep + ", Value: " + stepValues[currentStep]);
}
else
{
Debug.Log("Current Step: " + currentStep + ", No Value Yet");
}
}
}