62 lines
1.7 KiB
C#
62 lines
1.7 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace AibisDream
|
|
{
|
|
public class SaveFileUIController : MonoBehaviour
|
|
{
|
|
private static readonly string SaveFilePath = Application.streamingAssetsPath + "/SaveFiles";
|
|
|
|
#region 索引
|
|
public Button buttonPrefab;
|
|
public Transform buttonParent;
|
|
public Button returnButton;
|
|
#endregion
|
|
|
|
private void Start()
|
|
{
|
|
returnButton.onClick.AddListener(HideSaveFileUI);
|
|
}
|
|
|
|
public void ShowSaveFileUI()
|
|
{
|
|
// 清空旧按钮
|
|
foreach (Transform child in buttonParent)
|
|
{
|
|
Destroy(child.gameObject);
|
|
}
|
|
|
|
// 加载存档文件
|
|
string[] saveFiles = Directory.GetFiles(SaveFilePath, "*.json");
|
|
var orderedSaveFiles = saveFiles.OrderByDescending(item => item).ToArray();
|
|
foreach (var saveFile in orderedSaveFiles)
|
|
{
|
|
var button = Instantiate(buttonPrefab, buttonParent);
|
|
button.GetComponentInChildren<TMP_Text>().text = Path.GetFileNameWithoutExtension(saveFile);
|
|
button.onClick.AddListener(() => OnSaveFileSelected(saveFile));
|
|
}
|
|
|
|
gameObject.SetActive(true);
|
|
}
|
|
|
|
private void OnSaveFileSelected(string saveFileName)
|
|
{
|
|
// 隐藏UI
|
|
gameObject.SetActive(false);
|
|
// 开始游戏
|
|
// GameLoopManager.Instance.StartWithSaveFile(saveFileName);
|
|
}
|
|
|
|
public void HideSaveFileUI()
|
|
{
|
|
gameObject.SetActive(false);
|
|
}
|
|
}
|
|
}
|
|
|