FixSystemCenter.OnSingletonDestroy 在场景销毁阶段访问的 CameraKit、 BubbleSlotKit 可能已清理,且 Director.QuitCurrentMode 协程依赖的 对象可能已拆除。改为判空访问,并新增 Director.Reset 直接清理状态。
98 lines
2.9 KiB
C#
98 lines
2.9 KiB
C#
using System;
|
|
using System.Collections;
|
|
using AibisDream;
|
|
using AibisDream.Framework;
|
|
using AibisDream.Kit;
|
|
using AibisDream.SaveSystem;
|
|
using UnityEngine;
|
|
|
|
namespace AibisDream.FixSystem
|
|
{
|
|
public class FixSystemCenter : Singleton<FixSystemCenter>, ISceneDialogueGate
|
|
{
|
|
public FixSceneMode CurrentMode => Director.CurrentMode;
|
|
|
|
public FixSceneMode defaultMode = FixSceneMode.Default;
|
|
|
|
public bool IsDirectorReady { get; private set; }
|
|
|
|
public bool IsDialogueReady => IsDirectorReady;
|
|
|
|
public static IOCContainer SystemDic = new();
|
|
public static FixSceneContext Context;
|
|
public static FixSceneDirector Director;
|
|
|
|
public override void OnSingletonInit()
|
|
{
|
|
SystemDic ??= new IOCContainer();
|
|
Context = new FixSceneContext(SystemDic);
|
|
Director = new FixSceneDirector();
|
|
IsDirectorReady = false;
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
if (SaveRestoreOrchestrator.IsRestoring)
|
|
{
|
|
return;
|
|
}
|
|
|
|
StartCoroutine(InitDirectorRoutine());
|
|
}
|
|
|
|
private IEnumerator InitDirectorRoutine()
|
|
{
|
|
IsDirectorReady = false;
|
|
yield return Director.Init(defaultMode);
|
|
IsDirectorReady = true;
|
|
}
|
|
|
|
public override void OnSingletonDestroy()
|
|
{
|
|
IsDirectorReady = false;
|
|
CameraKit.Instance?.RemoveAllCam();
|
|
BubbleSlotKit.Instance?.RemoveAll();
|
|
Director?.Reset();
|
|
Context?.Clear();
|
|
}
|
|
|
|
public IEnumerator TransitionTo(FixSceneMode nextMode, string args = "")
|
|
{
|
|
yield return Director.TransitionTo(nextMode, args);
|
|
}
|
|
|
|
public IEnumerator TransitionToImmediate(FixSceneMode nextMode, string args = "")
|
|
{
|
|
yield return Director.TransitionToImmediate(nextMode, args);
|
|
}
|
|
|
|
/// <summary>Captures the macro Fix scene cue snapshot.</summary>
|
|
public FixSnapshotDto CaptureSnapshot()
|
|
{
|
|
return new FixSnapshotDto
|
|
{
|
|
state = Director.CurrentMode.ToString(),
|
|
args = Director.CurrentArgs
|
|
};
|
|
}
|
|
|
|
/// <summary>Restores the macro Fix scene snapshot by jumping directly to the target cue endpoint.</summary>
|
|
public IEnumerator RestoreSnapshot(FixSnapshotDto dto)
|
|
{
|
|
if (dto == null || string.IsNullOrEmpty(dto.state))
|
|
{
|
|
yield break;
|
|
}
|
|
|
|
if (!Enum.TryParse<FixSceneMode>(dto.state, out var mode))
|
|
{
|
|
Debug.LogWarning($"[FixSystemCenter] Could not parse FixSceneMode: {dto.state}");
|
|
yield break;
|
|
}
|
|
|
|
yield return Director.TransitionToImmediate(mode, dto.args ?? "");
|
|
IsDirectorReady = true;
|
|
}
|
|
}
|
|
}
|