From f9b38aaba8b38638658d5ad21c3b65f7d4ce5d67 Mon Sep 17 00:00:00 2001 From: Ding Yuntian <1491671119@qq.com> Date: Thu, 16 Apr 2026 14:14:49 +0800 Subject: [PATCH] =?UTF-8?q?feat(scene-mgmt):=20=E6=B7=BB=E5=8A=A0=E5=9C=B0?= =?UTF-8?q?=E9=93=81=E5=9C=BA=E6=99=AF=E6=96=B0=E9=97=BB=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E5=88=87=E6=8D=A2=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Made-with: Cursor --- .../SceneCenter/SubwayCenter.cs | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) 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