MoTaForPSVita/Assets/Scripts/Controller/UI/HomeCanvasController.cs

76 lines
1.7 KiB
C#
Raw Permalink Normal View History

2024-04-30 17:39:50 +08:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class HomeCanvasController : MonoBehaviour
{
private Button newGameButton;
private Button loadGameButton;
private Button exitGameButton;
2024-09-22 01:06:18 +08:00
private Text txtSaveDate;
2024-04-30 17:39:50 +08:00
private void Awake()
{
newGameButton = transform.Find("Panel").Find("NewGameButton").GetComponent<Button>();
loadGameButton = transform.Find("Panel").Find("LoadGameButton").GetComponent<Button>();
exitGameButton = transform.Find("Panel").Find("ExitGameButton").GetComponent<Button>();
2024-09-22 01:06:18 +08:00
txtSaveDate = transform.Find("Panel").Find("txtSaveDate").GetComponent<Text>();
2024-04-30 17:39:50 +08:00
newGameButton.onClick.AddListener(() => { NewGameEvent(); });
loadGameButton.onClick.AddListener(() => { LoadGameEvent(); });
exitGameButton.onClick.AddListener(ExitGameEvent);
}
2024-04-30 17:39:50 +08:00
2024-09-22 01:06:18 +08:00
void OnEnable()
{
// 加载游戏存档
if (!ResourceManager.Instance.GetGameArchiveStatus())
{
txtSaveDate.text = "没有存档";
}
else
{
txtSaveDate.text = ResourceManager.Instance.GetSaveDateTime();
}
}
/// <summary>
/// 新游戏
/// </summary>
public void NewGameEvent()
{
// 设置标识符
PlayerPrefs.SetInt("NewGame", 1);
// 加载场景
SceneManager.LoadScene("Level");
}
2024-04-30 17:39:50 +08:00
/// <summary>
/// 加载游戏
/// </summary>
public void LoadGameEvent()
{
// 加载游戏存档
if (ResourceManager.Instance.GetGameArchiveStatus())
{
SceneManager.LoadScene("Level");
}
2024-04-30 17:39:50 +08:00
}
/// <summary>
/// 退出游戏
/// </summary>
public void ExitGameEvent()
{
2024-04-30 17:39:50 +08:00
#if UNITY_EDITOR
UnityEditor.EditorApplication.isPlaying = false;
2024-04-30 17:39:50 +08:00
#else
Application.Quit();
#endif
}
2024-04-30 17:39:50 +08:00
}