新对话记录
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using AibisDream.Framework;
|
||||
using AibisDream.Kit;
|
||||
using AibisDream.Utility;
|
||||
using UnityEngine;
|
||||
using Yarn.Unity;
|
||||
@@ -19,8 +18,7 @@ namespace AibisDream
|
||||
Debug.Log($"[对话流程] [{lineId}] ===== 开始处理 =====");
|
||||
Debug.Log($"[对话流程] [{lineId}] 文本内容: {shortText}");
|
||||
|
||||
EnumEventSystem.Global.Send(DialogEventEnum.LineStart,
|
||||
DialogText.GetLine(dialogueLine, DialogController.Instance.GetCurLocalizedTableName()));
|
||||
EnumEventSystem.Global.Send(DialogEventEnum.LineStart, DialogText.GetLine(dialogueLine));
|
||||
|
||||
HandleLineOutput(dialogueLine, onDialogueLineFinished);
|
||||
|
||||
|
||||
@@ -45,19 +45,24 @@ namespace AibisDream
|
||||
public string line;
|
||||
public CharacterVo actor;
|
||||
public string lineId;
|
||||
public string localizationTableName;
|
||||
|
||||
public static DialogText GetLine(LocalizedLine dialogueLine, string projName)
|
||||
public static DialogText GetLine(LocalizedLine dialogueLine)
|
||||
{
|
||||
return new DialogText
|
||||
{
|
||||
isOption = false,
|
||||
line = dialogueLine.TextWithoutCharacterName.Text,
|
||||
lineId = dialogueLine.TextID,
|
||||
actor = dialogueLine.GetCharacterVo(),
|
||||
localizationTableName = projName
|
||||
actor = dialogueLine.GetCharacterVo()
|
||||
};
|
||||
}
|
||||
|
||||
public string GetRecordLine()
|
||||
{
|
||||
const string allowedTagsPattern = @"(<|{)(?!\/?(b|i|color)(?=>|\s|=))[^(>|})]+(>|})";
|
||||
var res = Regex.Replace(line, allowedTagsPattern, "");
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
public enum StorageEvent
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using AibisDream.Utility;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Localization.Components;
|
||||
|
||||
namespace AibisDream.UI
|
||||
{
|
||||
@@ -8,23 +7,16 @@ namespace AibisDream.UI
|
||||
{
|
||||
#region 索引
|
||||
|
||||
[SerializeField] private LocalizeStringEvent actorName;
|
||||
[SerializeField] private LocalizeStringEvent dialogLine;
|
||||
[SerializeField] private TMP_Text actorName;
|
||||
[SerializeField] private TMP_Text dialogLine;
|
||||
|
||||
#endregion
|
||||
|
||||
public void Init(DialogText dialogText)
|
||||
{
|
||||
actorName.text = dialogText.actor.GetActorName();
|
||||
dialogLine.text = dialogText.GetRecordLine();
|
||||
gameObject.SetActive(true);
|
||||
actorName.SetTable(ConstRef.ActorNameTable);
|
||||
actorName.SetEntry(dialogText.actor.key);
|
||||
dialogLine.SetTable(dialogText.localizationTableName);
|
||||
dialogLine.SetEntry(dialogText.lineId);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,17 +12,15 @@ namespace AibisDream.UI
|
||||
public bool IsCloseable => true;
|
||||
|
||||
#region 索引
|
||||
|
||||
|
||||
[SerializeField] private Image popupBackground;
|
||||
[SerializeField] private Button closeBtn;
|
||||
[SerializeField] private LoopVerticalScrollRect recordScroll;
|
||||
[SerializeField] private Transform content;
|
||||
[SerializeField] private Transform inactiveRoot;
|
||||
[SerializeField] private Transform recordRoot;
|
||||
[SerializeField] private GameObject recordPrefab;
|
||||
|
||||
#endregion
|
||||
|
||||
private readonly List<DialogText> _recordDataList = new();
|
||||
// private RecordSource _recordSource;
|
||||
|
||||
public void Show()
|
||||
{
|
||||
@@ -65,18 +63,20 @@ namespace AibisDream.UI
|
||||
|
||||
private void ShowRecord()
|
||||
{
|
||||
var resource = new RecordSource(content, inactiveRoot, _recordDataList);
|
||||
|
||||
recordScroll.prefabSource = resource;
|
||||
recordScroll.dataSource = resource;
|
||||
recordScroll.totalCount = resource.TotalCount;
|
||||
recordScroll.RefillCells();
|
||||
for (var i = _recordDataList.Count - 1; i >= 0; i--)
|
||||
{
|
||||
var dialogText = _recordDataList[i];
|
||||
var record = Instantiate(recordPrefab, recordRoot);
|
||||
record.GetComponent<RecordItem>().Init(dialogText);
|
||||
}
|
||||
}
|
||||
|
||||
private void HideRecord()
|
||||
{
|
||||
content.DestroyAllChildren();
|
||||
// TODO 可能有性能问题
|
||||
recordRoot.DestroyAllChildren();
|
||||
}
|
||||
|
||||
|
||||
private void ReturnGame()
|
||||
{
|
||||
|
||||
@@ -1,68 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using AibisDream.Framework;
|
||||
using AibisDream.Kit;
|
||||
using AibisDream.Utility;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AibisDream.UI
|
||||
{
|
||||
public class RecordSource : ILoopScrollDataSource, ILoopScrollPrefabSource
|
||||
{
|
||||
private readonly SimpleObjectPool<RecordItem> _pool;
|
||||
|
||||
private readonly GameObject _itemPrefab;
|
||||
private readonly Transform _contentRoot;
|
||||
private readonly Transform _tempRoot;
|
||||
|
||||
private List<DialogText> _dialogTexts;
|
||||
|
||||
public int TotalCount => _dialogTexts.Count;
|
||||
|
||||
public RecordSource(Transform content, Transform tempRoot, List<DialogText> dialogTexts)
|
||||
{
|
||||
_contentRoot = content;
|
||||
_tempRoot = tempRoot;
|
||||
|
||||
_dialogTexts = dialogTexts;
|
||||
|
||||
_itemPrefab = ResourceKit.LoadAssetSync<GameObject>(ConstRef.RecordPrefab);
|
||||
_pool = new SimpleObjectPool<RecordItem>(InstantiateItem);
|
||||
}
|
||||
|
||||
private RecordItem InstantiateItem()
|
||||
{
|
||||
return Object.Instantiate(_itemPrefab, _tempRoot).GetComponent<RecordItem>();
|
||||
}
|
||||
|
||||
#region 滚动功能
|
||||
|
||||
public void ProvideData(Transform transform, int idx)
|
||||
{
|
||||
var item = transform.GetComponent<RecordItem>();
|
||||
if (item != null)
|
||||
{
|
||||
item.Init(_dialogTexts[idx]);
|
||||
}
|
||||
}
|
||||
|
||||
public GameObject GetObject(int index)
|
||||
{
|
||||
var obj = _pool.Allocate().gameObject;
|
||||
obj.transform.SetParent(_contentRoot);
|
||||
return obj;
|
||||
}
|
||||
|
||||
public void ReturnObject(Transform trans)
|
||||
{
|
||||
Debug.Log("return obj");
|
||||
|
||||
trans.SetParent(_tempRoot);
|
||||
|
||||
var record = trans.GetComponent<RecordItem>();
|
||||
record.Dispose();
|
||||
_pool.Recycle(record);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 616a80ca37a1406e808457bc971323b1
|
||||
timeCreated: 1757673398
|
||||
Reference in New Issue
Block a user