保留 Stage6 当前台词,仅恢复粒子与完成表现及 start_expression 参数。 Co-authored-by: Cursor <cursoragent@cursor.com>
184 lines
7.8 KiB
C#
184 lines
7.8 KiB
C#
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using AibisDream.FixSystem;
|
||
using AibisDream;
|
||
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>
|
||
/// 启动表达粒子系统(在打开视图后调用),等待火山表达panel播完再返回。
|
||
/// 流程:若有上一轮则先淡出字与连线 → 再淡入火山释放 log → 再启动新一轮并等表达 panel 就绪。
|
||
/// 注意:Yarn Spinner 2.x 对同名 <see cref="YarnCommand"/> 重载支持不可靠,只保留一个注册入口,用可选参数区分 3/4 参调用。
|
||
/// <<start_expression "哈哈|嘿嘿|呵呵" "我很害怕" "ExpressionCompleted">>
|
||
/// <<start_expression "哈哈|嘿嘿|呵呵" "我很害怕" "ExpressionCompleted" 24>>
|
||
/// (第四项为「非目标」候选粒子总数,候选池 = 目标句字数 + 该值;不写第四项则用 Inspector 的 Candidate Count)
|
||
/// </summary>
|
||
/// <param name="anxietyPhrasesStr">干扰短句(笑话等),用 | 分隔,用于非目标粒子字符池,如:"哈哈|嘿嘿|呵呵"</param>
|
||
/// <param name="targetSentence">目标句子</param>
|
||
/// <param name="completionNode">完成时触发的对话节点(可空字符串)</param>
|
||
/// <param name="nonTargetParticleTotal">非目标候选粒子总数;<0 表示使用 Inspector 默认</param>
|
||
[YarnCommand("start_expression")]
|
||
public static IEnumerator StartExpression(
|
||
string anxietyPhrasesStr,
|
||
string targetSentence,
|
||
string completionNode = "",
|
||
float nonTargetParticleTotal = -1f)
|
||
{
|
||
return RunStartExpression(
|
||
anxietyPhrasesStr,
|
||
targetSentence,
|
||
completionNode ?? "",
|
||
UnityEngine.Mathf.RoundToInt(nonTargetParticleTotal));
|
||
}
|
||
|
||
private static IEnumerator RunStartExpression(string anxietyPhrasesStr, string targetSentence, string completionNode, int nonTargetParticleTotal)
|
||
{
|
||
if (ExpressionManager == null)
|
||
{
|
||
UnityEngine.Debug.LogError("ExpressionManager 未找到!请确保场景中有 ExpressionManager 组件。");
|
||
yield break;
|
||
}
|
||
|
||
string[] phrases = null;
|
||
if (!string.IsNullOrEmpty(anxietyPhrasesStr))
|
||
{
|
||
phrases = anxietyPhrasesStr.Split('|');
|
||
for (int i = 0; i < phrases.Length; i++)
|
||
{
|
||
phrases[i] = phrases[i].Trim();
|
||
}
|
||
}
|
||
|
||
// 先淡出上一轮文字/连线等,再淡入火山释放 log,最后开新一轮粒子(避免 log 与旧字叠在一起)
|
||
yield return ExpressionManager.FadeOutParticlesBeforeNewRound(0f);
|
||
yield return ExpressionManager.EnsureReleaseLogFadedIn(1f);
|
||
ExpressionManager.StartSystem(phrases, targetSentence, completionNode, nonTargetParticleTotal);
|
||
yield return ExpressionManager.WaitUntilExpressionFlowReady();
|
||
}
|
||
|
||
/// <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>
|
||
/// 触发聚焦稳定化(从文字飘动保持态 → 概率递增 → 文字锁定 → 排列),等待全流程完成后返回
|
||
/// <<resolve_expression_focus>>
|
||
/// </summary>
|
||
[YarnCommand("resolve_expression_focus")]
|
||
public static IEnumerator ResolveExpressionFocus()
|
||
{
|
||
if (ExpressionManager == null)
|
||
{
|
||
UnityEngine.Debug.LogError("ExpressionManager 未找到!");
|
||
yield break;
|
||
}
|
||
yield return ExpressionManager.StartCoroutine(ExpressionManager.ResolveFocusAndWait());
|
||
}
|
||
|
||
/// <summary>
|
||
/// 淡入 ExpressionManager 的 Sprite 图片
|
||
/// <<expression_sprite_fade_in>>
|
||
/// <<expression_sprite_fade_in 1.5>>
|
||
/// </summary>
|
||
/// <param name="duration">淡入时长(秒),默认 1</param>
|
||
[YarnCommand("expression_sprite_fade_in")]
|
||
public static IEnumerator ExpressionSpriteFadeIn(float duration = 1f)
|
||
{
|
||
if (ExpressionManager == null)
|
||
{
|
||
UnityEngine.Debug.LogError("ExpressionManager 未找到!");
|
||
yield break;
|
||
}
|
||
yield return ExpressionManager.StartCoroutine(ExpressionManager.FadeInSpriteOverlay(duration));
|
||
}
|
||
|
||
/// <summary>
|
||
/// 淡出 ExpressionManager 的 Sprite 图片
|
||
/// <<expression_sprite_fade_out>>
|
||
/// <<expression_sprite_fade_out 1.5>>
|
||
/// </summary>
|
||
/// <param name="duration">淡出时长(秒),默认 1</param>
|
||
[YarnCommand("expression_sprite_fade_out")]
|
||
public static IEnumerator ExpressionSpriteFadeOut(float duration = 1f)
|
||
{
|
||
if (ExpressionManager == null)
|
||
{
|
||
UnityEngine.Debug.LogError("ExpressionManager 未找到!");
|
||
yield break;
|
||
}
|
||
yield return ExpressionManager.StartCoroutine(ExpressionManager.FadeOutSpriteOverlay(duration));
|
||
}
|
||
|
||
/// <summary>
|
||
/// Glitch 噪波过渡,等待完成后再继续下一步。
|
||
/// <<glitch_transition 0.95 2>> -- 从 0 到 0.95,2 秒
|
||
/// <<glitch_transition 0.95>> -- 立即到 0.95(duration 默认 0)
|
||
/// <<glitch_transition 0.3 0.45 1>> -- 从 0.3 到 0.45,1 秒
|
||
/// </summary>
|
||
[YarnCommand("glitch_transition")]
|
||
public static IEnumerator GlitchTransition(float to, float duration = 0f)
|
||
{
|
||
if (ExpressionManager == null)
|
||
{
|
||
UnityEngine.Debug.LogError("ExpressionManager 未找到!");
|
||
yield break;
|
||
}
|
||
yield return ExpressionManager.StartCoroutine(ExpressionManager.TransitionGlitchAndWait(to, duration));
|
||
}
|
||
|
||
// /// <summary>
|
||
// /// Glitch 噪波过渡(指定起止值),等待完成后再继续下一步。
|
||
// /// </summary>
|
||
// [YarnCommand("glitch_transition")]
|
||
// public static IEnumerator GlitchTransition(float from, float to, float duration)
|
||
// {
|
||
// if (ExpressionManager == null)
|
||
// {
|
||
// UnityEngine.Debug.LogError("ExpressionManager 未找到!");
|
||
// yield break;
|
||
// }
|
||
// yield return ExpressionManager.StartCoroutine(ExpressionManager.TransitionGlitchAndWait(from, to, duration));
|
||
// }
|
||
}
|
||
}
|
||
|