using System; using System.Collections; using AibisDream.Framework; using UnityEngine; using UnityEngine.ResourceManagement.AsyncOperations; namespace AibisDream { internal static class Day2SleepSpriteLoader { private const string DreamSpritePath = "Sprite/梦境/{0}.png"; public static string NormalizeName(string picName) { if (string.IsNullOrEmpty(picName)) return picName; return picName.EndsWith(".png", StringComparison.OrdinalIgnoreCase) ? picName.Substring(0, picName.Length - 4) : picName; } public static IEnumerator LoadInto( SpriteRenderer target, string picName, Action completed = null, Action warning = null) { if (target == null) { completed?.Invoke(false); yield break; } var key = string.Format(DreamSpritePath, NormalizeName(picName)); var handle = ResourceSystem.LoadAsync(key); yield return handle; if (handle.Status == AsyncOperationStatus.Succeeded && handle.Result != null) { target.sprite = handle.Result; completed?.Invoke(true); yield break; } var message = $"[Day2SleepPresentation] Failed to load sprite: {key}"; Debug.LogError(message); warning?.Invoke(message); completed?.Invoke(false); } public static IEnumerator Load( string picName, Action completed, Action warning = null) { var key = string.Format(DreamSpritePath, NormalizeName(picName)); var handle = ResourceSystem.LoadAsync(key); yield return handle; if (handle.Status == AsyncOperationStatus.Succeeded && handle.Result != null) { completed?.Invoke(handle.Result); yield break; } var message = $"[Day2SleepPresentation] Failed to load sprite: {key}"; Debug.LogError(message); warning?.Invoke(message); completed?.Invoke(null); } } }