You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.6 KiB
50 lines
1.6 KiB
3 years ago
|
using UnityEngine;
|
||
|
using System.Collections;
|
||
|
using UnityEngine.UI;
|
||
|
using System.Collections.Generic;
|
||
|
public class SceneKindSelect : MonoBehaviour {
|
||
|
|
||
|
/// <summary>
|
||
|
/// 多种类场景选择
|
||
|
/// </summary>
|
||
|
private Button SureBtn;
|
||
|
private Button CloseBtn;
|
||
|
private GameObject Parent;
|
||
|
|
||
|
public void GetStringList(ref Dictionary<string,string> kinds)
|
||
|
{
|
||
|
SureBtn = transform.Find("Sure").GetComponent<Button>();
|
||
|
CloseBtn = transform.Find("Close").GetComponent<Button>();
|
||
|
Parent = transform.Find("SceneSelect/Viewport/Content").gameObject;
|
||
|
SureBtn.onClick.AddListener(Sure);
|
||
|
CloseBtn.onClick.AddListener(Close);
|
||
|
|
||
|
foreach (KeyValuePair<string, string> kvp in kinds)
|
||
|
{
|
||
|
GameObject sceneChose = Instantiate(Resources.Load<GameObject>("UIPrefab/SceneChose"));
|
||
|
sceneChose.transform.SetParent(Parent.transform);
|
||
|
sceneChose.transform.localScale = new Vector3(1, 1, 1);
|
||
|
sceneChose.GetComponent<Toggle>().group = Parent.GetComponent<ToggleGroup>();
|
||
|
sceneChose.GetComponent<Scenekinds>().kindsNumber = kvp.Key;
|
||
|
sceneChose.GetComponent<Scenekinds>().GetComponentInChildren<Text>().text = kvp.Value;
|
||
|
}
|
||
|
kinds.Clear();
|
||
|
}
|
||
|
public void Sure()
|
||
|
{
|
||
|
foreach (Transform child in Parent.transform)
|
||
|
{
|
||
|
if (child.GetComponent<Toggle>().isOn)
|
||
|
{
|
||
|
MySceneManager.MyLoadScene(child.GetComponent<Scenekinds>().kindsNumber);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
public void Close()
|
||
|
{
|
||
|
Destroy(gameObject);
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|