feat(dialog): 支持叙事文本语义样式展开
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -8,6 +8,7 @@ namespace AibisDream
|
||||
public const string Root = "AIBIS";
|
||||
|
||||
public const string NarrativeTalkScene = Root + "/叙事/对话场景";
|
||||
public const string NarrativeTextStyle = Root + "/叙事/文本样式";
|
||||
public const string FrameAnimationGraph = Root + "/角色动画/帧动画 Graph";
|
||||
public const string FrameClip = Root + "/角色动画/帧动画 Clip";
|
||||
public const string BubbleStyle = Root + "/对话 UI/气泡样式";
|
||||
|
||||
@@ -29,6 +29,9 @@ namespace AibisDream
|
||||
[SerializeField, Language]
|
||||
private string _fallbackLocaleCode = System.Globalization.CultureInfo.CurrentCulture.TwoLetterISOLanguageName;
|
||||
|
||||
[SerializeField]
|
||||
private NarrativeTextStyleConfig _narrativeTextStyle;
|
||||
|
||||
public string AssetLocaleCode
|
||||
{
|
||||
get => _assetLocaleCode;
|
||||
@@ -82,7 +85,9 @@ namespace AibisDream
|
||||
line.Substitutions[i] = LocalizationKit.LocalizeParam(line.Substitutions[i]);
|
||||
}
|
||||
|
||||
// 保留旧 LocalisedLineProvider 的文本转义处理
|
||||
// 先展开项目级语义标记,再保留旧 LocalisedLineProvider 的文本转义处理。
|
||||
// ULM 的 [[vertexp ...]] 会由 Escape 转成 Text Animator 使用的花括号标签。
|
||||
text = NarrativeTextStyleExpander.Expand(text, _narrativeTextStyle);
|
||||
text = CommonUtil.Escape(text);
|
||||
|
||||
var parseResult = lineParser.ParseString(Yarn.Markup.LineParser.ExpandSubstitutions(text, line.Substitutions), LocaleCode);
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
using System.Globalization;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AibisDream
|
||||
{
|
||||
[CreateAssetMenu(
|
||||
fileName = "NarrativeTextStyleConfig",
|
||||
menuName = AibisAssetMenus.NarrativeTextStyle)]
|
||||
public sealed class NarrativeTextStyleConfig : ScriptableObject
|
||||
{
|
||||
[Header("语义颜色")]
|
||||
[SerializeField] private Color _asideColor = new Color32(0x5F, 0x5F, 0x5F, 0xFF);
|
||||
[SerializeField] private Color _termColor = new Color32(0x52, 0xB6, 0xFF, 0xFF);
|
||||
[SerializeField] private Color _keyColor = new Color32(0xFF, 0xB2, 0x00, 0xFF);
|
||||
|
||||
[Header("节奏与效果")]
|
||||
[SerializeField, Min(0f)] private float _commaPauseSeconds = 0.2f;
|
||||
[SerializeField] private string _ulmEffectPrefix = "[[vertexp d=0.05 bot]]";
|
||||
[SerializeField] private string _jokeOpenTag = "<wiggle a=0.3 s=0.1>";
|
||||
[SerializeField] private string _jokeCloseTag = "</wiggle>";
|
||||
|
||||
public Color AsideColor => _asideColor;
|
||||
public Color TermColor => _termColor;
|
||||
public Color KeyColor => _keyColor;
|
||||
public float CommaPauseSeconds => _commaPauseSeconds;
|
||||
public string UlmEffectPrefix => _ulmEffectPrefix;
|
||||
public string JokeOpenTag => _jokeOpenTag;
|
||||
public string JokeCloseTag => _jokeCloseTag;
|
||||
}
|
||||
|
||||
public static class NarrativeTextStyleExpander
|
||||
{
|
||||
private static readonly Color DefaultAsideColor = new Color32(0x5F, 0x5F, 0x5F, 0xFF);
|
||||
private static readonly Color DefaultTermColor = new Color32(0x52, 0xB6, 0xFF, 0xFF);
|
||||
private static readonly Color DefaultKeyColor = new Color32(0xFF, 0xB2, 0x00, 0xFF);
|
||||
|
||||
public static string Expand(string text, NarrativeTextStyleConfig config)
|
||||
{
|
||||
if (string.IsNullOrEmpty(text))
|
||||
{
|
||||
return text;
|
||||
}
|
||||
|
||||
Color asideColor = config != null ? config.AsideColor : DefaultAsideColor;
|
||||
Color termColor = config != null ? config.TermColor : DefaultTermColor;
|
||||
Color keyColor = config != null ? config.KeyColor : DefaultKeyColor;
|
||||
float commaPause = config != null ? config.CommaPauseSeconds : 0.2f;
|
||||
string ulmPrefix = config != null
|
||||
? config.UlmEffectPrefix
|
||||
: "[[vertexp d=0.05 bot]]";
|
||||
string jokeOpen = config != null
|
||||
? config.JokeOpenTag
|
||||
: "<wiggle a=0.3 s=0.1>";
|
||||
string jokeClose = config != null ? config.JokeCloseTag : "</wiggle>";
|
||||
|
||||
return text
|
||||
.Replace("[[aside]]", ColorOpen(asideColor))
|
||||
.Replace("[[/aside]]", "</color>")
|
||||
.Replace("[[term]]", ColorOpen(termColor))
|
||||
.Replace("[[/term]]", "</color>")
|
||||
.Replace("[[key]]", ColorOpen(keyColor))
|
||||
.Replace("[[/key]]", "</color>")
|
||||
.Replace(
|
||||
"[[comma-pause]]",
|
||||
$"<waitfor={commaPause.ToString("0.###", CultureInfo.InvariantCulture)}>")
|
||||
.Replace("[[ulm]]", ulmPrefix)
|
||||
.Replace("[[joke]]", jokeOpen)
|
||||
.Replace("[[/joke]]", jokeClose);
|
||||
}
|
||||
|
||||
private static string ColorOpen(Color color)
|
||||
{
|
||||
// This runs after Yarn has parsed the source, so the hash must not
|
||||
// carry Yarn's source-level escape into TextMesh Pro.
|
||||
return $"<color=#{ColorUtility.ToHtmlStringRGB(color)}>";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0df9c4430661480e9c647ea7e22a92b6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user