文本系统重做完成

This commit is contained in:
2025-11-12 20:00:18 +08:00
parent 845ac9cc27
commit ef260e5d43
18 changed files with 311 additions and 293 deletions
@@ -13,8 +13,6 @@ namespace AibisDream
[SerializeField] private LineAdvanceInput lineAdvanceInput;
public AdvanceMode advanceMode;
private void Start()
{
_dialogueRunner = GetComponentInChildren<DialogueRunner>();
@@ -33,11 +31,17 @@ namespace AibisDream
private void OnEnable()
{
EnumEventSystem.Global.Register(GameLoopEnum.GameStart, ResetAdvanceMode);
EnumEventSystem.Global.Register(DialogEventEnum.OptionShow, OnOptionShow);
EnumEventSystem.Global.Register<DialogEventEnum, LineInfo>(DialogEventEnum.OptionSelected, OnOptionSelected);
}
private void OnDisable()
{
EnumEventSystem.Global.UnRegister(GameLoopEnum.GameStart, ResetAdvanceMode);
EnumEventSystem.Global.UnRegister(DialogEventEnum.OptionShow, OnOptionShow);
EnumEventSystem.Global.UnRegister<DialogEventEnum, LineInfo>(DialogEventEnum.OptionSelected, OnOptionSelected);
}
private void ResetAdvanceMode()
@@ -48,6 +52,9 @@ namespace AibisDream
isQuick = false
};
isInOption = false;
lineSyncToken = null;
Time.timeScale = 1f;
lineAdvanceInput.ResetAdvanceMode();
}
@@ -113,6 +120,8 @@ namespace AibisDream
#region
public AdvanceMode advanceMode;
public void SwitchAutoMode()
{
advanceMode.isAuto = !advanceMode.isAuto;
@@ -128,8 +137,36 @@ namespace AibisDream
}
#endregion
}
public LineSyncToken lineSyncToken;
public bool isInOption;
public LineSyncState GetDialogState()
{
if (lineSyncToken != null && lineSyncToken.state != LineSyncState.Advanced)
{
return lineSyncToken.state;
}
else if (isInOption)
{
return LineSyncState.InOption;
}
else
{
return LineSyncState.Default;
}
}
private void OnOptionShow()
{
isInOption = true;
}
private void OnOptionSelected(LineInfo lineInfo)
{
isInOption = false;
}
}
public struct AdvanceMode
{
@@ -140,14 +177,14 @@ namespace AibisDream
{
get
{
if (isAuto)
{
return AdvanceModeEnum.Auto;
}
else if (isQuick)
if (isQuick)
{
return AdvanceModeEnum.Quick;
}
else if (isAuto)
{
return AdvanceModeEnum.Auto;
}
else
{
return AdvanceModeEnum.Default;
+3 -2
View File
@@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using AibisDream.Framework;
using AibisDream.Utility;
using UnityEngine;
using Yarn.Unity;
@@ -23,6 +21,7 @@ namespace AibisDream
{
// 自动推进视图
lineSyncEvent = LineSyncToken.CreateAuto(dialogueLine, onDialogueLineFinished);
DialogController.Instance.lineSyncToken = lineSyncEvent;
if (_screenViewDict.TryGetValue(DialogViewType.Screen, out var view))
{
view.RunLine(lineSyncEvent);
@@ -35,6 +34,7 @@ namespace AibisDream
else if (dialogueLine.GetCharacterVo().dialogViewType == DialogViewType.Task)
{
lineSyncEvent = LineSyncToken.CreateImmediate(dialogueLine, onDialogueLineFinished);
DialogController.Instance.lineSyncToken = lineSyncEvent;
if (_screenViewDict.TryGetValue(DialogViewType.Task, out var view))
{
view.RunLine(lineSyncEvent);
@@ -48,6 +48,7 @@ namespace AibisDream
{
// 手动推进视图
lineSyncEvent = LineSyncToken.CreateDefault(dialogueLine, onDialogueLineFinished);
DialogController.Instance.lineSyncToken = lineSyncEvent;
bubbleGroup.RunLine(lineSyncEvent);
}
+29 -13
View File
@@ -41,7 +41,6 @@ namespace AibisDream
{
this.lineInfo = LineInfo.Generate(lineInfo);
_nextStep = nextStep;
state = LineSyncState.PlayText;
_textShown = textShown;
}
@@ -104,7 +103,7 @@ namespace AibisDream
EnumEventSystem.Global.Send(DialogEventEnum.LineShown);
await _textShown.OnTextShown(this);
}
public void TextStart()
{
if (state != LineSyncState.Default)
@@ -149,7 +148,7 @@ namespace AibisDream
var delayTime = lineText.RemoveRichTextTags().Length * ConstRef.CharacterDelayTime;
return CommonUtil.Limit(delayTime, ConstRef.LineMaxDelay, ConstRef.LineMinDelay);
}
public int CalcDelayTime()
{
return ConstRef.FixedDelay;
@@ -165,11 +164,18 @@ namespace AibisDream
{
public async Task OnTextShown(LineSyncToken token)
{
token.state = LineSyncState.AdvanceDelay;
await Task.Delay(token.lineInfo.CalcDelayTime(), token.AdvanceDelayToken.Token);
token.state = LineSyncState.WaitForAdvance;
await Task.Delay(token.lineInfo.CalcAutoDelayTime(), token.AdvanceDelayToken.Token);
token.state = LineSyncState.WaitForAutoAdvance;
try
{
token.state = LineSyncState.AdvanceDelay;
await Task.Delay(token.lineInfo.CalcDelayTime(), token.AdvanceDelayToken.Token);
token.state = LineSyncState.WaitForAdvance;
await Task.Delay(token.lineInfo.CalcAutoDelayTime(), token.AdvanceDelayToken.Token);
token.state = LineSyncState.WaitForAutoAdvance;
}
catch (TaskCanceledException)
{
// 跳过,无事发生
}
}
}
@@ -177,10 +183,17 @@ namespace AibisDream
{
public async Task OnTextShown(LineSyncToken token)
{
token.state = LineSyncState.AdvanceDelay;
await Task.Delay(token.lineInfo.CalcDelayTime(), token.AdvanceDelayToken.Token);
token.state = LineSyncState.WaitForAutoAdvance;
token.TryAdvance();
try
{
token.state = LineSyncState.AdvanceDelay;
await Task.Delay(token.lineInfo.CalcDelayTime(), token.AdvanceDelayToken.Token);
token.state = LineSyncState.WaitForAutoAdvance;
token.TryAdvance();
}
catch (TaskCanceledException)
{
// 跳过,无事发生
}
}
}
@@ -199,6 +212,9 @@ namespace AibisDream
AdvanceDelay,
WaitForAdvance,
WaitForAutoAdvance,
Advanced
Advanced,
// 仅限DialogController使用
InOption
}
}