1
This commit is contained in:
91
Assets/Scripts/Story/Dialog/DialogModule.cs
Normal file
91
Assets/Scripts/Story/Dialog/DialogModule.cs
Normal file
@@ -0,0 +1,91 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text.RegularExpressions;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Ichni.Story
|
||||
{
|
||||
public class DialogSentence
|
||||
{
|
||||
public string content;
|
||||
public string audioEventName;
|
||||
|
||||
public string characterName;
|
||||
public string characterEmotion;
|
||||
|
||||
public DialogSentence()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public DialogSentence(string content, string audioEventName, string characterName, string characterEmotion)
|
||||
{
|
||||
this.content = content;
|
||||
this.audioEventName = audioEventName;
|
||||
this.characterName = characterName;
|
||||
this.characterEmotion = characterEmotion;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 匹配{@FUNCTION},解析函数并返回解析后的语句内容。
|
||||
/// </summary>
|
||||
public string GetInterpretedContent()
|
||||
{
|
||||
List<string> parts = new List<string>();
|
||||
Regex regex = new Regex(@"\{\@.*?\}");
|
||||
int lastIndex = 0;
|
||||
|
||||
foreach (Match match in regex.Matches(content))
|
||||
{
|
||||
if (match.Index > lastIndex)
|
||||
{
|
||||
parts.Add(content.Substring(lastIndex, match.Index - lastIndex));
|
||||
}
|
||||
parts.Add(match.Value);
|
||||
lastIndex = match.Index + match.Length;
|
||||
}
|
||||
|
||||
if (lastIndex < content.Length)
|
||||
{
|
||||
parts.Add(content.Substring(lastIndex));
|
||||
}
|
||||
|
||||
for (int i = 0; i < parts.Count; i++)
|
||||
{
|
||||
if (parts[i].StartsWith("{@") && parts[i].EndsWith("}"))
|
||||
{
|
||||
string expression = parts[i].Substring(2, parts[i].Length - 3);
|
||||
object result = StoryInterpreters.FunctionInterpreter.Eval(expression);
|
||||
parts[i] = result.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
return string.Join("", parts);
|
||||
}
|
||||
}
|
||||
|
||||
public class Choice
|
||||
{
|
||||
public string choiceText;
|
||||
public string hint;
|
||||
public string nextDialogName;
|
||||
}
|
||||
|
||||
public class Condition
|
||||
{
|
||||
public string conditionSentence;
|
||||
public string nextDialogName;
|
||||
|
||||
public bool GetConditionResult()
|
||||
{
|
||||
bool result = StoryInterpreters.ConditionInterpreter.Eval<bool>(conditionSentence);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public class DialogCharacter
|
||||
{
|
||||
public string name;
|
||||
public string title;
|
||||
public Dictionary<string, Sprite> emotions;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user