对话框

This commit is contained in:
2025-06-04 21:45:50 +08:00
parent c468c8b070
commit f14cdf90f6
37 changed files with 1129 additions and 966 deletions
+3
View File
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: d9cb39e4c7764dcf8f99fe429a8edc19
timeCreated: 1749038925
@@ -0,0 +1,72 @@
using AibisDream.Framework;
using AibisDream.Kit;
using AibisDream.Utility;
using Febucci.UI.Core;
using TMPro;
using UnityEngine;
namespace AibisDream
{
public class Bubble : MonoBehaviour
{
private TypewriterCore _typewriter;
private TMP_Text _actorName;
#region
[SerializeField] public ActorRole role;
[SerializeField] public int idx;
[SerializeField] private int maxCharNum;
#endregion
public bool IsShowingText => _typewriter.isShowingText;
private void Awake()
{
_typewriter = GetComponentInChildren<TypewriterCore>();
_actorName = transform.Find("Actor")?.GetComponent<TMP_Text>();
_typewriter.onTextShowed.AddListener(() => EnumEventSystem.Global.Send(DialogEventEnum.LineShown));
}
public void ShowActorName(CharacterVo characterVo)
{
if (!_actorName) return;
_actorName.text = string.IsNullOrEmpty(characterVo.GetActorName())
? string.Empty
: characterVo.GetActorName();
}
public void ShowLine(string line)
{
_typewriter.TextAnimator.SetText("");
gameObject.SetActive(true);
var formattedLine = CommonUtil.SplitString(line, maxCharNum);
_typewriter.ShowText(formattedLine);
}
public void SkipLine()
{
if (_typewriter.isShowingText)
{
_typewriter.SkipTypewriter();
}
}
public void Hide()
{
gameObject.SetActive(false);
}
public void OnLocalizationChanged(string value)
{
var textParam = JsonUtil.ReadBeanByText<TextParam>(value);
var tmp = GetComponentInChildren<TMP_Text>();
tmp.characterSpacing = textParam.charSpace;
_actorName.characterSpacing = textParam.charSpace;
maxCharNum = textParam.maxCharNum;
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 6adb9d7cc075457a8fece1b14ca4c429
timeCreated: 1749022700
@@ -0,0 +1,155 @@
using System;
using System.Collections.Generic;
using System.Linq;
using AibisDream.Framework;
using AibisDream.Kit;
using UnityEngine;
namespace AibisDream
{
public class BubbleGroup : MonoBehaviour, IDialogView
{
private BubbleOption[] _options;
private Dictionary<ActorRole, Bubble[]> _bubbleDict;
#region
private Action _nextStep;
private Bubble _curBubble;
#endregion
#region
private void Awake()
{
// 注册泡泡
EnumEventSystem.Global.Register(DialogEventEnum.OptionSelected, HideOptions);
}
private void Start()
{
HideDialog();
}
private void OnDestroy()
{
EnumEventSystem.Global.UnRegister(DialogEventEnum.OptionSelected, HideOptions);
}
public void Init()
{
}
#endregion
#region
public void ShowLine(string dialogLine, CharacterVo character, Action nextStep, string lineId,
bool isAutoSkip = false)
{
gameObject.SetActive(true);
if (TryGetBubble(character.role, character.bubbleIdx, out var bubble))
{
bubble.ShowActorName(character);
bubble.ShowLine(dialogLine);
// 将非选定的Bubble隐藏
HideDialog(bubble);
}
else
{
Debug.LogWarning($"{character.GetActorName()}的Role没有对应Bubble");
return;
}
// 保留信息
_nextStep = nextStep;
_curBubble = bubble;
}
public void ShowOptions(DialogOption[] dialogueOptions)
{
HideDialog();
// 要求最多三个选项
for (var i = 0; i < dialogueOptions.Length; i++)
{
_options[i].ShowOption(dialogueOptions[i]);
}
}
public void HideDialog()
{
foreach (var textBubble in _bubbleDict.Values.SelectMany(inner => inner))
{
textBubble.Hide();
}
HideOptions();
}
public bool TrySkipLine(bool isForceSkip = false)
{
if (_curBubble.IsShowingText)
{
_curBubble.SkipLine();
return true;
}
return false;
}
public void NextStep()
{
if (_nextStep == null) return;
EnumEventSystem.Global.Send(DialogEventEnum.LineEnd);
var next = _nextStep;
_nextStep = null;
_curBubble?.Hide();
next?.Invoke();
}
public void OnLocalizationChanged(string value)
{
}
#endregion
private void HideDialog(Bubble activeBubble)
{
foreach (var textBubble in _bubbleDict.Values.SelectMany(inner => inner))
{
if (activeBubble != textBubble)
{
textBubble.Hide();
}
}
HideOptions();
}
private bool TryGetBubble(ActorRole role, int idx, out Bubble bubble)
{
if (_bubbleDict.TryGetValue(role, out var bubbles))
{
bubble = bubbles.FirstOrDefault(item => item.idx == idx);
return bubble != null;
}
bubble = null;
return false;
}
private void HideOptions()
{
foreach (var option in _options)
{
option.Hide();
}
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: a76234ef7ee34400b306a4823081ba62
timeCreated: 1749022020
@@ -0,0 +1,37 @@
using TMPro;
using UnityEngine;
using UnityEngine.UI;
namespace AibisDream
{
public class BubbleOption : MonoBehaviour
{
public int optionIdx;
private TMP_Text _text;
private DialogOption _option;
private Button _button;
public void Awake()
{
_text = GetComponent<TMP_Text>();
}
public void ShowOption(DialogOption dialogOption)
{
_button.onClick.RemoveAllListeners();
_text.text = "";
// 清理旧数据
gameObject.SetActive(true);
_text.text = dialogOption.Line;
_button.onClick.AddListener(() =>
{
dialogOption.Select();
});
}
public void Hide()
{
gameObject.SetActive(false);
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 468ec4615ee64b2cb5ef8b1a66339dac
timeCreated: 1749024963
@@ -0,0 +1,24 @@
using UnityEngine;
namespace AibisDream
{
public class BubbleOptionSlot : MonoBehaviour
{
private BubbleOptionSlotData _data;
public BubbleOptionSlotData Data
{
get
{
_data.slotPosition = transform.position;
return _data;
}
}
}
public struct BubbleOptionSlotData
{
[HideInInspector] public Vector3 slotPosition;
public int optionIdx;
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c1a72c4bf33546244b7030c41b1b2b05
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,31 @@
using System;
using AibisDream.Framework;
using AibisDream.Kit;
using UnityEngine;
namespace AibisDream
{
public class BubbleSlot : MonoBehaviour
{
[SerializeField] private BubbleSlotData data;
public BubbleSlotData Data
{
get
{
data.slotPosition = CameraKit.GetScreenPos(transform.position);
return data;
}
}
}
[Serializable]
public struct BubbleSlotData
{
[HideInInspector] public Vector3 slotPosition;
public ActorRole actorRole;
public int idx;
public bool hasActorName;
public int maxCharNum;
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: bbc0dde0e8b8a9c498545e1b5b508241
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,27 @@
using System;
using UnityEngine;
namespace AibisDream
{
public class BubbleSlotGroup
{
public BubbleSlotGroupData data;
}
[Serializable]
public struct BubbleSlotGroupData
{
public DialogViewType dialogViewType;
[HideInInspector] public BubbleSlotData[] bubbleSlots;
[HideInInspector] public BubbleOptionSlotData[] bubbleOptionSlots;
}
public enum PivotType {
Center,
CenterLeft,
CenterRight,
Top,
Bottom
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 8225446392f64688813d628ffb56cc7c
timeCreated: 1749042853
-21
View File
@@ -18,18 +18,12 @@ namespace AibisDream
private Action _nextStep;
#endregion
private bool _skipLineDelay;
private TextParam _textParam;
[Header("跳过阻塞延迟时间/ms")] [SerializeField]
private int delayTime = 300;
private void Awake()
{
InitComponents();
AddSomeListener();
}
private void InitComponents()
@@ -37,16 +31,6 @@ namespace AibisDream
_dialogText = transform.Find("Dialog Text")?.gameObject.GetComponent<TypewriterByCharacter>();
}
private void AddSomeListener()
{
// 对话显示后有一段延时不可跳过
_dialogText.onTypewriterStart.AddListener(() =>
{
_skipLineDelay = true;
_ = CommonUtil.Delay(delayTime, () => { _skipLineDelay = false; });
});
}
public void ShowLine(string dialogLine, CharacterVo character, Action nextStep, string lineId, bool isAutoSkip = false)
{
// 把原有对话清掉
@@ -75,11 +59,6 @@ namespace AibisDream
public bool TrySkipLine(bool isForceSkip)
{
if (_skipLineDelay && !isForceSkip)
{
return true;
}
if (_dialogText.isShowingText)
{
_dialogText.SkipTypewriter();
@@ -15,8 +15,6 @@ namespace AibisDream
private IDialogView _defaultView;
private IDialogView _showingView;
public TempTextBox tempText;
private IActionController _autoNext;
private IActionController _block;
private IActionController _hideDialog;
@@ -50,10 +48,6 @@ namespace AibisDream
RegisterDialogView(DialogViewType.CenterText, centerText);
var centerOption = transform.Find("Center Option").GetComponent<IDialogView>();
RegisterDialogView(DialogViewType.CenterOption, centerOption);
if (tempText != null)
{
RegisterDialogView(DialogViewType.Temp, tempText);
}
_defaultView = _dialogViewDict[DialogViewType.OldBox];
}
@@ -205,7 +199,7 @@ namespace AibisDream
// 根据状况选择不同的选择框
if (viewType == DialogViewType.Default)
{
if (_showingView != _dialogViewDict[DialogViewType.OldBox])
if (_showingView != _defaultView)
{
_showingView?.HideDialog();
}
@@ -214,12 +208,13 @@ namespace AibisDream
_hideDialog?.Deinit();
_hideDialog = null;
}
_showingView = _defaultView;
_dialogViewDict[DialogViewType.OldBox].ShowOptions(dialogueOptions);
_showingView.ShowOptions(dialogueOptions);
}
else
else if(_dialogViewDict.TryGetValue(viewType, out var view))
{
if (_showingView != _dialogViewDict[viewType])
if (_showingView != view)
{
_showingView?.HideDialog();
}
@@ -228,8 +223,8 @@ namespace AibisDream
_hideDialog?.Deinit();
_hideDialog = null;
}
_dialogViewDict[viewType].ShowOptions(dialogueOptions);
_showingView = view;
_showingView.ShowOptions(dialogueOptions);
}
}
@@ -319,6 +314,7 @@ namespace AibisDream
CenterText,
CenterOption,
Task,
Temp
ClinicBubble,
ModuleBubble
}
}
@@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.Linq;
using AibisDream.Framework;
using AibisDream.Kit;
using AibisDream.Utility;
using UnityEngine;
namespace AibisDream
@@ -14,14 +13,10 @@ namespace AibisDream
#region
private bool _skipLineDelay;
private Action _nextStep;
private TextBubble _curBubble;
[Header("跳过阻塞延迟时间/ms")] [SerializeField]
private int delayTime = 300;
#endregion
#region
@@ -60,9 +55,6 @@ namespace AibisDream
if (TryGetBubble(character.role, character.bubbleIdx ,out var bubble))
{
bubble.ShowLine(dialogLine, OnTextShowed);
// 设置延时
_skipLineDelay = true;
_ = CommonUtil.Delay(delayTime, () => { _skipLineDelay = false; });
// 将非选定的Bubble隐藏
HideDialog(bubble);
}
@@ -103,11 +95,6 @@ namespace AibisDream
public bool TrySkipLine(bool isForceSkip)
{
if (_skipLineDelay && !isForceSkip)
{
return true;
}
if (_curBubble.IsShowingText)
{
_curBubble.SkipLine();