using System; using System.Collections.Generic; using AibisDream.Config; using UnityEngine; using Yarn.Unity; namespace AibisDream { public class DialogBubbleViewer : MonoBehaviour, IDialogView { private const string PlayerBubble = "Player Bubble"; private const string ActorBubble = "Actor Bubble"; private const string NormalBox = "Normal Box"; private IDialogView _normalBox; private IDialogView _playerBubble; private IDialogView _actorBubble; // 应该会有自定义位置的泡泡,但目前还没想好怎么做 private Dictionary _customBubblePool = new(); private List _dialogViews; private IDialogView _currentView; private void Awake() { Init(); } private void Init() { _normalBox = transform.Find(NormalBox).GetComponent(); _playerBubble = transform.Find(PlayerBubble).GetComponent(); _actorBubble = transform.Find(ActorBubble).GetComponent(); _dialogViews = new List { _normalBox, _playerBubble, _actorBubble }; _dialogViews.ForEach(item => item.HideDialog()); } public void ShowLine(string dialogLine, CharacterVo character, Action nextStep, bool isAutoSkip = false) { gameObject.SetActive(true); // 根据角色信息气泡 _currentView = SelectBubbleByCharacter(character); // 处理其他泡泡 ProcessOtherBox(); // 显示对话 _currentView.ShowLine(dialogLine, character, nextStep, isAutoSkip); } public void ShowOptions(DialogueOption[] dialogueOptions, Action onOptionSelected) { gameObject.SetActive(true); _currentView = _normalBox; // 目前只有正常Box可以展示选项 // 处理其他泡泡 ProcessOtherBox(); // 展示选项 _normalBox.ShowOptions(dialogueOptions, onOptionSelected); } public void HideDialog() { gameObject.SetActive(false); // 隐藏整个对话组件 _dialogViews?.ForEach(item => item.HideDialog()); } public bool TrySkipLine() { return _currentView == null || _currentView.TrySkipLine(); } private IDialogView SelectBubbleByCharacter(CharacterVo characterVo) { return characterVo.role switch { ActorRole.Player => _playerBubble, ActorRole.MainActor => _actorBubble, ActorRole.Aside => _normalBox, _ => _normalBox }; } private void ProcessOtherBox() { if (_currentView == _actorBubble || _currentView == _playerBubble) { _normalBox.HideDialog(); } if (_currentView == _normalBox) { _actorBubble.HideDialog(); _playerBubble.HideDialog(); } } } }