65 lines
1.8 KiB
C#
65 lines
1.8 KiB
C#
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
|
|
namespace AibisDream
|
|
{
|
|
public class SceneSelectionUIController : MonoBehaviour
|
|
{
|
|
[Header("UI References")]
|
|
public GameObject panel; // 用于显示选择界面的面板
|
|
public Button buttonPrefab; // 按钮预制体
|
|
public Transform buttonParent; // 按钮容器,用来放置动态创建的按钮
|
|
|
|
public Button returnButton;
|
|
|
|
private void Start()
|
|
{
|
|
// 确保场景选择面板开始时是隐藏的
|
|
panel.SetActive(false);
|
|
}
|
|
|
|
public void ShowSceneSelection(TalkSceneSO[] sceneSos)
|
|
{
|
|
// 清空当前的按钮
|
|
foreach (Transform child in buttonParent)
|
|
{
|
|
Destroy(child.gameObject);
|
|
}
|
|
|
|
// 动态创建按钮
|
|
foreach (var sceneSo in sceneSos)
|
|
{
|
|
Button button = Instantiate(buttonPrefab, buttonParent);
|
|
button.GetComponentInChildren<TMP_Text>().text = sceneSo.nameToPlayer;
|
|
button.onClick.AddListener(() => OnSceneSelected(sceneSo));
|
|
returnButton.onClick.AddListener(() => close());
|
|
}
|
|
|
|
// 显示选择面板
|
|
panel.SetActive(true);
|
|
}
|
|
|
|
private void OnSceneSelected(TalkSceneSO selectedScene)
|
|
{
|
|
// 在场景管理器中加载选定的场景
|
|
GameLoopManager.Instance.StartWithTalkSceneSO(selectedScene);
|
|
panel.SetActive(false); // 隐藏选择面板
|
|
|
|
}
|
|
private void close()
|
|
{
|
|
panel.SetActive(false);
|
|
}
|
|
private void Update() {
|
|
|
|
if (Input.GetKeyDown(KeyCode.A) && Input.GetKey(KeyCode.L))
|
|
{
|
|
DialogController.Instance.StopDialog();
|
|
ShowSceneSelection(GameLoopManager.Instance.totalSceneSos);
|
|
}
|
|
}
|
|
}
|
|
}
|