修正 UIManager 运行时销毁逻辑

This commit is contained in:
JSD\13999
2026-05-19 20:31:04 +08:00
parent a51145ae2c
commit 436cf6ef56
2 changed files with 5 additions and 3 deletions

View File

@@ -92,7 +92,7 @@ namespace FlowScope.UI
{ {
if (instance != null) if (instance != null)
{ {
UnityEngine.Object.DestroyImmediate(instance); UnityEngine.Object.Destroy(instance);
} }
handle.Dispose(); handle.Dispose();
@@ -184,7 +184,7 @@ namespace FlowScope.UI
} }
layer.RemoveCached(record.PanelType); layer.RemoveCached(record.PanelType);
UnityEngine.Object.DestroyImmediate(record.Panel.gameObject); UnityEngine.Object.Destroy(record.Panel.gameObject);
record.Handle.Dispose(); record.Handle.Dispose();
} }

View File

@@ -104,8 +104,9 @@ namespace FlowScope.Tests.PlayMode.UI
Assert.That(panel.UnbindCount, Is.EqualTo(1)); Assert.That(panel.UnbindCount, Is.EqualTo(1));
Assert.That(handle.IsDisposed, Is.True); Assert.That(handle.IsDisposed, Is.True);
Assert.That(panel == null, Is.True);
Assert.That(manager.IsOpen<ExplicitPathPanel>(), Is.False); Assert.That(manager.IsOpen<ExplicitPathPanel>(), Is.False);
yield return null;
Assert.That(panel == null, Is.True);
} }
[UnityTest] [UnityTest]
@@ -172,6 +173,7 @@ namespace FlowScope.Tests.PlayMode.UI
() => manager.OpenAsync<ThrowingBindPanel, TestViewModel>(new TestViewModel("boom"), CancellationToken.None)); () => manager.OpenAsync<ThrowingBindPanel, TestViewModel>(new TestViewModel("boom"), CancellationToken.None));
Assert.That(resources.Handles[0].IsDisposed, Is.True); Assert.That(resources.Handles[0].IsDisposed, Is.True);
yield return null;
Assert.That(canvas.transform.childCount, Is.EqualTo(0)); Assert.That(canvas.transform.childCount, Is.EqualTo(0));
Assert.That(manager.IsOpen<ThrowingBindPanel>(), Is.False); Assert.That(manager.IsOpen<ThrowingBindPanel>(), Is.False);
} }