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

101 lines
2.6 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Script;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public enum CarType
{
,
,
,
}
public class MenuManager : MonoBehaviour
{
public static MenuManager instance;
public GameObject[] uiGames;
private int currentStep = 0; // 当前步骤索引
private void Awake()
{
instance = this;
}
private void Start()
{
GetComponent<SteeringWheelController>().buttons = uiGames[currentStep].GetComponentsInChildren<Button>();
GetComponent<SteeringWheelController>().HighlightButton(0);
GameInfo.instance.carSelectTypeInfo.Clear();
}
public void OnBtClick(CarType carType, string btName)
{
GameInfo.instance.carSelectTypeInfo.Add(carType, btName);
NextStep();
if (GameInfo.instance.carSelectTypeInfo.Count() == 1)
{
SceneManager.LoadScene("main_");
}
foreach (var v in GameInfo.instance.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);
}
if (GameInfo.instance.carSelectTypeInfo.Count > 0)
{
var item = GameInfo.instance.carSelectTypeInfo.ElementAt(GameInfo.instance.carSelectTypeInfo.Count - 1);
GameInfo.instance.carSelectTypeInfo.Remove(item.Key);
}
currentStep--;
uiGames[currentStep].SetActive(true);
}
uiGames[currentStep].transform.GetChild(0).GetComponent<BtClick>().OnClickSprite();
GetComponent<SteeringWheelController>().buttons = uiGames[currentStep].GetComponentsInChildren<Button>();
}
}