116 lines
3.0 KiB
C#
116 lines
3.0 KiB
C#
using System;
|
|
using System.Threading.Tasks;
|
|
using AibisDream.Kit;
|
|
using AibisDream.Utility;
|
|
using UnityEngine;
|
|
using Yarn.Unity;
|
|
|
|
namespace AibisDream
|
|
{
|
|
public class LineViewNew : DialogueViewBase
|
|
{
|
|
[SerializeField] private LineAdvanceInput advanceInput;
|
|
// [SerializeField] private BubbleCenter bubbleCenter;
|
|
|
|
public override void RunLine(LocalizedLine dialogueLine, Action onDialogueLineFinished)
|
|
{
|
|
// 预处理Line和Event
|
|
var lineSyncEvent = new LineSyncToken(dialogueLine, onDialogueLineFinished);
|
|
// bubbleCenter.RunLine(lineSyncEvent);
|
|
advanceInput.RunLine(lineSyncEvent);
|
|
}
|
|
}
|
|
|
|
public class LineSyncToken
|
|
{
|
|
public LineInfo lineInfo;
|
|
public LineSyncState state;
|
|
|
|
public Action nextStep;
|
|
public event Action SkipTextAnima;
|
|
|
|
public LineSyncToken(LocalizedLine lineInfo, Action nextStep)
|
|
{
|
|
this.lineInfo = LineInfo.Generate(lineInfo);
|
|
this.nextStep = nextStep;
|
|
state = LineSyncState.PlayText;
|
|
}
|
|
|
|
public bool TrySkip()
|
|
{
|
|
if (state == LineSyncState.PlayText)
|
|
{
|
|
SkipTextAnima?.Invoke();
|
|
SkipTextAnima = null;
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
Debug.Log($"line{lineInfo.lineId} 状态为{state.ToString()}, 不能跳过文本");
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public bool TryAdvance()
|
|
{
|
|
if (state == LineSyncState.WaitForAdvance)
|
|
{
|
|
nextStep?.Invoke();
|
|
state = LineSyncState.Advanced;
|
|
Dispose();
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
Debug.Log($"line{lineInfo.lineId} 状态为{state.ToString()}, 不能向前推进");
|
|
return false;
|
|
}
|
|
}
|
|
|
|
private void Dispose()
|
|
{
|
|
nextStep = null;
|
|
SkipTextAnima = null;
|
|
}
|
|
|
|
public void TextStart()
|
|
{
|
|
state = LineSyncState.PlayText;
|
|
}
|
|
|
|
public void TextShown()
|
|
{
|
|
state = LineSyncState.AdvanceDelay;
|
|
// 延时
|
|
|
|
state = LineSyncState.WaitForAdvance;
|
|
}
|
|
}
|
|
|
|
public struct LineInfo
|
|
{
|
|
public string lineId;
|
|
public string lineText;
|
|
public CharacterVo character;
|
|
public bool isAutoSkip;
|
|
|
|
public static LineInfo Generate(LocalizedLine dialogueLine)
|
|
{
|
|
return new LineInfo
|
|
{
|
|
lineId = dialogueLine.TextID,
|
|
lineText = dialogueLine.TextWithoutCharacterName.Text,
|
|
character = dialogueLine.GetCharacterVo(),
|
|
isAutoSkip = dialogueLine.IsAutoSkipLine()
|
|
};
|
|
}
|
|
}
|
|
|
|
public enum LineSyncState
|
|
{
|
|
PlayText,
|
|
AdvanceDelay,
|
|
WaitForAdvance,
|
|
Advanced
|
|
}
|
|
} |