对话框优化
This commit is contained in:
@@ -31,28 +31,14 @@ namespace AibisDream
|
||||
|
||||
private TextParam _textParam;
|
||||
|
||||
private bool _skipLineDelay;
|
||||
private Action _nextStep;
|
||||
|
||||
[Header("跳过阻塞延迟时间/ms")] [SerializeField]
|
||||
private int delayTime = 300;
|
||||
|
||||
[SerializeReference] private GameObject choiceButtonPrefab;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
InitComponents();
|
||||
AddSomeListener();
|
||||
}
|
||||
|
||||
private void AddSomeListener()
|
||||
{
|
||||
// 对话显示后有一段延时不可跳过
|
||||
_dialogText.onTypewriterStart.AddListener(() =>
|
||||
{
|
||||
_skipLineDelay = true;
|
||||
_ = CommonUtil.Delay(delayTime, () => { _skipLineDelay = false; });
|
||||
});
|
||||
RegisterEvents();
|
||||
}
|
||||
|
||||
#region 初始化
|
||||
@@ -64,6 +50,11 @@ namespace AibisDream
|
||||
_nextArray = transform.Find(NextArray)?.gameObject;
|
||||
_choiceBox = transform.Find(ChoiceBox)?.gameObject;
|
||||
}
|
||||
|
||||
private void RegisterEvents()
|
||||
{
|
||||
_dialogText.onTextShowed.AddListener(OnTextShowed);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -96,19 +87,14 @@ namespace AibisDream
|
||||
// 显示内容
|
||||
ShowActorName(character);
|
||||
_dialogText.ShowText(dialogLine);
|
||||
|
||||
// 自动跳过的回调很难独立Remove,只能全部清空再注册,下策
|
||||
_dialogText.onTextShowed.RemoveAllListeners();
|
||||
_dialogText.onTextShowed.AddListener(() => _nextArray.gameObject.SetActive(true));
|
||||
_dialogText.onTextShowed.AddListener(() => EnumEventSystem.Global.Send(DialogEventEnum.LineShown));
|
||||
|
||||
|
||||
_nextStep = nextStep;
|
||||
}
|
||||
|
||||
// 执行自动跳过结局
|
||||
if (isAutoSkip)
|
||||
{
|
||||
_dialogText.onTextShowed.AddListener(() => _ = CommonUtil.Delay(200, NextStep));
|
||||
}
|
||||
private void OnTextShowed()
|
||||
{
|
||||
_nextArray.gameObject.SetActive(true);
|
||||
EnumEventSystem.Global.Send(DialogEventEnum.LineShown);
|
||||
}
|
||||
|
||||
public void NextStep()
|
||||
@@ -116,6 +102,7 @@ namespace AibisDream
|
||||
if (_nextStep == null) return;
|
||||
|
||||
EnumEventSystem.Global.Send(DialogEventEnum.LineEnd);
|
||||
// 关闭对话
|
||||
var next = _nextStep;
|
||||
_nextStep = null;
|
||||
next.Invoke();
|
||||
@@ -177,21 +164,14 @@ namespace AibisDream
|
||||
/// <returns></returns>
|
||||
public bool TrySkipLine(bool isForceSkip)
|
||||
{
|
||||
if (_skipLineDelay && !isForceSkip)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (_dialogText.isShowingText)
|
||||
{
|
||||
_dialogText.SkipTypewriter();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
_nextArray.gameObject.SetActive(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
_nextArray.gameObject.SetActive(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
private void ClearBox()
|
||||
|
||||
Reference in New Issue
Block a user