138 lines
5.2 KiB
C#
138 lines
5.2 KiB
C#
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using AibisDream.FixSystem;
|
||
using Yarn.Unity;
|
||
|
||
namespace AibisDream.MiniGame.Language
|
||
{
|
||
/// <summary>
|
||
/// 表达系统的 Yarn 命令接口(原语言系统)
|
||
/// </summary>
|
||
public static class LanguageYarnCommand
|
||
{
|
||
private static AibisDream.ExpressionManager ExpressionManager => FixSystemCenter.SystemDic.Get<AibisDream.ExpressionManager>();
|
||
|
||
/// <summary>
|
||
/// 打开表达视图(只显示美术背景,不启动粒子系统)
|
||
/// <<open_expression>>
|
||
/// </summary>
|
||
[YarnCommand("open_expression")]
|
||
public static void OpenExpression()
|
||
{
|
||
if (ExpressionManager == null)
|
||
{
|
||
UnityEngine.Debug.LogError("ExpressionManager 未找到!请确保场景中有 ExpressionManager 组件。");
|
||
return;
|
||
}
|
||
|
||
ExpressionManager.OpenView();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 启动表达粒子系统(在打开视图后调用)
|
||
/// <<start_expression "我好怕|怎么办|不行|好难" "我能做到" "ExpressionCompleted">>
|
||
/// </summary>
|
||
/// <param name="anxietyPhrasesStr">焦虑短句,用 | 分隔,如:"我好怕|怎么办|不行"</param>
|
||
/// <param name="targetSentence">目标句子</param>
|
||
/// <param name="completionNode">完成时触发的对话节点(可选)</param>
|
||
[YarnCommand("start_expression")]
|
||
public static void StartExpression(string anxietyPhrasesStr, string targetSentence, string completionNode = "")
|
||
{
|
||
if (ExpressionManager == null)
|
||
{
|
||
UnityEngine.Debug.LogError("ExpressionManager 未找到!请确保场景中有 ExpressionManager 组件。");
|
||
return;
|
||
}
|
||
|
||
// 解析焦虑短句(用 | 分隔)
|
||
string[] phrases = null;
|
||
if (!string.IsNullOrEmpty(anxietyPhrasesStr))
|
||
{
|
||
phrases = anxietyPhrasesStr.Split('|');
|
||
for (int i = 0; i < phrases.Length; i++)
|
||
{
|
||
phrases[i] = phrases[i].Trim();
|
||
}
|
||
}
|
||
|
||
ExpressionManager.StartSystem(phrases, targetSentence, completionNode);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 关闭表达系统
|
||
/// <<close_expression>>
|
||
/// </summary>
|
||
[YarnCommand("close_expression")]
|
||
public static void CloseExpression()
|
||
{
|
||
if (ExpressionManager == null)
|
||
{
|
||
UnityEngine.Debug.LogError("ExpressionManager 未找到!");
|
||
return;
|
||
}
|
||
|
||
ExpressionManager.CloseView();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 重置表达系统(使用当前配置)
|
||
/// <<reset_expression>>
|
||
/// 或
|
||
/// <<reset_expression false>> // 不播放入场动画
|
||
/// </summary>
|
||
/// <param name="playEntranceEffect">是否播放入场效果</param>
|
||
[YarnCommand("reset_expression")]
|
||
public static void ResetExpression(bool playEntranceEffect = true)
|
||
{
|
||
if (ExpressionManager == null)
|
||
{
|
||
UnityEngine.Debug.LogError("ExpressionManager 未找到!");
|
||
return;
|
||
}
|
||
|
||
ExpressionManager.ResetSystem(playEntranceEffect);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 重新启动表达系统(会重置并使用新配置,需要先 open_expression)
|
||
/// <<restart_expression "我好怕|怎么办|不行" "我能做到" "ExpressionCompleted">>
|
||
/// </summary>
|
||
/// <param name="anxietyPhrasesStr">焦虑短句,用 | 分隔</param>
|
||
/// <param name="targetSentence">目标句子</param>
|
||
/// <param name="completionNode">完成时触发的对话节点(可选)</param>
|
||
[YarnCommand("restart_expression")]
|
||
public static void RestartExpression(string anxietyPhrasesStr, string targetSentence, string completionNode = "")
|
||
{
|
||
if (ExpressionManager == null)
|
||
{
|
||
UnityEngine.Debug.LogError("ExpressionManager 未找到!");
|
||
return;
|
||
}
|
||
|
||
// 停止当前系统
|
||
ExpressionManager.CloseView();
|
||
|
||
// 等一帧后重新启动
|
||
UnityEngine.MonoBehaviour coroutineRunner = UnityEngine.Object.FindObjectOfType<UnityEngine.MonoBehaviour>();
|
||
if (coroutineRunner != null)
|
||
{
|
||
coroutineRunner.StartCoroutine(RestartExpressionCoroutine(anxietyPhrasesStr, targetSentence, completionNode));
|
||
}
|
||
else
|
||
{
|
||
// 如果找不到 MonoBehaviour,直接启动
|
||
ExpressionManager.OpenView();
|
||
StartExpression(anxietyPhrasesStr, targetSentence, completionNode);
|
||
}
|
||
}
|
||
|
||
private static IEnumerator RestartExpressionCoroutine(string anxietyPhrasesStr, string targetSentence, string completionNode)
|
||
{
|
||
yield return null; // 等一帧
|
||
ExpressionManager.OpenView();
|
||
StartExpression(anxietyPhrasesStr, targetSentence, completionNode);
|
||
}
|
||
}
|
||
}
|
||
|