Files
plugin-library/Assets/Main/HotfixUpdateScript/Runtime/HotUpdate/LasterDoMain/VideoTableData.cs
2025-07-02 10:05:26 +08:00

63 lines
1.9 KiB
C#

using System;
using System.Threading;
using Cysharp.Threading.Tasks;
using Stary.Evo;
using UnityEngine;
using YooAsset;
namespace Main
{
public interface IVideoTableData : IData
{
UniTask LoadData(string videotabledata_asset);
Stary.Evo.TableTextConversion.VideoTableData.MessageInfo PlayVideoName(string vidid);
}
public class VideoTableData : AbstractData, IVideoTableData
{
private Stary.Evo.TableTextConversion.VideoTableData videoTableDatas;
private CancellationTokenSource _cancellationTokenSource;
protected override async void OnInit()
{
}
public async UniTask LoadData(string videotabledata_asset)
{
_cancellationTokenSource = new CancellationTokenSource();
var handle = YooAssets.LoadAssetAsync<Stary.Evo.TableTextConversion.VideoTableData>(videotabledata_asset);
await handle.WithCancellation(this._cancellationTokenSource.Token);
videoTableDatas = handle.GetAssetObject<Stary.Evo.TableTextConversion.VideoTableData>();
}
public Stary.Evo.TableTextConversion.VideoTableData.MessageInfo PlayVideoName(string vidid)
{
var info = videoTableDatas.infos.Find(x => x.vidid == vidid);
if (info != null && !info.filename.Contains("Video"))
{
info.filename = "Video_" + info.filename;
}
return info;
}
public override void Dispose()
{
try
{
if (_cancellationTokenSource != null && !_cancellationTokenSource.IsCancellationRequested)
{
_cancellationTokenSource.Cancel();
_cancellationTokenSource.Dispose();
}
}
catch (OperationCanceledException e)
{
Debug.Log("异步取消操作");
}
}
}
}