本地化
This commit is contained in:
@@ -10,6 +10,7 @@ namespace AibisDream
|
||||
public class DialogController : Singleton<DialogController>
|
||||
{
|
||||
private DialogueRunner _dialogueRunner;
|
||||
private LocalisedLineProvider _lineProvider;
|
||||
|
||||
# region controller状态标识
|
||||
|
||||
@@ -45,6 +46,7 @@ namespace AibisDream
|
||||
private void Start()
|
||||
{
|
||||
_dialogueRunner = GetComponentInChildren<DialogueRunner>();
|
||||
_lineProvider = GetComponentInChildren<LocalisedLineProvider>();
|
||||
|
||||
_dialogueRunner.onDialogueStart.AddListener(() =>
|
||||
{
|
||||
@@ -58,7 +60,6 @@ namespace AibisDream
|
||||
OnDialogueComplete?.Invoke();
|
||||
IsTalking = false;
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -68,6 +69,7 @@ namespace AibisDream
|
||||
public void StartDialog(YarnProject yarnProject)
|
||||
{
|
||||
_dialogueRunner.SetProject(yarnProject);
|
||||
_lineProvider.InitStringTable(yarnProject.name);
|
||||
_dialogueRunner.StartDialogue("Start");
|
||||
}
|
||||
|
||||
@@ -82,6 +84,7 @@ namespace AibisDream
|
||||
public void LoadDialog(YarnProject yarnProject)
|
||||
{
|
||||
_dialogueRunner.SetProject(yarnProject);
|
||||
_lineProvider.InitStringTable(yarnProject.name);
|
||||
_dialogueRunner.StartDialogue("Center");
|
||||
}
|
||||
|
||||
@@ -93,7 +96,7 @@ namespace AibisDream
|
||||
}
|
||||
}
|
||||
|
||||
public bool CheckIfNodeExistInCurrentYarnProject(string nodeName)
|
||||
private bool CheckIfNodeExistInCurrentYarnProject(string nodeName)
|
||||
{
|
||||
YarnProject currentProject = _dialogueRunner.yarnProject;
|
||||
string[] nodeNames = currentProject.NodeNames;
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
using System.Linq;
|
||||
using UnityEngine.Localization.Settings;
|
||||
using Yarn.Unity;
|
||||
using AibisDream.Framework;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AibisDream
|
||||
{
|
||||
public class LocalisedLineProvider : LineProviderBehaviour
|
||||
{
|
||||
private LocalizationTable _localizationTable;
|
||||
|
||||
public override string LocaleCode => LocalizationSettings.SelectedLocale.Identifier.Code;
|
||||
|
||||
// 本地化表存在即可用
|
||||
public override bool LinesAvailable => _localizationTable != null;
|
||||
|
||||
// We're good to go!
|
||||
public override LocalizedLine GetLocalizedLine(Yarn.Line line)
|
||||
{
|
||||
var text = line.ID;
|
||||
if (_localizationTable != null)
|
||||
{
|
||||
text = _localizationTable[line.ID]?.LocalizedValue ??
|
||||
$"Error: Missing localisation for line {line.ID} in string table {_localizationTable.LocaleIdentifier}";
|
||||
}
|
||||
|
||||
// Construct the localized line
|
||||
LocalizedLine localizedLine = new LocalizedLine
|
||||
{
|
||||
TextID = line.ID,
|
||||
RawText = text,
|
||||
Substitutions = line.Substitutions,
|
||||
Metadata = YarnProject.lineMetadata.GetMetadata(line.ID)
|
||||
};
|
||||
|
||||
// Attempt to fetch metadata tags for this line from the string
|
||||
// table
|
||||
if (_localizationTable == null) return localizedLine;
|
||||
|
||||
var metadata = _localizationTable[line.ID]?.SharedEntry.Metadata
|
||||
.GetMetadata<Yarn.Unity.UnityLocalization.LineMetadata>();
|
||||
|
||||
if (metadata != null && localizedLine.Metadata != null)
|
||||
{
|
||||
localizedLine.Metadata = localizedLine.Metadata.Concat(metadata.tags).ToArray();
|
||||
}
|
||||
else if (localizedLine.Metadata == null && metadata != null)
|
||||
{
|
||||
localizedLine.Metadata = metadata.tags;
|
||||
}
|
||||
|
||||
return localizedLine;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化StringTable
|
||||
/// </summary>
|
||||
/// <param name="tableName">本地化表名称</param>
|
||||
/// <returns>协程</returns>
|
||||
public void InitStringTable(string tableName)
|
||||
{
|
||||
Debug.Log(tableName + "Init");
|
||||
// 释放
|
||||
_localizationTable?.Dispose();
|
||||
// 加载
|
||||
_localizationTable = new LocalizationTable(tableName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8d3a78e02d644e96a9e0caa46f1e442b
|
||||
timeCreated: 1745489761
|
||||
Reference in New Issue
Block a user