Ver.0.3.0.33
This commit is contained in:
@@ -14,18 +14,14 @@ namespace AibisDream
|
||||
public static void NextYarn()
|
||||
{
|
||||
EnumEventSystem.Global.Send(EventEnum.NextYarn);
|
||||
DialogController.Instance.ClearVariables();
|
||||
DialogController.Instance.StartCoroutine(GameLoopManager.Instance.NextSceneSo());
|
||||
}
|
||||
[YarnCommand("BackToMenu")]
|
||||
public static void BackToMenu()
|
||||
{
|
||||
StartMenu.Instance.BackToMenu();
|
||||
StorageSystem.Instance.ClearLocal();
|
||||
DialogController.Instance.StartCoroutine(GameManager.Instance.NextSceneSo());
|
||||
}
|
||||
|
||||
[YarnCommand("OpenEndMenu")]
|
||||
public static void OpenEndMenu()
|
||||
{
|
||||
EndMenu.Instance.OpenEndMenu();
|
||||
UIManager.Instance.ShowPanel<EndPanel>();
|
||||
}
|
||||
|
||||
[Obsolete]
|
||||
@@ -41,7 +37,7 @@ namespace AibisDream
|
||||
{
|
||||
Debug.Log("show_tv_scene 已废弃");
|
||||
}
|
||||
|
||||
|
||||
[YarnCommand("load_scene")]
|
||||
public static IEnumerator LoadScene(string sceneName, float duration = 1)
|
||||
{
|
||||
@@ -64,37 +60,78 @@ namespace AibisDream
|
||||
[YarnCommand("fade_in")]
|
||||
public static IEnumerator FadeIn(float duration = 1)
|
||||
{
|
||||
return MainUIController.Instance.FadeInSync(duration);
|
||||
var panel = UIManager.Instance.GetPanel<PlayToolPanel>();
|
||||
return panel.FadeInAsync(duration);
|
||||
}
|
||||
|
||||
[YarnCommand("fade_out")]
|
||||
public static IEnumerator FadeOut(float duration = 1)
|
||||
{
|
||||
return MainUIController.Instance.FadeOutSync(duration);
|
||||
var panel = UIManager.Instance.GetPanel<PlayToolPanel>();
|
||||
return panel.FadeOutAsync(duration);
|
||||
}
|
||||
|
||||
[YarnCommand("fade_in_sync")]
|
||||
public static void FadeInSync(float duration = 1)
|
||||
{
|
||||
var panel = UIManager.Instance.GetPanel<PlayToolPanel>();
|
||||
panel.FadeInSync(duration);
|
||||
}
|
||||
|
||||
[YarnCommand("fade_out_sync")]
|
||||
public static void FadeOutSync(float duration = 1)
|
||||
{
|
||||
var panel = UIManager.Instance.GetPanel<PlayToolPanel>();
|
||||
panel.FadeOutSync(duration);
|
||||
}
|
||||
|
||||
[YarnCommand("show_obj")]
|
||||
public static IEnumerator ShowObj(string picName)
|
||||
{
|
||||
return MainUIController.Instance.ShowObj(picName);
|
||||
var panel = UIManager.Instance.GetPanel<PlayToolPanel>();
|
||||
return panel.ShowObj(picName);
|
||||
}
|
||||
|
||||
[YarnCommand("hide_obj")]
|
||||
public static IEnumerator HideObj()
|
||||
{
|
||||
return MainUIController.Instance.HideObj();
|
||||
var panel = UIManager.Instance.GetPanel<PlayToolPanel>();
|
||||
return panel.HideObj();
|
||||
}
|
||||
|
||||
|
||||
[YarnCommand("show_full_screen")]
|
||||
public static IEnumerator ShowFullScreen(string picName)
|
||||
{
|
||||
return MainUIController.Instance.ShowFullScreen(picName);
|
||||
var panel = UIManager.Instance.GetPanel<PlayToolPanel>();
|
||||
return panel.ShowFullScreen(picName);
|
||||
}
|
||||
|
||||
[YarnCommand("hide_full_screen")]
|
||||
public static IEnumerator HideFullScreen()
|
||||
{
|
||||
return MainUIController.Instance.HideFullScreen();
|
||||
var panel = UIManager.Instance.GetPanel<PlayToolPanel>();
|
||||
return panel.HideFullScreen();
|
||||
}
|
||||
|
||||
[YarnCommand("open_progress_window")]
|
||||
public static IEnumerator OpenProgressWindow(string title, string description, float duration)
|
||||
{
|
||||
var panel = UIManager.Instance.GetPanel<PlayToolPanel>();
|
||||
return panel.OpenProgressWindow(title, description, duration);
|
||||
}
|
||||
|
||||
[YarnCommand("open_warning_window")]
|
||||
public static IEnumerator OpenWarningWindow(string description)
|
||||
{
|
||||
var panel = UIManager.Instance.GetPanel<PlayToolPanel>();
|
||||
return panel.OpenWarningWindow(description);
|
||||
}
|
||||
|
||||
[YarnCommand("flash_red")]
|
||||
public static IEnumerator FlashRed(float duration = 0.2f)
|
||||
{
|
||||
var panel = UIManager.Instance.GetPanel<PlayToolPanel>();
|
||||
return panel.FlashRed(duration);
|
||||
}
|
||||
|
||||
[YarnCommand("switch_dialog_viewer")]
|
||||
|
||||
@@ -10,33 +10,12 @@ namespace AibisDream
|
||||
public class DialogController : Singleton<DialogController>
|
||||
{
|
||||
private DialogueRunner _dialogueRunner;
|
||||
private VariableStorageBehaviour _variableStorage;
|
||||
private LocalisedLineProvider _lineProvider;
|
||||
|
||||
# region controller状态标识
|
||||
|
||||
private bool _isTalking;
|
||||
|
||||
public bool IsTalking
|
||||
{
|
||||
set
|
||||
{
|
||||
if (_isTalking == value) return;
|
||||
|
||||
_isTalking = value;
|
||||
Debug.Log($"IsTalking 状态更改: {_isTalking}");
|
||||
if (value)
|
||||
{
|
||||
OnDialogueStart?.Invoke();
|
||||
}
|
||||
else
|
||||
{
|
||||
OnDialogueComplete?.Invoke();
|
||||
}
|
||||
}
|
||||
get => _isTalking;
|
||||
}
|
||||
|
||||
public bool quickRunMode;
|
||||
public bool autoRunMode;
|
||||
|
||||
# endregion
|
||||
|
||||
@@ -46,71 +25,20 @@ namespace AibisDream
|
||||
private void Start()
|
||||
{
|
||||
_dialogueRunner = GetComponentInChildren<DialogueRunner>();
|
||||
_variableStorage = GetComponentInChildren<InMemoryVariableStorage>();
|
||||
_lineProvider = GetComponentInChildren<LocalisedLineProvider>();
|
||||
|
||||
_dialogueRunner.onDialogueStart.AddListener(() =>
|
||||
{
|
||||
EnumEventSystem.Global.Send(InteractionEventEnum.End);
|
||||
OnDialogueStart?.Invoke();
|
||||
IsTalking = true;
|
||||
});
|
||||
_dialogueRunner.onDialogueComplete.AddListener(() =>
|
||||
{
|
||||
EnumEventSystem.Global.Send(InteractionEventEnum.Start);
|
||||
OnDialogueComplete?.Invoke();
|
||||
IsTalking = false;
|
||||
});
|
||||
|
||||
RegisterEvent();
|
||||
}
|
||||
|
||||
private void RegisterEvent()
|
||||
{
|
||||
EnumEventSystem.Global.Register(EventEnum.SceneUnload, ResetDialog);
|
||||
}
|
||||
|
||||
private void ResetDialog()
|
||||
{
|
||||
_dialogueRunner.Stop();
|
||||
_variableStorage.Clear();
|
||||
DialogCanvasManager.Instance.HideDialog();
|
||||
DialogCanvasManager.Instance.SwitchDialogView(DialogViewType.OldBox);
|
||||
}
|
||||
|
||||
#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);
|
||||
}
|
||||
|
||||
public bool Contains(string variableName)
|
||||
{
|
||||
return _variableStorage.Contains(variableName);
|
||||
}
|
||||
|
||||
public void ClearVariables()
|
||||
{
|
||||
_variableStorage.Clear();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// 开启对话
|
||||
/// </summary>
|
||||
@@ -118,16 +46,27 @@ namespace AibisDream
|
||||
public void StartDialog(YarnProject yarnProject)
|
||||
{
|
||||
_dialogueRunner.SetProject(yarnProject);
|
||||
_lineProvider.InitStringTable(yarnProject.name);
|
||||
_dialogueRunner.StartDialogue("Start");
|
||||
}
|
||||
|
||||
public string GetCurLocalizedTableName()
|
||||
{
|
||||
return _lineProvider.GetStringTableName();
|
||||
}
|
||||
|
||||
public void StopDialog()
|
||||
{
|
||||
_dialogueRunner.Stop();
|
||||
StorageSystem.Instance.Clear();
|
||||
DialogCanvasManager.Instance.HideDialog();
|
||||
DialogCanvasManager.Instance.SwitchDialogView(DialogViewType.StandardBubble);
|
||||
}
|
||||
|
||||
public void LoadDialog(YarnProject yarnProject)
|
||||
{
|
||||
_dialogueRunner.SetProject(yarnProject);
|
||||
_lineProvider.InitStringTable(yarnProject.name);
|
||||
_dialogueRunner.StartDialogue("Center");
|
||||
}
|
||||
|
||||
@@ -139,7 +78,7 @@ namespace AibisDream
|
||||
}
|
||||
}
|
||||
|
||||
public bool CheckIfNodeExistInCurrentYarnProject(string nodeName)
|
||||
private bool CheckIfNodeExistInCurrentYarnProject(string nodeName)
|
||||
{
|
||||
YarnProject currentProject = _dialogueRunner.yarnProject;
|
||||
string[] nodeNames = currentProject.NodeNames;
|
||||
@@ -153,7 +92,7 @@ namespace AibisDream
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 跳到下一句
|
||||
/// </summary>
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace AibisDream
|
||||
private void HandleLineOutput(LocalizedLine dialogueLine, Action onDialogueLineFinished)
|
||||
{
|
||||
DialogCanvasManager.Instance.ShowLine(dialogueLine.TextWithoutCharacterName.Text,
|
||||
dialogueLine.GetCharacterVo(), onDialogueLineFinished, dialogueLine.IsAutoSkipLine());
|
||||
dialogueLine.GetCharacterVo(), onDialogueLineFinished, dialogueLine.TextID, dialogueLine.IsAutoSkipLine());
|
||||
}
|
||||
|
||||
public override void RunOptions(DialogueOption[] dialogueOptions, Action<int> onOptionSelected)
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
using System.Linq;
|
||||
using UnityEngine.Localization.Settings;
|
||||
using Yarn.Unity;
|
||||
using AibisDream.Framework;
|
||||
using AibisDream.Utility;
|
||||
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;
|
||||
|
||||
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}";
|
||||
}
|
||||
|
||||
LocalizeSubstitutions(line);
|
||||
var resText = CommonUtil.Escape(text);
|
||||
|
||||
// Construct the localized line
|
||||
LocalizedLine localizedLine = new LocalizedLine
|
||||
{
|
||||
TextID = line.ID,
|
||||
RawText = resText,
|
||||
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;
|
||||
}
|
||||
|
||||
private void LocalizeSubstitutions(Yarn.Line line)
|
||||
{
|
||||
for (var i = 0; i < line.Substitutions.Length; i++)
|
||||
{
|
||||
line.Substitutions[i] = LocalizationKit.LocalizeParam(line.Substitutions[i], _localizationTable);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化StringTable
|
||||
/// </summary>
|
||||
/// <param name="tableName">本地化表名称</param>
|
||||
/// <returns>协程</returns>
|
||||
public void InitStringTable(string tableName)
|
||||
{
|
||||
// 释放
|
||||
_localizationTable?.Dispose();
|
||||
// 加载
|
||||
_localizationTable = new LocalizationTable(tableName);
|
||||
}
|
||||
|
||||
public string GetStringTableName()
|
||||
{
|
||||
return _localizationTable.TableName;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8d3a78e02d644e96a9e0caa46f1e442b
|
||||
timeCreated: 1745489761
|
||||
Reference in New Issue
Block a user