更新
This commit is contained in:
@@ -1,18 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using AibisDream.Framework;
|
||||
using AibisDream.Kit;
|
||||
using AibisDream.Utility;
|
||||
using DG.Tweening;
|
||||
using Febucci.UI;
|
||||
using Febucci.UI.Core;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace AibisDream.FixSystem
|
||||
{
|
||||
public class ScreenSystem : MonoBehaviour, IDialogView
|
||||
public class ScreenSystem : MonoBehaviour, ILineView
|
||||
{
|
||||
#region 索引
|
||||
|
||||
@@ -47,15 +46,15 @@ namespace AibisDream.FixSystem
|
||||
private void Register()
|
||||
{
|
||||
FixSystemCenter.SystemDic.Register(this);
|
||||
DialogCanvasManager.Instance.RegisterDialogView(DialogViewType.Screen, this);
|
||||
DialogCanvasManager.Instance.RegisterDialogView(DialogViewType.Task, TaskScreen);
|
||||
DialogUIManager.Instance.RegisterScreenView(DialogViewType.Screen, this);
|
||||
DialogUIManager.Instance.RegisterScreenView(DialogViewType.Task, TaskScreen);
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
FixSystemCenter.SystemDic.Unregister<ScreenSystem>();
|
||||
DialogCanvasManager.Instance.UnregisterDialogView(DialogViewType.Screen);
|
||||
DialogCanvasManager.Instance.UnregisterDialogView(DialogViewType.Task);
|
||||
DialogUIManager.Instance.UnRegisterScreenView(DialogViewType.Screen);
|
||||
DialogUIManager.Instance.UnRegisterScreenView(DialogViewType.Task);
|
||||
}
|
||||
|
||||
#region 基础功能
|
||||
@@ -82,25 +81,38 @@ namespace AibisDream.FixSystem
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 对话框功能实现
|
||||
|
||||
public void ShowLine(string dialogLine, CharacterVo character, Action nextStep, string lineId, bool isAutoSkip = false)
|
||||
|
||||
public void RunLine(LineSyncToken token)
|
||||
{
|
||||
Debug.Log($"[ScreenSystem] ShowLine - 原始文本: '{dialogLine}'");
|
||||
|
||||
if (string.IsNullOrWhiteSpace(dialogLine))
|
||||
// 空格延长一点避免报错
|
||||
if (string.IsNullOrWhiteSpace(token.lineInfo.lineText))
|
||||
{
|
||||
dialogLine = " ";
|
||||
// Debug.Log("[ScreenSystem] ShowLine - 空文本被替换为空格");
|
||||
token.lineInfo.lineText = " ";
|
||||
}
|
||||
|
||||
ShowTitle(character.GetActorName());
|
||||
// 显示标题
|
||||
ShowTitle(token.lineInfo.character.GetActorName());
|
||||
// 显示文本
|
||||
TypewriterCore textItemTypewriter = AddText(token.lineInfo.lineText);
|
||||
textItemTypewriter.onTextShowed.AddListener(() => OnTextShown(token, textItemTypewriter));
|
||||
token.state = LineSyncState.PlayText;
|
||||
// 强制更新布局
|
||||
LayoutRebuilder.ForceRebuildLayoutImmediate(textRoot);
|
||||
}
|
||||
|
||||
private void OnTextShown(LineSyncToken syncToken, TypewriterCore typewriter)
|
||||
{
|
||||
typewriter.onTextShowed.RemoveAllListeners();
|
||||
syncToken.TextShown();
|
||||
}
|
||||
|
||||
private TypewriterByCharacter AddText(string newLine)
|
||||
{
|
||||
// 生成新文本组件
|
||||
var textItem = Instantiate(_textItemPrefab, textRoot);
|
||||
var textItemTypewriter = textItem.GetComponent<TypewriterByCharacter>();
|
||||
// 估算文本高度
|
||||
var newLineNum = EstimateLineNum(dialogLine);
|
||||
var newLineNum = EstimateLineNum(newLine);
|
||||
var oldLineNum = CalcTotalLineNum();
|
||||
if (newLineNum + oldLineNum > maxLineNum)
|
||||
{
|
||||
@@ -109,57 +121,10 @@ namespace AibisDream.FixSystem
|
||||
_lineQueue.Enqueue(textItemTypewriter);
|
||||
|
||||
// 播放文本
|
||||
textItemTypewriter.ShowText(dialogLine);
|
||||
textItemTypewriter.onTextShowed.AddListener(() => AfterLineShown(textItemTypewriter, nextStep));
|
||||
|
||||
// 强制更新布局
|
||||
LayoutRebuilder.ForceRebuildLayoutImmediate(textRoot);
|
||||
|
||||
Debug.Log($"[ScreenSystem] ShowLine - 文本播放开始,nextStep是否为null: {nextStep == null}");
|
||||
}
|
||||
textItemTypewriter.ShowText(newLine);
|
||||
|
||||
private void AfterLineShown(TypewriterByCharacter typewriter, Action nextStop)
|
||||
{
|
||||
Debug.Log("[ScreenSystem] AfterLineShown - 文本显示完成");
|
||||
Debug.Log($"[ScreenSystem] AfterLineShown - nextStop是否为null: {nextStop == null}");
|
||||
|
||||
EnumEventSystem.Global.Send(DialogEventEnum.LineShown);
|
||||
ActionKit.Delay(0.1f, () =>
|
||||
{
|
||||
Debug.Log("[ScreenSystem] AfterLineShown - 延迟结束,调用回调");
|
||||
nextStop?.Invoke();
|
||||
Debug.Log("[ScreenSystem] AfterLineShown - 回调调用完成");
|
||||
}).StartGlobal();
|
||||
typewriter.onTextShowed.RemoveAllListeners();
|
||||
return textItemTypewriter;
|
||||
}
|
||||
|
||||
public void ShowOptions(DialogOption[] dialogueOptions)
|
||||
{
|
||||
Debug.Log("不能在显示屏显示对话");
|
||||
}
|
||||
|
||||
public void HideDialog()
|
||||
{
|
||||
// HideDialog应该由其他函数控制
|
||||
}
|
||||
|
||||
public bool TrySkipLine(bool isAutoSkip)
|
||||
{
|
||||
// 这里不能跳过对话
|
||||
return true;
|
||||
}
|
||||
|
||||
public void NextStep()
|
||||
{
|
||||
// 这里不能手动跳到下一行
|
||||
}
|
||||
|
||||
public void OnLocalizationChanged(string value)
|
||||
{
|
||||
// 屏幕不需要本地化
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private int EstimateLineNum(string text)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user