新增测试模式;增加选择项接入
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Yarn.Markup;
|
||||
using Yarn.Unity;
|
||||
|
||||
namespace AibisDream
|
||||
{
|
||||
public class CommandOptionView : DialogueViewBase
|
||||
{
|
||||
// 进入指令选项模式
|
||||
private bool isInCommand;
|
||||
private string commandName;
|
||||
|
||||
public override void RunLine(LocalizedLine dialogueLine, Action onDialogueLineFinished)
|
||||
{
|
||||
// 判断是否进入Command状态
|
||||
isInCommand = dialogueLine.Text.TryGetCommandAttr(out var name);
|
||||
if (isInCommand)
|
||||
{
|
||||
// 保存指令
|
||||
commandName = name;
|
||||
// 进入下一步
|
||||
onDialogueLineFinished.Invoke();
|
||||
}
|
||||
else
|
||||
{
|
||||
base.RunLine(dialogueLine, onDialogueLineFinished);
|
||||
}
|
||||
}
|
||||
|
||||
public override void RunOptions(DialogueOption[] dialogueOptions, Action<int> onOptionSelected)
|
||||
{
|
||||
// 非指令直接跳过
|
||||
if (!isInCommand)
|
||||
{
|
||||
base.RunOptions(dialogueOptions, onOptionSelected);
|
||||
return;
|
||||
}
|
||||
|
||||
// 传输选项
|
||||
YarnOption[] options = YarnOption.GeneOptions(dialogueOptions, onOptionSelected);
|
||||
DialogController.Instance.InvokeOptionCommand(commandName, options);
|
||||
commandName = null;
|
||||
}
|
||||
|
||||
public override void InterruptLine(LocalizedLine dialogueLine, Action onDialogueLineFinished)
|
||||
{
|
||||
base.InterruptLine(dialogueLine, onDialogueLineFinished);
|
||||
}
|
||||
|
||||
public override void DismissLine(Action onDismissalComplete)
|
||||
{
|
||||
base.DismissLine(onDismissalComplete);
|
||||
}
|
||||
|
||||
public override void UserRequestedViewAdvancement()
|
||||
{
|
||||
base.UserRequestedViewAdvancement();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4e61040b961ba1446ad453ee17f4a737
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
@@ -11,6 +12,8 @@ namespace AibisDream
|
||||
{
|
||||
private DialogueRunner dialogueRunner;
|
||||
|
||||
private Dictionary<string, Action<YarnOption[]>> commandMap = new Dictionary<string, Action<YarnOption[]>>();
|
||||
|
||||
private void Start()
|
||||
{
|
||||
dialogueRunner = GetComponentInChildren<DialogueRunner>();
|
||||
@@ -26,6 +29,55 @@ namespace AibisDream
|
||||
dialogueRunner.StartDialogue("Start");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 执行指令
|
||||
/// </summary>
|
||||
/// <param name="commandName">指令名称</param>
|
||||
public void InvokeOptionCommand(string commandName, YarnOption[] options)
|
||||
{
|
||||
if (commandName == null) { }
|
||||
|
||||
if (commandMap.TryGetValue(commandName, out var action))
|
||||
{
|
||||
action(options);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning($"没有找到 {commandName} 命令");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 注册带选项指令
|
||||
/// </summary>
|
||||
/// <param name="commandName">指令名称</param>
|
||||
/// <param name="commandAction">指令函数</param>
|
||||
public void RegisterOptionCommand(string commandName, Action<YarnOption[]> commandAction)
|
||||
{
|
||||
if (commandMap.ContainsKey(commandName))
|
||||
{
|
||||
Debug.Log($"命令 {commandName} 并未注册,重新注册会替换旧指令");
|
||||
}
|
||||
|
||||
commandMap[commandName] = commandAction;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 卸载指令
|
||||
/// </summary>
|
||||
/// <param name="commandName">指令名称</param>
|
||||
public void RemoveOptionCommand(string commandName)
|
||||
{
|
||||
if (commandMap.ContainsKey(commandName))
|
||||
{
|
||||
commandMap.Remove(commandName);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log($"命令 {commandName} 并未注册,重新注册会替换旧指令");
|
||||
}
|
||||
}
|
||||
|
||||
#region 各种命令
|
||||
[YarnCommand("switch_tv")]
|
||||
public static void SwitchTV(string picName)
|
||||
|
||||
@@ -8,13 +8,33 @@ namespace AibisDream
|
||||
{
|
||||
public class LineView : DialogueViewBase
|
||||
{
|
||||
// ½øÈëÖ¸ÁîÑ¡Ïîģʽ
|
||||
private bool isInCommand;
|
||||
|
||||
public override void RunLine(LocalizedLine dialogueLine, Action onDialogueLineFinished)
|
||||
{
|
||||
DialogUiViewer.Instance.ShowLine(dialogueLine.TextWithoutCharacterName.Text, dialogueLine.CharacterName, onDialogueLineFinished);
|
||||
isInCommand = dialogueLine.Text.HasCommandAttr();
|
||||
|
||||
if (isInCommand)
|
||||
{
|
||||
DialogUiViewer.Instance.HideDialog();
|
||||
base.RunLine(dialogueLine, onDialogueLineFinished);
|
||||
return;
|
||||
}
|
||||
|
||||
DialogUiViewer.Instance.ShowLine(dialogueLine.TextWithoutCharacterName.Text,
|
||||
dialogueLine.CharacterName, onDialogueLineFinished);
|
||||
}
|
||||
|
||||
public override void RunOptions(DialogueOption[] dialogueOptions, Action<int> onOptionSelected)
|
||||
{
|
||||
if (isInCommand)
|
||||
{
|
||||
DialogUiViewer.Instance.HideDialog();
|
||||
base.RunOptions(dialogueOptions, onOptionSelected);
|
||||
return;
|
||||
}
|
||||
|
||||
DialogUiViewer.Instance.ShowOptions(dialogueOptions, onOptionSelected);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Yarn.Unity;
|
||||
|
||||
namespace AibisDream
|
||||
{
|
||||
public class YarnOption
|
||||
{
|
||||
private DialogueOption dialogueOption;
|
||||
|
||||
private Action<int> onOptionSelected;
|
||||
|
||||
public YarnOption(DialogueOption dialogueOption, Action<int> onOptionSelected)
|
||||
{
|
||||
this.dialogueOption = dialogueOption;
|
||||
this.onOptionSelected = onOptionSelected;
|
||||
}
|
||||
|
||||
public string Text
|
||||
{
|
||||
get
|
||||
{
|
||||
return dialogueOption.Line.TextWithoutCharacterName.Text;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 选择该选项
|
||||
/// </summary>
|
||||
public void SelectOption()
|
||||
{
|
||||
if (onOptionSelected == null)
|
||||
{
|
||||
Debug.LogWarning($"选项 {Text} 已经执行过了");
|
||||
}
|
||||
else
|
||||
{
|
||||
onOptionSelected.Invoke(dialogueOption.DialogueOptionID);
|
||||
onOptionSelected = null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 生成选项
|
||||
/// </summary>
|
||||
/// <param name="options">原始选项</param>
|
||||
/// <param name="onOptionSelected">选择</param>
|
||||
/// <returns>包装选项</returns>
|
||||
public static YarnOption[] GeneOptions(DialogueOption[] options, Action<int> onOptionSelected)
|
||||
{
|
||||
YarnOption[] yarnOptions = new YarnOption[options.Length];
|
||||
for (int i = 0; i < options.Length; i++)
|
||||
{
|
||||
yarnOptions[i] = new YarnOption(options[i], onOptionSelected);
|
||||
}
|
||||
|
||||
return yarnOptions;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 19f7a96d35f4ad54ea493eb8c65ab6f0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user