This commit is contained in:
2025-03-08 19:13:57 +08:00
parent 6b615454df
commit 3e2a606b87
9 changed files with 756 additions and 21 deletions
+1
View File
@@ -13,6 +13,7 @@ namespace AibisDream.Framework
#region
[SerializeField] public ActorRole role;
[SerializeField] public int idx;
[SerializeField] private int maxCharNum;
#endregion
+40 -20
View File
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using AibisDream.Framework;
using AibisDream.Kit;
using AibisDream.Utility;
@@ -9,14 +10,15 @@ namespace AibisDream
{
public class TextBubbleGroup : MonoBehaviour, IDialogView
{
private readonly Dictionary<ActorRole, TextBubble> _bubbleDict = new();
private Dictionary<ActorRole, TextBubble[]> _bubbleDict;
#region
private bool _skipLineDelay;
private Action _nextStep;
private bool _isAutoSkip;
private ActorRole _curRole;
private TextBubble _curBubble;
[Header("跳过阻塞延迟时间/ms")] [SerializeField]
private int delayTime = 300;
@@ -46,10 +48,8 @@ namespace AibisDream
private void InitBubbles()
{
foreach (var bubble in GetComponentsInChildren<TextBubble>(true))
{
_bubbleDict[bubble.role] = bubble;
}
_bubbleDict = GetComponentsInChildren<TextBubble>().GroupBy(item => item.role)
.ToDictionary(group => group.Key, group => group.ToArray());
}
#endregion
@@ -57,18 +57,15 @@ namespace AibisDream
public void ShowLine(string dialogLine, CharacterVo character, Action nextStep, bool isAutoSkip = false)
{
gameObject.SetActive(true);
if (_curRole != character.role)
{
_bubbleDict[_curRole].Hide();
}
if (_bubbleDict.TryGetValue(character.role, out var bubble))
if (TryGetBubble(character.role, character.bubbleIdx ,out var bubble))
{
bubble.ShowLine(dialogLine, OnTextShowed);
// 设置延时
_skipLineDelay = true;
_ = CommonUtil.Delay(delayTime, () => { _skipLineDelay = false; });
// 将非选定的Bubble隐藏
HideDialog(bubble);
}
else
{
@@ -79,7 +76,7 @@ namespace AibisDream
// 保留信息
_nextStep = nextStep;
_isAutoSkip = isAutoSkip;
_curRole = character.role;
_curBubble = bubble;
}
public void ShowOptions(DialogOption[] dialogueOptions)
@@ -89,9 +86,20 @@ namespace AibisDream
public void HideDialog()
{
foreach (var bubble in _bubbleDict.Values)
foreach (var textBubble in _bubbleDict.Values.SelectMany(inner => inner))
{
bubble.Hide();
textBubble.Hide();
}
}
public void HideDialog(TextBubble activeBubble)
{
foreach (var textBubble in _bubbleDict.Values.SelectMany(inner => inner))
{
if (activeBubble != textBubble)
{
textBubble.Hide();
}
}
}
@@ -102,9 +110,9 @@ namespace AibisDream
return true;
}
if (_bubbleDict.TryGetValue(_curRole, out var bubble) && bubble.IsShowingText)
if (_curBubble.IsShowingText)
{
bubble.SkipLine();
_curBubble.SkipLine();
return true;
}
@@ -119,9 +127,9 @@ namespace AibisDream
var next = _nextStep;
_nextStep = null;
_bubbleDict[_curRole].Hide();
_curBubble?.Hide();
next.Invoke();
next?.Invoke();
}
private void OnTextShowed()
@@ -136,5 +144,17 @@ namespace AibisDream
_isAutoSkip = false;
}
}
private bool TryGetBubble(ActorRole role, int idx, out TextBubble textBubble)
{
if (_bubbleDict.TryGetValue(role, out var bubbles))
{
textBubble = bubbles.FirstOrDefault(item => item.idx == idx);
return textBubble != null;
}
textBubble = null;
return false;
}
}
}