对话回顾
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AibisDream
|
||||
|
||||
@@ -30,9 +30,10 @@ namespace AibisDream
|
||||
#endregion
|
||||
|
||||
private bool _skipLineDelay;
|
||||
[Header("跳过阻塞延迟时间/ms")]
|
||||
[SerializeField] private int delayTime = 300;
|
||||
|
||||
|
||||
[Header("跳过阻塞延迟时间/ms")] [SerializeField]
|
||||
private int delayTime = 300;
|
||||
|
||||
protected GameObject choiceButtonPrefab;
|
||||
|
||||
protected virtual void Awake()
|
||||
@@ -85,7 +86,8 @@ namespace AibisDream
|
||||
/// <param name="nextStep">下一步</param>
|
||||
/// <param name="onTextShowed">文字展示结束后触发</param>
|
||||
/// <param name="isAutoSkip">是否自动跳过,默认为false</param>
|
||||
public virtual void ShowLine(string dialogLine, CharacterVo character, Action nextStep, Action onTextShowed ,bool isAutoSkip = false)
|
||||
public virtual void ShowLine(string dialogLine, CharacterVo character, Action nextStep, Action onTextShowed,
|
||||
bool isAutoSkip = false)
|
||||
{
|
||||
gameObject.SetActive(true);
|
||||
// 没有dialogText说明不能显示对话,直接跳过
|
||||
@@ -122,7 +124,7 @@ namespace AibisDream
|
||||
/// </summary>
|
||||
/// <param name="dialogueOptions">对话选项</param>
|
||||
/// <param name="onOptionSelected">选项选择</param>
|
||||
public virtual void ShowOptions(DialogueOption[] dialogueOptions, Action<int> onOptionSelected)
|
||||
public virtual void ShowOptions(DialogOption[] dialogueOptions)
|
||||
{
|
||||
gameObject.SetActive(true);
|
||||
// 没有选择框直接不显示选项
|
||||
@@ -143,15 +145,13 @@ namespace AibisDream
|
||||
}
|
||||
|
||||
// 生成新按钮
|
||||
foreach (DialogueOption option in dialogueOptions)
|
||||
foreach (var option in dialogueOptions)
|
||||
{
|
||||
if (!option.IsAvailable) continue;
|
||||
|
||||
var choiceInstance = Instantiate(choiceButtonPrefab, choiceBox.transform);
|
||||
choiceInstance.GetComponentInChildren<TextMeshProUGUI>().text =
|
||||
option.Line.TextWithoutCharacterName.Text;
|
||||
choiceInstance.GetComponent<Button>().onClick
|
||||
.AddListener(() => onOptionSelected.Invoke(option.DialogueOptionID));
|
||||
choiceInstance.GetComponentInChildren<TextMeshProUGUI>().text = option.Line;
|
||||
choiceInstance.GetComponent<Button>().onClick.AddListener(option.Select);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -167,7 +167,7 @@ namespace AibisDream
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
if (dialogText.isShowingText)
|
||||
{
|
||||
dialogText.SkipTypewriter();
|
||||
@@ -191,16 +191,7 @@ namespace AibisDream
|
||||
private void ShowActorName(CharacterVo character)
|
||||
{
|
||||
if (!actorName) return;
|
||||
|
||||
if (string.IsNullOrEmpty(character.nameColor))
|
||||
{
|
||||
actorName.text = character.cn;
|
||||
}
|
||||
else
|
||||
{
|
||||
var showStr = $"<color={character.nameColor}>{character.cn}</color>";
|
||||
actorName.text = showStr;
|
||||
}
|
||||
actorName.text = character.GetActorName();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,6 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using AibisDream.Kit;
|
||||
using UnityEngine;
|
||||
using Yarn.Unity;
|
||||
|
||||
namespace AibisDream
|
||||
{
|
||||
@@ -18,9 +17,6 @@ namespace AibisDream
|
||||
|
||||
private IDialogView _actorBubble;
|
||||
|
||||
// 应该会有自定义位置的泡泡,但目前还没想好怎么做
|
||||
private Dictionary<string, IDialogView> _customBubblePool = new();
|
||||
|
||||
private List<IDialogView> _dialogViews;
|
||||
|
||||
private IDialogView _currentView;
|
||||
@@ -52,7 +48,7 @@ namespace AibisDream
|
||||
_currentView.ShowLine(dialogLine, character, nextStep, onTextShowed, isAutoSkip);
|
||||
}
|
||||
|
||||
public void ShowOptions(DialogueOption[] dialogueOptions, Action<int> onOptionSelected)
|
||||
public void ShowOptions(DialogOption[] options)
|
||||
{
|
||||
gameObject.SetActive(true);
|
||||
_currentView = _normalBox;
|
||||
@@ -61,7 +57,7 @@ namespace AibisDream
|
||||
ProcessOtherBox();
|
||||
|
||||
// 展示选项
|
||||
_normalBox.ShowOptions(dialogueOptions, onOptionSelected);
|
||||
_normalBox.ShowOptions(options);
|
||||
}
|
||||
|
||||
public void HideDialog()
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using AibisDream.Framework;
|
||||
using AibisDream.Kit;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
@@ -9,24 +12,44 @@ namespace AibisDream
|
||||
{
|
||||
private const string BubbleView = "Dialog Bubble View";
|
||||
private const string OldBoxView = "Dialog Box";
|
||||
|
||||
|
||||
private const string QuickTalk = "Quick Talk";
|
||||
|
||||
|
||||
#region 引用
|
||||
|
||||
private IDialogView _bubbleView;
|
||||
private IDialogView _oldBoxView;
|
||||
|
||||
private IDialogView _curView;
|
||||
|
||||
|
||||
private GameObject _quickTalkButton;
|
||||
|
||||
#endregion
|
||||
|
||||
private List<IUnRegister> _rmvList = new();
|
||||
|
||||
|
||||
public override void OnSingletonInit()
|
||||
{
|
||||
InitDialogViews();
|
||||
InitQuickTalkButton();
|
||||
InitEvent();
|
||||
// 默认为旧Box
|
||||
_curView = _bubbleView;
|
||||
}
|
||||
|
||||
private void InitEvent()
|
||||
{
|
||||
_rmvList.Add(EnumEventSystem.Global.Register<EventEnum, DialogLine>(EventEnum.DialogLine, AddDialogueLine));
|
||||
_rmvList.Add(EnumEventSystem.Global.Register(EventEnum.NextYarn, CleanDialogHistory));
|
||||
}
|
||||
|
||||
public override void OnSingletonDestroy()
|
||||
{
|
||||
// 销毁前处理事件
|
||||
_rmvList.ForEach(item => item.UnRegister());
|
||||
}
|
||||
|
||||
#region 对话结束后隐藏
|
||||
|
||||
private void OnEnable()
|
||||
@@ -45,20 +68,22 @@ namespace AibisDream
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.Q) && Input.GetKey(KeyCode.P) )
|
||||
if (Input.GetKeyDown(KeyCode.Q) && Input.GetKey(KeyCode.P))
|
||||
{
|
||||
_quickTalkButton.SetActive(!_quickTalkButton.activeSelf);
|
||||
_quickTalkButton.SetActive(!_quickTalkButton.activeSelf);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#region 对话框相关处理
|
||||
|
||||
private void InitDialogViews()
|
||||
{
|
||||
_bubbleView = transform.Find(BubbleView).GetComponent<IDialogView>();
|
||||
_oldBoxView = transform.Find(OldBoxView).GetComponent<IDialogView>();
|
||||
|
||||
|
||||
_bubbleView.HideDialog();
|
||||
_oldBoxView.HideDialog();
|
||||
}
|
||||
@@ -68,7 +93,7 @@ namespace AibisDream
|
||||
_quickTalkButton = transform.Find(QuickTalk).gameObject;
|
||||
_quickTalkButton.GetComponent<Button>().onClick.AddListener(SwitchQuickTalkMode);
|
||||
}
|
||||
|
||||
|
||||
private void SwitchQuickTalkMode()
|
||||
{
|
||||
DialogController.Instance.quickRunMode = !DialogController.Instance.quickRunMode;
|
||||
@@ -108,11 +133,42 @@ namespace AibisDream
|
||||
{
|
||||
return Instance._curView;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 对话回顾
|
||||
|
||||
[Header("对话回顾组件")] [SerializeField] private TMP_Text logText;
|
||||
|
||||
/// <summary>
|
||||
/// 记录对话
|
||||
/// </summary>
|
||||
/// <param name="line">对话</param>
|
||||
private void AddDialogueLine(DialogLine line)
|
||||
{
|
||||
logText.text += line.GetDialogText();
|
||||
}
|
||||
|
||||
private void CleanDialogHistory()
|
||||
{
|
||||
logText.text = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 切换对话回顾展示状态
|
||||
/// </summary>
|
||||
public void ControlDialogHistory()
|
||||
{
|
||||
var logObj = transform.Find("Dialogue Log").gameObject;
|
||||
logObj.SetActive(!logObj.activeSelf);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
public enum DialogViewType
|
||||
{
|
||||
Bubble, OldBox
|
||||
Bubble,
|
||||
OldBox
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using AibisDream.Framework;
|
||||
using AibisDream.Kit;
|
||||
using AibisDream.Utility;
|
||||
using UnityEngine;
|
||||
using Yarn.Unity;
|
||||
|
||||
namespace AibisDream
|
||||
@@ -9,10 +14,51 @@ namespace AibisDream
|
||||
public void ShowLine(string dialogLine, CharacterVo character, Action nextStep, Action onTextShowed = null,
|
||||
bool isAutoSkip = false);
|
||||
|
||||
public void ShowOptions(DialogueOption[] dialogueOptions, Action<int> onOptionSelected);
|
||||
public void ShowOptions(DialogOption[] dialogueOptions);
|
||||
|
||||
public void HideDialog();
|
||||
|
||||
public bool TrySkipLine();
|
||||
}
|
||||
|
||||
public struct DialogOption
|
||||
{
|
||||
private Action<int> _onOptionSelected;
|
||||
private DialogueOption _option;
|
||||
|
||||
public bool IsAvailable => _option.IsAvailable;
|
||||
public string Line => _option.Line.TextWithoutCharacterName.Text;
|
||||
|
||||
/// <summary>
|
||||
/// 选择该选项
|
||||
/// </summary>
|
||||
public void Select()
|
||||
{
|
||||
if (!_option.IsAvailable)
|
||||
{
|
||||
Debug.Log($"{_option.Line} 不可用");
|
||||
return;
|
||||
}
|
||||
|
||||
EnumEventSystem.Global.Send(EventEnum.DialogLine, TransToLine());
|
||||
_onOptionSelected.Invoke(_option.DialogueOptionID);
|
||||
}
|
||||
|
||||
private DialogLine TransToLine()
|
||||
{
|
||||
return new DialogLine
|
||||
{
|
||||
isOption = true,
|
||||
lineId = _option.TextID,
|
||||
line = _option.Line.TextWithoutCharacterName.Text,
|
||||
actor = _option.Line.GetCharacterVo()
|
||||
};
|
||||
}
|
||||
|
||||
public static DialogOption[] GeneOptions(DialogueOption[] dialogueOptions, Action<int> onOptionSelected)
|
||||
{
|
||||
return dialogueOptions
|
||||
.Select(item => new DialogOption { _option = item, _onOptionSelected = onOptionSelected }).ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user