feat(scene-mgmt): 添加地铁场景新闻图片切换功能
Made-with: Cursor
This commit is contained in:
@@ -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<Sprite>(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<OutSideState>
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user