自动跳过和判断是否在对话的逻辑

This commit is contained in:
2024-08-29 00:05:25 +08:00
parent ef6aac8474
commit 144547bcb3
8 changed files with 121 additions and 26 deletions
@@ -42,6 +42,7 @@ namespace AibisDream
return;
}
DialogController.Instance.IsTalking = false;
// 传输选项
YarnOption[] options = YarnOption.GeneOptions(dialogueOptions, onOptionSelected);
DialogController.Instance.InvokeOptionCommand(commandName, options);
@@ -2,6 +2,7 @@ using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using Yarn.Unity;
namespace AibisDream
@@ -14,8 +15,28 @@ namespace AibisDream
private Dictionary<string, Action<YarnOption[]>> commandMap = new();
public static event Action OnDialogueStart;
public static event Action OnDialogueComplete;
private bool _isTalking;
public bool IsTalking
{
set
{
if (_isTalking == value) return;
_isTalking = value;
if (value)
{
OnDialogueStart?.Invoke();
}
else
{
OnDialogueComplete?.Invoke();
}
}
}
public static UnityAction OnDialogueStart;
public static UnityAction OnDialogueComplete;
public bool quickRunMode;
@@ -23,8 +44,10 @@ namespace AibisDream
{
dialogueRunner = GetComponentInChildren<DialogueRunner>();
_variableStorage = GetComponentInChildren<InMemoryVariableStorage>();
dialogueRunner.onDialogueStart.AddListener(() => OnDialogueStart?.Invoke());
dialogueRunner.onDialogueComplete.AddListener(() => OnDialogueComplete?.Invoke());
dialogueRunner.onDialogueStart.AddListener(() => { OnDialogueStart?.Invoke(); });
dialogueRunner.onDialogueComplete.AddListener(() => { OnDialogueComplete?.Invoke(); });
dialogueRunner.AddCommandListener(_ => { IsTalking = false; });
}
#region
@@ -38,12 +61,12 @@ namespace AibisDream
{
_variableStorage.SetValue(variableName, value);
}
public void SetVariable(string variableName, bool value)
{
_variableStorage.SetValue(variableName, value);
}
public void SetVariable(string variableName, float value)
{
_variableStorage.SetValue(variableName, value);
@@ -95,8 +118,7 @@ namespace AibisDream
{
Debug.Log($"命令 {commandName} 已经存在,将被替换");
}
Debug.Log(commandMap == null);
commandMap[commandName] = commandAction;
}
@@ -137,7 +159,6 @@ namespace AibisDream
[YarnCommand("character_init")]
public static void CharacterInit(string picName)
{
Debug.Log(picName);
MainSceneController.Instance.Guest.SwitchImage(picName);
MainSceneController.Instance.Guest.Show();
}
+26 -3
View File
@@ -1,10 +1,13 @@
using System;
using System.Linq;
using Yarn.Unity;
namespace AibisDream
{
public class LineView : DialogueViewBase
{
private const string AutoNext = "auto_next";
// 进入指令选项模式
private bool _isInCommand;
@@ -18,9 +21,8 @@ namespace AibisDream
base.RunLine(dialogueLine, onDialogueLineFinished);
return;
}
DialogUiViewer.Instance.ShowLine(dialogueLine.TextWithoutCharacterName.Text,
dialogueLine.CharacterName, onDialogueLineFinished);
HandleLineOutput(dialogueLine, onDialogueLineFinished);
if (DialogController.Instance.quickRunMode)
{
@@ -28,6 +30,26 @@ namespace AibisDream
}
}
private void HandleLineOutput(LocalizedLine dialogueLine, Action onDialogueLineFinished)
{
// 对话系统正在交谈状态
DialogController.Instance.IsTalking = true;
// 解析LocalizedLine
if (dialogueLine.Metadata != null && dialogueLine.Metadata.Contains(AutoNext))
{
// 自动跳过
DialogUiViewer.Instance.ShowAutoLine(dialogueLine.TextWithoutCharacterName.Text,
dialogueLine.CharacterName, onDialogueLineFinished);
}
else
{
// 需要玩家点击
DialogUiViewer.Instance.ShowLine(dialogueLine.TextWithoutCharacterName.Text,
dialogueLine.CharacterName, onDialogueLineFinished);
}
}
public override void RunOptions(DialogueOption[] dialogueOptions, Action<int> onOptionSelected)
{
if (_isInCommand)
@@ -37,6 +59,7 @@ namespace AibisDream
return;
}
DialogController.Instance.IsTalking = true;
DialogUiViewer.Instance.ShowOptions(dialogueOptions, onOptionSelected);
}