using System; using System.Collections.Generic; using System.Linq; using AibisDream.Kit; using UnityEngine; 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 List _dialogViews; private IDialogView _currentView; private Action _nextStep; 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(DialogOption[] options) { gameObject.SetActive(true); _currentView = _normalBox; // 目前只有正常Box可以展示选项 // 处理其他泡泡 ProcessOtherBox(); // 展示选项 _normalBox.ShowOptions(options); } public void HideDialog() { gameObject.SetActive(false); // 隐藏整个对话组件 _dialogViews?.ForEach(item => item.HideDialog()); } public bool TrySkipLine() { return _currentView == null || _currentView.TrySkipLine(); } public void NextStep() { _currentView.NextStep(); } private IDialogView SelectBubbleByCharacter(CharacterVo characterVo) { var targetBubble = characterVo.role switch { ActorRole.Player => _playerBubble, ActorRole.MainActor => _actorBubble, ActorRole.Aside => _normalBox, _ => _normalBox }; foreach (var bubble in _dialogViews.Where(bubble => bubble != targetBubble)) { bubble.HideDialog(); } return targetBubble; } private void ProcessOtherBox() { if (_currentView == _actorBubble || _currentView == _playerBubble) { _normalBox.HideDialog(); } if (_currentView == _normalBox) { _actorBubble.HideDialog(); _playerBubble.HideDialog(); } } } }