修复无法点击按钮问题
This commit is contained in:
@@ -9,9 +9,7 @@ namespace GameFramework
|
||||
/// 场景异步加载器(持久化单例)。带黑色淡入淡出过渡。
|
||||
/// 场景名可在 Inspector 配置,默认 MainMenu / Gameplay / Scoring。
|
||||
///
|
||||
/// 搭建:把 SceneLoader 挂到一个空物体上(放第一个场景 MainMenu 里),
|
||||
/// 它会 DontDestroyOnLoad。transitionImage 是它子物体 Canvas 上的 Image(全屏黑),
|
||||
/// Canvas 设为 Screen Space - Overlay、sortingOrder 设很高(如 9999)。
|
||||
/// 修复:协程结束后将 isLoading 重置为 false,允许后续加载。
|
||||
/// </summary>
|
||||
public class SceneLoader : PersistentSingleton<SceneLoader>
|
||||
{
|
||||
@@ -19,7 +17,7 @@ namespace GameFramework
|
||||
[SerializeField] private Image transitionImage;
|
||||
[SerializeField] private float fadeTime = 1.5f;
|
||||
|
||||
[Header("场景名(按你工程里的实际名称填)")]
|
||||
[Header("场景名(按你工程中的实际名称填)")]
|
||||
[SerializeField] private string mainMenuScene = "MainMenu";
|
||||
[SerializeField] private string gameplayScene = "Gameplay";
|
||||
[SerializeField] private string scoringScene = "Scoring";
|
||||
@@ -27,34 +25,14 @@ namespace GameFramework
|
||||
private Color color;
|
||||
private bool isLoading = false;
|
||||
|
||||
public void LoadGameplayScene()
|
||||
{
|
||||
// 重置 GameManager 状态
|
||||
if (GameManager.Instance != null)
|
||||
{
|
||||
GameManager.GameState = GameState.Playing;
|
||||
GameManager.onGameOver = null;
|
||||
GameManager.onGameWin = null;
|
||||
}
|
||||
// 重置 ScoreManager
|
||||
if (ScoreManager.Instance != null)
|
||||
ScoreManager.Instance.ResetScore();
|
||||
// 清理静态事件残留订阅
|
||||
IndianOceanAssets.Engine2_5D.HealthSystem.onPlayerDamaged = null;
|
||||
|
||||
Load(gameplayScene);
|
||||
}
|
||||
public void LoadGameplayScene() => Load(gameplayScene);
|
||||
public void LoadMainMenuScene() => Load(mainMenuScene);
|
||||
public void LoadScoringScene() => Load(scoringScene);
|
||||
public void Load(string sceneName)
|
||||
{
|
||||
if (isLoading)
|
||||
{
|
||||
Debug.LogWarning($"[SceneLoader] 上次加载未完成,强制重置并加载: {sceneName}");
|
||||
StopAllCoroutines();
|
||||
isLoading = false;
|
||||
}
|
||||
if (isLoading) return;
|
||||
isLoading = true;
|
||||
StopAllCoroutines();
|
||||
StartCoroutine(LoadingCoroutine(sceneName));
|
||||
}
|
||||
|
||||
@@ -67,16 +45,7 @@ namespace GameFramework
|
||||
"拖到 SceneLoader 的 transitionImage 字段。");
|
||||
}
|
||||
|
||||
Debug.Log($"[SceneLoader] 开始加载场景: {sceneName}");
|
||||
var loadingOperation = SceneManager.LoadSceneAsync(sceneName);
|
||||
|
||||
if (loadingOperation == null)
|
||||
{
|
||||
Debug.LogError($"[SceneLoader] 场景 '{sceneName}' 加载失败!请检查 Build Settings 中是否包含该场景。");
|
||||
isLoading = false;
|
||||
yield break;
|
||||
}
|
||||
|
||||
loadingOperation.allowSceneActivation = false;
|
||||
|
||||
if (transitionImage != null)
|
||||
@@ -123,7 +92,7 @@ namespace GameFramework
|
||||
transitionImage.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
Debug.Log($"[SceneLoader] 场景加载完成: {sceneName}");
|
||||
// 加载完成,重置标志,允许下一次加载
|
||||
isLoading = false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user