增加skill、加入界面基础加载
This commit is contained in:
1 parent
839165ea63
commit
5921a4884e
128 files changed
+17935
-5023
No files matched your search
@@ -0,0 +1,54 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
/// <summary>
|
||||
/// Main 启动页。
|
||||
/// 点击事件在 Button 的 On Click() 里接线(Inspector 配置),代码里不查找节点。
|
||||
/// </summary>
|
||||
public class MainMenu : MonoBehaviour
|
||||
{
|
||||
[Tooltip("点「启动」后要加载的场景名,必须已经加进 Build Settings")]
|
||||
[SerializeField] private string startSceneName = "Start";
|
||||
|
||||
private bool _loading;
|
||||
|
||||
/// <summary>启动:加载目标场景,加载完成后卸载 Main 场景自己。</summary>
|
||||
public void OnStartClicked()
|
||||
{
|
||||
if (_loading) return; // 防连点,避免同时加载出两份
|
||||
_loading = true;
|
||||
StartCoroutine(LoadThenUnloadSelf());
|
||||
}
|
||||
|
||||
/// <summary>退出游戏。</summary>
|
||||
public void OnExitClicked()
|
||||
{
|
||||
Application.Quit();
|
||||
#if UNITY_EDITOR
|
||||
// 编辑器里 Application.Quit 不生效,方便本地测试
|
||||
UnityEditor.EditorApplication.isPlaying = false;
|
||||
#endif
|
||||
}
|
||||
|
||||
private IEnumerator LoadThenUnloadSelf()
|
||||
{
|
||||
Scene mainScene = gameObject.scene;
|
||||
|
||||
AsyncOperation load = SceneManager.LoadSceneAsync(startSceneName, LoadSceneMode.Additive);
|
||||
if (load == null)
|
||||
{
|
||||
Debug.LogError("[MainMenu] 场景 \"" + startSceneName + "\" 加载失败,确认它已加入 Build Settings。", this);
|
||||
_loading = false;
|
||||
yield break;
|
||||
}
|
||||
|
||||
yield return load; // 等目标场景加载完成
|
||||
|
||||
Scene loaded = SceneManager.GetSceneByName(startSceneName);
|
||||
if (loaded.IsValid())
|
||||
SceneManager.SetActiveScene(loaded);
|
||||
|
||||
SceneManager.UnloadSceneAsync(mainScene); // 加载完成后卸载 Main
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user