This commit is contained in:
CortexCore
2023-06-19 09:03:04 +08:00
parent acdbe54f79
commit 254e8ccde8
2 changed files with 132 additions and 3 deletions

View File

@@ -20,7 +20,7 @@ public partial class PlaybackService : UXPanel
[Export] private PackedScene template;
[Export] private PackedScene labelTemplate;
[Export] private DataPlayer dataPlayer;
private CancellationTokenSource cancellationTokenSource;
public PlaybackService()
{
BITApp.ServiceCollection.AddSingleton(this);
@@ -28,11 +28,17 @@ public partial class PlaybackService : UXPanel
public override void _Ready()
{
cancellationTokenSource = new CancellationTokenSource();
OnExit();
}
public override void _ExitTree()
{
cancellationTokenSource.Cancel();
}
public override void OnEntry()
{
cancellationTokenSource.Token.ThrowIfCancellationRequested();
var files =
new DirectoryInfo(PathHelper.GetFolderPath("Demos", GetTree().CurrentScene.Name))
.GetFiles()
@@ -62,8 +68,18 @@ public partial class PlaybackService : UXPanel
await UniTask.SwitchToTaskPool();
var array = BITAssets.Read<string[]>(x.FullName, "base64");
try
{
await UniTask.SwitchToSynchronizationContext(BITApp.SynchronizationContext,
cancellationTokenSource.Token);
}
catch (OperationCanceledException)
{
stopwatch.Stop();
return;
}
await UniTask.SwitchToSynchronizationContext(BITApp.SynchronizationContext);
stopwatch.Stop();
BIT4Log.Log<PlaybackService>($"已加载:{playableInfo.Name},耗时:{stopwatch.ElapsedMilliseconds}ms");