diff --git a/Assets/Scripts/SceneManagement/SceneCenter/SubwayCenter.cs b/Assets/Scripts/SceneManagement/SceneCenter/SubwayCenter.cs index 6c9a08449..319242159 100644 --- a/Assets/Scripts/SceneManagement/SceneCenter/SubwayCenter.cs +++ b/Assets/Scripts/SceneManagement/SceneCenter/SubwayCenter.cs @@ -5,6 +5,7 @@ using AibisDream.Kit; using Cinemachine; using UnityEngine; using UnityEngine.Playables; +using UnityEngine.ResourceManagement.AsyncOperations; using Yarn.Unity; namespace AibisDream @@ -18,6 +19,7 @@ namespace AibisDream public CinemachineVirtualCamera subwayCam; public CinemachineVirtualCamera tvCam; + public SpriteRenderer newsSpriteRenderer; public PlayableDirector arriveStation; @@ -58,6 +60,33 @@ namespace AibisDream arriveStation.Play(); yield return new WaitForSeconds((float) arriveStation.playableAsset.duration); } + + public IEnumerator SwitchNews(string spriteId) + { + if (string.IsNullOrWhiteSpace(spriteId)) + { + Debug.LogWarning("[SubwayCenter] spriteId 为空,无法切换新闻图片。"); + yield break; + } + + string addressableKey = $"Sprite/News[{spriteId}]"; + var handle = ResourceSystem.LoadAsync(addressableKey); + yield return handle; + + if (handle.Status != AsyncOperationStatus.Succeeded || handle.Result == null) + { + Debug.LogError($"[SubwayCenter] 加载新闻图片失败: {addressableKey}"); + yield break; + } + + if (newsSpriteRenderer == null) + { + Debug.LogWarning("[SubwayCenter] newsSpriteRenderer 未赋值,无法切换新闻图片。"); + yield break; + } + + newsSpriteRenderer.sprite = handle.Result; + } } public struct SubwayState : IState @@ -108,5 +137,17 @@ namespace AibisDream { return SubwayCenter.Instance.ArriveAtStation(); } + + [YarnCommand("switch_news")] + public static IEnumerator SwitchNews(string spriteId) + { + if (SubwayCenter.Instance == null) + { + Debug.LogError("[SubwayYarnCommand] SubwayCenter 实例不存在。"); + yield break; + } + + yield return SubwayCenter.Instance.SwitchNews(spriteId); + } } } \ No newline at end of file