Files
aibis-dream/Assets/Scripts/MiniGame/HuoShan/Waveform/WaveformYarnCommand.cs
T
2026-01-22 16:27:05 +08:00

392 lines
12 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System.Collections;
using AibisDream.FixSystem;
using AibisDream.UI;
using UnityEngine;
using Yarn.Unity;
namespace AibisDream.MiniGame.HuoShan
{
/// <summary>
/// 波形显示系统的Yarn命令
///
/// 功能:
/// - 设备控制:show/hide_waveform_detector
/// - 连接控制:connect/disconnect_waveform_detector
/// - 扫描模式:enable_scan_logic/emotion, wait_scan_locked/not_found
/// - 时间戳:show_timestamp_waveform, get_locked_timestamp()
/// - 波形显示:show_waveform "emotion/logic/joke/filter_output"
/// - 波形效果:check_waveform, check_waveform_pass/fail, modify_waveform
/// </summary>
public static class WaveformYarnCommand
{
private static WaveformDetector GetDetector()
{
return FixSystemCenter.SystemDic.Get<WaveformDetector>();
}
#region 设备控制
[YarnCommand("show_waveform_detector")]
public static IEnumerator ShowWaveformDetector()
{
var detector = GetDetector();
if (detector != null)
{
yield return detector.Show();
}
}
[YarnCommand("hide_waveform_detector")]
public static IEnumerator HideWaveformDetector(float duration = 0.3f)
{
var detector = GetDetector();
if (detector != null)
{
yield return detector.Hide(duration);
}
}
#endregion
#region 连接控制
/// <summary>
/// 连接波形检测器到指定模块
/// </summary>
[YarnCommand("connect_waveform_detector")]
public static IEnumerator ConnectWaveformDetector(string moduleId)
{
var detector = GetDetector();
if (detector != null)
{
yield return detector.ConnectToModule(moduleId);
}
}
/// <summary>
/// 断开波形检测器连接
/// </summary>
[YarnCommand("disconnect_waveform_detector")]
public static void DisconnectWaveformDetector()
{
var detector = GetDetector();
if (detector != null)
{
detector.Disconnect();
}
}
#endregion
#region 扫描模式
/// <summary>
/// 启用扫描模式 - 逻辑模式(有清晰点可锁定)
/// </summary>
[YarnCommand("enable_scan_logic")]
public static IEnumerator EnableScanLogic(string label = "寻找逻辑信号")
{
var detector = GetDetector();
if (detector != null)
{
yield return detector.EnableScanMode(WaveformDetector.ScanMode.Logic, label);
}
}
/// <summary>
/// 启用扫描模式 - 情绪模式(找不到)
/// </summary>
[YarnCommand("enable_scan_emotion")]
public static IEnumerator EnableScanEmotion(string label = "寻找情绪信号")
{
var detector = GetDetector();
if (detector != null)
{
yield return detector.EnableScanMode(WaveformDetector.ScanMode.Emotion, label);
}
}
/// <summary>
/// 停止扫描模式
/// </summary>
[YarnCommand("stop_scan_mode")]
public static void StopScanMode()
{
var detector = GetDetector();
if (detector != null)
{
detector.StopScanMode();
}
}
/// <summary>
/// 等待扫描锁定(逻辑模式)
/// </summary>
[YarnCommand("wait_scan_locked")]
public static IEnumerator WaitScanLocked()
{
var detector = GetDetector();
if (detector != null)
{
while (!detector.IsLocked)
{
yield return null;
}
}
}
/// <summary>
/// 等待扫描完成未找到(情绪模式)
/// </summary>
[YarnCommand("wait_scan_not_found")]
public static IEnumerator WaitScanNotFound()
{
var detector = GetDetector();
if (detector != null)
{
while (!detector.NotFoundTriggered)
{
yield return null;
}
}
}
/// <summary>
/// 检查是否已锁定
/// </summary>
[YarnFunction("is_scan_locked")]
public static bool IsScanLocked()
{
var detector = GetDetector();
return detector != null && detector.IsLocked;
}
/// <summary>
/// 检查是否扫描完成未找到
/// </summary>
[YarnFunction("is_scan_not_found")]
public static bool IsScanNotFound()
{
var detector = GetDetector();
return detector != null && detector.NotFoundTriggered;
}
/// <summary>
/// 检查是否已覆盖全部区域
/// </summary>
[YarnFunction("is_fully_covered")]
public static bool IsFullyCovered()
{
var detector = GetDetector();
return detector != null && detector.FullyCovered;
}
#endregion
#region 时间戳
/// <summary>
/// 获取锁定的时间戳
/// </summary>
[YarnFunction("get_locked_timestamp")]
public static string GetLockedTimestamp()
{
var detector = GetDetector();
return detector != null ? detector.LockedTimestamp : "";
}
/// <summary>
/// 显示锁定时间戳对应的原始波形
/// </summary>
[YarnCommand("show_timestamp_waveform")]
public static IEnumerator ShowTimestampWaveform()
{
var detector = GetDetector();
if (detector != null)
{
yield return detector.ShowTimestampWaveform();
}
}
#endregion
#region 波形显示(保持兼容)
[YarnCommand("show_waveform")]
public static IEnumerator ShowWaveform(string waveformType, float duration = 0.5f)
{
var detector = GetDetector();
if (detector != null)
{
if (!detector.IsShown) yield return detector.Show();
yield return detector.ShowWaveform(waveformType, duration);
}
}
[YarnCommand("hide_waveform")]
public static IEnumerator HideWaveform(float duration = 0.3f)
{
var detector = GetDetector();
if (detector != null)
{
yield return detector.HideWaveform(duration);
}
}
[YarnCommand("transform_waveform")]
public static IEnumerator TransformWaveform(string fromType, string toType, float duration = 1f)
{
var detector = GetDetector();
if (detector != null)
{
yield return detector.TransformWaveform(fromType, toType, duration);
}
}
#endregion
#region 结果显示
[YarnCommand("show_waveform_result")]
public static void ShowWaveformResult(string message, bool isSuccess = true)
{
var detector = GetDetector();
if (detector != null)
{
detector.ShowResult(isSuccess, message);
}
}
[YarnCommand("hide_waveform_result")]
public static void HideWaveformResult()
{
var detector = GetDetector();
if (detector != null)
{
detector.HideResult();
}
}
#endregion
#region 波形效果命令
/// <summary>
/// 波形检测效果(闪烁)
/// </summary>
[YarnCommand("check_waveform")]
public static IEnumerator CheckWaveform(int blinkCount = 3)
{
var detector = GetDetector();
if (detector != null)
{
yield return detector.WaveformCheckEffect(blinkCount);
}
}
/// <summary>
/// 屏蔽词检测效果(横扫)
/// </summary>
[YarnCommand("check_waveform_sweep")]
public static IEnumerator CheckWaveformSweep(int sweepCount = 2, float sweepDuration = 0.25f)
{
var detector = GetDetector();
if (detector != null)
{
yield return detector.WaveformSweepCheck(sweepCount, sweepDuration);
}
}
/// <summary>
/// 限幅检测效果(探测最大/最小)
/// </summary>
[YarnCommand("check_waveform_range")]
public static IEnumerator CheckWaveformRange(int pulseCount = 2, float pulseInterval = 0.12f)
{
var detector = GetDetector();
if (detector != null)
{
yield return detector.WaveformRangeCheck(pulseCount, pulseInterval);
}
}
/// <summary>
/// 波形检测通过效果(绿色闪烁)
/// </summary>
[YarnCommand("check_waveform_pass")]
public static IEnumerator CheckWaveformPass()
{
var detector = GetDetector();
if (detector != null)
{
yield return detector.WaveformCheckPass();
}
}
/// <summary>
/// 波形检测失败/警告效果(红色闪烁)
/// </summary>
[YarnCommand("check_waveform_fail")]
public static IEnumerator CheckWaveformFail()
{
var detector = GetDetector();
if (detector != null)
{
yield return detector.WaveformCheckFail();
}
}
/// <summary>
/// 波形被篡改的变换效果
/// 用法: transform_waveform "emotion" "joke" 2
/// </summary>
[YarnCommand("modify_waveform")]
public static IEnumerator ModifyWaveform(string fromType, string toType, float duration = 1.5f)
{
var detector = GetDetector();
if (detector != null)
{
yield return detector.TransformWaveform(fromType, toType, duration);
}
}
#endregion
#region 报错效果(Stage4使用
[YarnCommand("show_error_flood")]
public static IEnumerator ShowErrorFlood(int count = 5, float interval = 0.3f)
{
var errorMessages = new string[]
{
"[ERROR] 悲伤表达单元:信号堆积溢出",
"[ERROR] 焦虑表达单元:无法处理积压请求",
"[ERROR] 恐惧表达单元:RAM不足",
"[WARNING] 表达模块即将闭锁",
"[CRITICAL] 系统响应超时",
"[ERROR] 未处理的情绪信号队列已满",
"[WARNING] 低频信号被阻塞",
"[ERROR] 表达缓冲区溢出"
};
var panel = UIManager.Instance?.GetPanel<PlayToolPanel>();
if (panel != null)
{
for (int i = 0; i < Mathf.Min(count, errorMessages.Length); i++)
{
yield return panel.OpenWarningWindow(errorMessages[i % errorMessages.Length]);
yield return new WaitForSeconds(interval);
}
}
}
[YarnCommand("clear_errors")]
public static void ClearErrors()
{
// 报错窗口会自动关闭
}
#endregion
}
}