Command Option 增强及示例
This commit is contained in:
@@ -11,12 +11,19 @@ namespace AibisDream
|
||||
|
||||
public override void RunLine(LocalizedLine dialogueLine, Action onDialogueLineFinished)
|
||||
{
|
||||
// 判断选项选项行
|
||||
if (dialogueLine.Text.IsOptionAttrLine())
|
||||
{
|
||||
isInCommand = true;
|
||||
base.RunLine(dialogueLine, onDialogueLineFinished);
|
||||
return;
|
||||
}
|
||||
// 判断是否进入Command状态
|
||||
isInCommand = dialogueLine.Text.TryGetCommandAttr(out var name);
|
||||
isInCommand = dialogueLine.Text.TryGetCommandAttr(out var curCommandName);
|
||||
if (isInCommand)
|
||||
{
|
||||
// 保存指令
|
||||
commandName = name;
|
||||
commandName = curCommandName;
|
||||
// 进入下一步
|
||||
onDialogueLineFinished.Invoke();
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@ namespace AibisDream
|
||||
{
|
||||
private DialogueRunner dialogueRunner;
|
||||
|
||||
private VariableStorageBehaviour _variableStorage;
|
||||
|
||||
private Dictionary<string, Action<YarnOption[]>> commandMap = new();
|
||||
|
||||
public bool quickRunMode;
|
||||
@@ -17,8 +19,33 @@ namespace AibisDream
|
||||
private void Start()
|
||||
{
|
||||
dialogueRunner = GetComponentInChildren<DialogueRunner>();
|
||||
_variableStorage = GetComponentInChildren<InMemoryVariableStorage>();
|
||||
}
|
||||
|
||||
#region 变量操作
|
||||
|
||||
public bool TryGetVariable<T>(string variableName, out T result)
|
||||
{
|
||||
return _variableStorage.TryGetValue(variableName, out result);
|
||||
}
|
||||
|
||||
public void SetVariable(string variableName, string value)
|
||||
{
|
||||
_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);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// 开启对话
|
||||
/// </summary>
|
||||
@@ -158,7 +185,6 @@ namespace AibisDream
|
||||
[YarnCommand("fade_in")]
|
||||
public static IEnumerator FadeIn(float duration = 1)
|
||||
{
|
||||
Debug.Log("fade_in");
|
||||
return MainUIController.Instance.FadeInSync(duration);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,25 +8,26 @@ 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;
|
||||
}
|
||||
private int _idx;
|
||||
|
||||
private readonly DialogueOption _dialogueOption;
|
||||
|
||||
private Action<int> _onOptionSelected;
|
||||
|
||||
/// <summary>
|
||||
/// 选项中的文字
|
||||
/// </summary>
|
||||
public string Text
|
||||
public string Text => _dialogueOption.Line.TextWithoutCharacterName.Text;
|
||||
|
||||
public bool IsAvailable => _dialogueOption.IsAvailable;
|
||||
|
||||
public int Index => _idx;
|
||||
|
||||
public YarnOption(int idx, DialogueOption dialogueOption, Action<int> onOptionSelected)
|
||||
{
|
||||
get
|
||||
{
|
||||
return dialogueOption.Line.TextWithoutCharacterName.Text;
|
||||
}
|
||||
_dialogueOption = dialogueOption;
|
||||
_onOptionSelected = onOptionSelected;
|
||||
_idx = idx;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -34,15 +35,21 @@ namespace AibisDream
|
||||
/// </summary>
|
||||
public void SelectOption()
|
||||
{
|
||||
if (onOptionSelected == null)
|
||||
if (!IsAvailable)
|
||||
{
|
||||
Debug.LogWarning($"选项 {Text} 不可用");
|
||||
return;
|
||||
}
|
||||
|
||||
if (_onOptionSelected == null)
|
||||
{
|
||||
Debug.LogWarning($"选项 {Text} 已经执行过了");
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
onOptionSelected.Invoke(dialogueOption.DialogueOptionID);
|
||||
onOptionSelected = null;
|
||||
}
|
||||
|
||||
// 执行选项
|
||||
_onOptionSelected.Invoke(_dialogueOption.DialogueOptionID);
|
||||
_onOptionSelected = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -53,10 +60,10 @@ namespace AibisDream
|
||||
/// <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++)
|
||||
var yarnOptions = new YarnOption[options.Length];
|
||||
for (var i = 0; i < options.Length; i++)
|
||||
{
|
||||
yarnOptions[i] = new YarnOption(options[i], onOptionSelected);
|
||||
yarnOptions[i] = new YarnOption(i, options[i], onOptionSelected);
|
||||
}
|
||||
|
||||
return yarnOptions;
|
||||
|
||||
Reference in New Issue
Block a user