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

70 lines
1.7 KiB
C#
Raw 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-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-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
/// <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");
// UI 提示
GameManager.Instance.UIManager.ShowInfo("已读档!");
// 音频播放
GameManager.Instance.SoundManager.PlaySound(ESoundType.Effect, "Save");
}
else
{
// UI 提示
GameManager.Instance.UIManager.ShowInfo("未发现存档!");
GameManager.Instance.SoundManager.PlaySound(ESoundType.Effect, "No");
}
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
}