using System.Collections; using Yarn.Unity; using UnityEngine; using AibisDream.FixSystem; using AibisDream.MiniGame.Language; namespace AibisDream.MiniGame.HuoShan { /// /// 销售系统的Yarn命令扩展 /// 功能: /// - 发条控件命令 /// - 滑片控制器命令 /// - 处理器灯控制命令 /// - 销售流程控制命令 /// public static class SalesYarnCommand { #region 发条控件命令 /// /// 重置发条到初始状态 /// 用法: <> /// [YarnCommand("reset_crank")] public static void ResetCrank() { var crankController = FixSystemCenter.SystemDic.Get(); if (crankController != null) { crankController.ResetCrank(); Debug.Log("[SalesYarnCommand] 发条已重置"); } else { Debug.LogWarning("[SalesYarnCommand] 未找到CrankController"); } } /// /// 手动旋转发条到指定角度(用于测试或自动化) /// 用法: <> /// [YarnCommand("rotate_crank")] public static IEnumerator RotateCrank(float angle, float duration = 0.5f) { var crankController = FixSystemCenter.SystemDic.Get(); if (crankController != null) { Debug.Log($"[SalesYarnCommand] 旋转发条到{angle}度,时长{duration}秒"); yield return new WaitForSeconds(duration); } else { Debug.LogWarning("[SalesYarnCommand] 未找到CrankController"); } } /// /// 等待发条完成(达到最大角度并释放) /// 用法: <> /// [YarnCommand("wait_crank_complete")] public static IEnumerator WaitCrankComplete() { var crankController = FixSystemCenter.SystemDic.Get(); if (crankController == null) { Debug.LogWarning("[SalesYarnCommand] 未找到CrankController"); yield break; } Debug.Log("[SalesYarnCommand] 等待发条完成..."); // 使用协程等待事件 bool isComplete = false; UnityEngine.Events.UnityAction onComplete = () => isComplete = true; crankController.onCrankComplete.AddListener(onComplete); while (!isComplete) { yield return null; } crankController.onCrankComplete.RemoveListener(onComplete); Debug.Log("[SalesYarnCommand] 发条完成"); } #endregion #region 滑片控制命令 /// /// 重置滑片到起始位置 /// 用法: <> /// [YarnCommand("reset_slider")] public static void ResetSlider() { var sliderController = FixSystemCenter.SystemDic.Get(); if (sliderController != null) { sliderController.ResetPosition(); Debug.Log("[SalesYarnCommand] 滑片已重置"); } else { Debug.LogWarning("[SalesYarnCommand] 未找到SliderController"); } } /// /// 滑片移动到指定角度 /// 用法: <> /// [YarnCommand("slide_to_angle")] public static IEnumerator SlideToAngle(float angle, float duration = 1f) { var sliderController = FixSystemCenter.SystemDic.Get(); if (sliderController != null) { Debug.Log($"[SalesYarnCommand] 移动滑片到{angle}度,时长{duration}秒"); sliderController.SlideTo(angle, duration); yield return new WaitForSeconds(duration); } else { Debug.LogWarning("[SalesYarnCommand] 未找到SliderController"); } } /// /// 滑片移动到指定标准化位置(0-1) /// 用法: <> /// [YarnCommand("slide_to_position")] public static IEnumerator SlideToPosition(float normalizedPosition, float duration = 1f) { var sliderController = FixSystemCenter.SystemDic.Get(); if (sliderController != null) { Debug.Log($"[SalesYarnCommand] 移动滑片到位置{normalizedPosition},时长{duration}秒"); sliderController.SlideToNormalized(normalizedPosition, duration); yield return new WaitForSeconds(duration); } else { Debug.LogWarning("[SalesYarnCommand] 未找到SliderController"); } } /// /// 滑片移动到指定段 /// 用法: <> /// [YarnCommand("slide_to_segment")] public static IEnumerator SlideToSegment(int segmentIndex, float duration = 1f) { var sliderController = FixSystemCenter.SystemDic.Get(); if (sliderController != null) { Debug.Log($"[SalesYarnCommand] 移动滑片到段{segmentIndex},时长{duration}秒"); sliderController.SlideToSegment(segmentIndex, duration); yield return new WaitForSeconds(duration); } else { Debug.LogWarning("[SalesYarnCommand] 未找到SliderController"); } } /// /// 滑片移动到异常段(任务关键) /// 用法: <> /// [YarnCommand("slide_to_anomaly")] public static IEnumerator SlideToAnomaly(int segmentIndex, float duration = 1f) { var sliderController = FixSystemCenter.SystemDic.Get(); if (sliderController != null) { Debug.Log($"[SalesYarnCommand] 移动滑片到异常段{segmentIndex},时长{duration}秒"); // 设置段数为异常段 sliderController.SetSegmentCount(segmentIndex + 1); sliderController.SlideToSegment(segmentIndex, duration); yield return new WaitForSeconds(duration); } else { Debug.LogWarning("[SalesYarnCommand] 未找到SliderController"); } } /// /// 等待滑片到达目标位置 /// 用法: <> /// [YarnCommand("wait_slider_at")] public static IEnumerator WaitSliderAt(float targetPosition, float tolerance = 0.05f) { var sliderController = FixSystemCenter.SystemDic.Get(); if (sliderController == null) { Debug.LogWarning("[SalesYarnCommand] 未找到SliderController"); yield break; } Debug.Log($"[SalesYarnCommand] 等待滑片到达位置{targetPosition}..."); while (Mathf.Abs(sliderController.GetNormalizedPosition() - targetPosition) > tolerance) { yield return null; } Debug.Log($"[SalesYarnCommand] 滑片已到达位置{targetPosition}"); } #endregion #region 处理器灯控制命令 /// /// 激活指定索引的处理器灯 /// 用法: <> /// [YarnCommand("activate_processor")] public static void ActivateProcessor(int processorIndex, float duration = -1f) { var controller = FixSystemCenter.SystemDic.Get(); if (controller != null) { controller.ActivateProcessor(processorIndex, duration); Debug.Log($"[SalesYarnCommand] 激活处理器{processorIndex}"); } else { Debug.LogWarning("[SalesYarnCommand] 未找到ProcessorLightController"); } } /// /// 关闭所有处理器灯 /// 用法: <> /// [YarnCommand("deactivate_all_processors")] public static void DeactivateAllProcessors(float fadeOutDuration = 0.3f) { var controller = FixSystemCenter.SystemDic.Get(); if (controller != null) { controller.DeactivateAllProcessors(fadeOutDuration); Debug.Log("[SalesYarnCommand] 关闭所有处理器灯"); } else { Debug.LogWarning("[SalesYarnCommand] 未找到ProcessorLightController"); } } /// /// 显示异常处理器(闪烁) /// 用法: <> /// [YarnCommand("show_anomaly_processor")] public static void ShowAnomalyProcessor(int processorIndex) { var controller = FixSystemCenter.SystemDic.Get(); if (controller != null) { controller.ShowAnomalyProcessor(processorIndex); Debug.Log($"[SalesYarnCommand] 显示异常处理器{processorIndex}"); } else { Debug.LogWarning("[SalesYarnCommand] 未找到ProcessorLightController"); } } /// /// 根据滑片位置自动更新处理器灯 /// 用法: <> /// [YarnCommand("update_processor_from_slider")] public static void UpdateProcessorFromSlider() { var processorController = FixSystemCenter.SystemDic.Get(); var sliderController = FixSystemCenter.SystemDic.Get(); if (processorController != null && sliderController != null) { float position = sliderController.GetNormalizedPosition(); int processorIndex = processorController.GetProcessorIndexFromSlider(position); processorController.ActivateProcessor(processorIndex); Debug.Log($"[SalesYarnCommand] 根据滑片位置{position}激活处理器{processorIndex}"); } else { Debug.LogWarning("[SalesYarnCommand] 未找到所需的控制器"); } } #endregion #region 销售流程控制命令 /// /// 进入步进模式(收缩扩张动画) /// 用法: <> /// [YarnCommand("enter_step_mode")] public static IEnumerator EnterStepMode() { Debug.Log("[SalesYarnCommand] 进入步进模式"); // 这个命令需要触发收缩扩张动画 // 具体实现需要与动画系统或Timeline集成 yield return new WaitForSeconds(1f); } /// /// 进入处理器深入模式(面板右移) /// 用法: <> /// [YarnCommand("enter_processor_mode")] public static IEnumerator EnterProcessorMode() { Debug.Log("[SalesYarnCommand] 进入处理器深入模式"); // 触发面板右移动画 // 可以使用DOTween或Timeline yield return new WaitForSeconds(1f); } /// /// 完成一次完整的发条-滑片循环 /// 用法: <> /// [YarnCommand("complete_crank_cycle")] public static IEnumerator CompleteCrankCycle() { Debug.Log("[SalesYarnCommand] 完成发条-滑片循环"); // 等待发条完成 yield return WaitCrankComplete(); // 移动滑片一段距离 var sliderController = FixSystemCenter.SystemDic.Get(); if (sliderController != null) { float currentPosition = sliderController.GetNormalizedPosition(); float newPosition = currentPosition + 0.25f; // 每次移动25% yield return SlideToPosition(newPosition, 0.5f); } } /// /// 等待特定步进节点完成 /// 用法: <> /// [YarnCommand("wait_step_node")] public static IEnumerator WaitStepNode(int stepIndex) { Debug.Log($"[SalesYarnCommand] 等待步进节点{stepIndex}完成..."); // 根据步进索引执行不同的等待逻辑 switch (stepIndex) { case 1: case 2: // 等待发条和滑片完成 yield return WaitCrankComplete(); break; case 3: // 等待滑片移动到异常段 yield return new WaitForSeconds(2f); break; case 4: // 等待反向操作完成 yield return new WaitForSeconds(1f); break; } Debug.Log($"[SalesYarnCommand] 步进节点{stepIndex}完成"); } #endregion #region 静态工具方法 /// /// 获取销售系统管理器 /// private static SalesManager GetSalesManager() { return FixSystemCenter.SystemDic.Get(); } /// /// 等待指定时长 /// private static IEnumerator Wait(float seconds) { yield return new WaitForSeconds(seconds); } #endregion } }