247 lines
9.4 KiB
C#
247 lines
9.4 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);
|
||
}
|
||
|
||
#region 分析模式命令
|
||
|
||
/// <summary>
|
||
/// 启动分析模式(使用 ScriptableObject 配置 - 推荐)
|
||
/// <<start_analysis level:AnalysisLevel_Fear_01>>
|
||
/// 或
|
||
/// <<start_analysis level:AnalysisLevel_Fear_01 completion:TestNode>>
|
||
/// </summary>
|
||
/// <param name="levelName">关卡配置名称(Resources/AnalysisLevels/ 下的文件名)</param>
|
||
/// <param name="completionNode">完成时触发的对话节点(可选,会覆盖配置中的节点)</param>
|
||
[YarnCommand("start_analysis")]
|
||
public static void StartAnalysis(string levelName, string completionNode = "")
|
||
{
|
||
if (ExpressionManager == null)
|
||
{
|
||
UnityEngine.Debug.LogError("ExpressionManager 未找到!请确保场景中有 ExpressionManager 组件。");
|
||
return;
|
||
}
|
||
|
||
// 从 Resources 加载关卡配置
|
||
AnalysisModeData levelData = UnityEngine.Resources.Load<AnalysisModeData>($"AnalysisLevels/{levelName}");
|
||
|
||
if (levelData == null)
|
||
{
|
||
UnityEngine.Debug.LogError($"找不到关卡配置: Resources/AnalysisLevels/{levelName}.asset");
|
||
return;
|
||
}
|
||
|
||
// 启动分析模式
|
||
var analysisManager = UnityEngine.Object.FindObjectOfType<AnalysisModeManager>();
|
||
if (analysisManager != null)
|
||
{
|
||
analysisManager.StartAnalysisMode(levelData, completionNode);
|
||
}
|
||
else
|
||
{
|
||
UnityEngine.Debug.LogError("场景中找不到 AnalysisModeManager 组件!");
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 启动分析模式(旧版本,使用笑话短句 - 已弃用)
|
||
/// <<start_analysis_mode>>
|
||
/// 或
|
||
/// <<start_analysis_mode "CompletionNodeName">>
|
||
/// 或
|
||
/// <<start_analysis_mode "临检要来了|不合格英里被骂了|我担心业绩会下滑" "AnalysisComplete">>
|
||
/// </summary>
|
||
/// <param name="anxietyPhrasesStr">焦虑短句,用 | 分隔(可选,为空时使用默认配置)</param>
|
||
/// <param name="completionNode">完成时触发的对话节点(可选)</param>
|
||
[System.Obsolete("使用 start_analysis 命令代替,支持关卡配置数据")]
|
||
[YarnCommand("start_analysis_mode")]
|
||
public static void StartAnalysisMode(string anxietyPhrasesStr = "", string completionNode = "")
|
||
{
|
||
if (ExpressionManager == null)
|
||
{
|
||
UnityEngine.Debug.LogError("ExpressionManager 未找到!请确保场景中有 ExpressionManager 组件。");
|
||
return;
|
||
}
|
||
|
||
// 解析焦虑短句(用 | 分隔)
|
||
List<string> phrases = null;
|
||
if (!string.IsNullOrEmpty(anxietyPhrasesStr))
|
||
{
|
||
string[] phrasesArray = anxietyPhrasesStr.Split('|');
|
||
phrases = new List<string>();
|
||
for (int i = 0; i < phrasesArray.Length; i++)
|
||
{
|
||
string phrase = phrasesArray[i].Trim();
|
||
if (!string.IsNullOrEmpty(phrase))
|
||
{
|
||
phrases.Add(phrase);
|
||
}
|
||
}
|
||
}
|
||
|
||
ExpressionManager.StartAnalysisMode(phrases, completionNode);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 关闭分析模式
|
||
/// <<close_analysis>>
|
||
/// </summary>
|
||
[YarnCommand("close_analysis")]
|
||
public static void CloseAnalysis()
|
||
{
|
||
var analysisManager = UnityEngine.Object.FindObjectOfType<AnalysisModeManager>();
|
||
if (analysisManager != null)
|
||
{
|
||
analysisManager.CloseAnalysisMode();
|
||
}
|
||
else
|
||
{
|
||
UnityEngine.Debug.LogWarning("场景中找不到 AnalysisModeManager 组件!");
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 关闭分析模式(旧命令名称)
|
||
/// <<close_analysis_mode>>
|
||
/// </summary>
|
||
[YarnCommand("close_analysis_mode")]
|
||
public static void CloseAnalysisMode()
|
||
{
|
||
CloseAnalysis();
|
||
}
|
||
|
||
#endregion
|
||
}
|
||
}
|
||
|