using System; using System.Collections.Generic; using System.Linq; using AibisDream.Utility; using UnityEngine; using Yarn.Unity; namespace AibisDream { public class LineRunner : DialogueViewBase { [SerializeField] private DialogViewType[] lineViewTypes; [SerializeField] private LineAdvanceInput advanceInput; [SerializeField] private BubbleGroup bubbleGroup; private readonly Dictionary _screenViewDict = new(); public override void RunLine(LocalizedLine dialogueLine, Action onDialogueLineFinished) { LineSyncToken lineSyncEvent; if (!lineViewTypes.Contains(dialogueLine.GetCharacterVo().dialogViewType)) { // 手动推进视图 lineSyncEvent = new LineSyncToken(dialogueLine, onDialogueLineFinished); bubbleGroup.RunLine(lineSyncEvent); } else { // 自动推进视图 lineSyncEvent = new LineSyncToken(dialogueLine, onDialogueLineFinished, true); if (_screenViewDict.TryGetValue(dialogueLine.GetCharacterVo().dialogViewType, out var view)) { view.RunLine(lineSyncEvent); } else { Debug.LogWarning($"未注册的视图类型: {dialogueLine.GetCharacterVo().dialogViewType}"); } } // 最后交给推进处理 advanceInput.RunLine(lineSyncEvent); } public void RegisterView(DialogViewType dialogViewType, ILineView view) { _screenViewDict.Add(dialogViewType, view); } public void UnRegisterView(DialogViewType dialogViewType) { _screenViewDict.Remove(dialogViewType); } } public interface ILineView { void RunLine(LineSyncToken token); } }