131 lines
4.5 KiB
C#
131 lines
4.5 KiB
C#
using System;
|
|
using System.Threading;
|
|
using Cysharp.Threading.Tasks;
|
|
using DG.Tweening;
|
|
using Stary.Evo;
|
|
using Stary.Evo.AudioCore;
|
|
using Stary.Evo.InformationSave;
|
|
using Stary.Evo.TableTextConversion;
|
|
using Stary.Evo.UIFarme;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using YooAsset;
|
|
|
|
namespace Main
|
|
{
|
|
public class TextPanel : BasePanel
|
|
{
|
|
static readonly string path = "TextPanel";
|
|
|
|
private TextMeshProUGUI intro;
|
|
|
|
private LocalTransformInfo transformInfo;
|
|
|
|
|
|
public TextPanel()
|
|
{
|
|
}
|
|
|
|
|
|
public override void Initialize(GameObject panelGo)
|
|
{
|
|
base.Initialize(panelGo);
|
|
|
|
intro = activePanel.transform.Find("Intro").GetComponent<TextMeshProUGUI>();
|
|
transformInfo = activePanel.transform.GetComponent<LocalTransformInfo>();
|
|
intro.text = "";
|
|
|
|
intro.overflowMode = TextOverflowModes.Overflow; // 启用溢出模式
|
|
|
|
intro.GetComponent<CanvasGroup>().alpha = 0;
|
|
}
|
|
|
|
public override void OnEnter()
|
|
{
|
|
base.OnEnter();
|
|
|
|
this.RegisterEvent<IntroType, string, float, string>(IntroType.SetText, OnSetTextIntroEvent);
|
|
this.RegisterEvent<IntroType, string, string>(IntroType.SetTextSubtitle, OnSetTextIntroEvent);
|
|
}
|
|
|
|
public override void OnExit(float delay = 0)
|
|
{
|
|
base.OnExit(delay);
|
|
intro.text = "";
|
|
this.UnRegisterEvent<IntroType, string, float, string>(IntroType.SetText, OnSetTextIntroEvent);
|
|
this.UnRegisterEvent<IntroType, string, string>(IntroType.SetTextSubtitle, OnSetTextIntroEvent);
|
|
}
|
|
|
|
|
|
public async void OnSetTextIntroEvent(string text, float audioLength, string desc)
|
|
{
|
|
try
|
|
{
|
|
float delay = audioLength / (float)text.Length / 2;
|
|
for (int i = 0; i < text.Length; i++)
|
|
{
|
|
intro.text += text[i];
|
|
await UniTask.Delay(TimeSpan.FromSeconds(delay),
|
|
cancellationToken: CancellationTokenCore.Instance.CancellationTokenSource(path));
|
|
}
|
|
}
|
|
catch (OperationCanceledException)
|
|
{
|
|
Debug.Log($"ComponentExtensions:【{path}】异步任务被取消");
|
|
}
|
|
|
|
intro.ForceMeshUpdate();
|
|
transformInfo.Set(desc);
|
|
}
|
|
|
|
public async void OnSetTextIntroEvent(string UIid, string desc)
|
|
{
|
|
var messageInfo = this.GetData<IAudioTableData>().GetUIInfo(UIid);
|
|
if (messageInfo != null)
|
|
{
|
|
if (messageInfo.subtitle.Count > 0)
|
|
{
|
|
foreach (var subtitle in messageInfo.subtitle)
|
|
{
|
|
intro.text = "";
|
|
//float delay = (float)(subtitle.end - subtitle.start) /subtitle.subtitle.Length /2 ;
|
|
intro.GetComponent<CanvasGroup>().DOFade(1, 0.2f);
|
|
|
|
intro.text = subtitle.subtitle;
|
|
// for (int i = 0; i < subtitle.subtitle.Length; i++)
|
|
// {
|
|
// intro.text += subtitle.subtitle[i];
|
|
// await UniTask.Delay(TimeSpan.FromSeconds(delay),
|
|
// cancellationToken: tokenSource.Token);
|
|
// }
|
|
try
|
|
{
|
|
await UniTask.Delay(TimeSpan.FromSeconds((float)(subtitle.end - subtitle.start)),
|
|
cancellationToken: CancellationTokenCore.Instance.CancellationTokenSource(path));
|
|
intro.GetComponent<CanvasGroup>().DOFade(0, 0.2f);
|
|
await UniTask.Delay(TimeSpan.FromSeconds(0.2f),
|
|
cancellationToken: CancellationTokenCore.Instance.CancellationTokenSource(path));
|
|
}
|
|
catch (OperationCanceledException)
|
|
{
|
|
Debug.Log($"ComponentExtensions:【{path}】异步任务被取消");
|
|
}
|
|
}
|
|
}
|
|
|
|
transformInfo.Set(desc);
|
|
}
|
|
else
|
|
{
|
|
Debug.LogError($"UnityEvo:【{UIid}】没有找到对应的UI信息");
|
|
}
|
|
}
|
|
|
|
public enum IntroType
|
|
{
|
|
SetText,
|
|
SetTextSubtitle,
|
|
}
|
|
}
|
|
} |