using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace Vanguard.UI
{
///
/// Загрузка настоящих артов по imageKey. Соглашение: спрайт лежит в
/// Assets/Vanguard/Resources/CardArt/{imageKey}.png. Пока файла нет —
/// используется процедурный CardArt. Позже этот же вход можно
/// перевести на Addressables без изменения экранов.
///
public static class CardImageService
{
private const string ResourceFolder = "CardArt/";
private static readonly Dictionary Cache =
new Dictionary();
public static void Apply(Image target, string imageKey, Sprite fallback)
{
if (target == null)
return;
target.sprite = fallback;
target.color = Color.white;
target.preserveAspect = false;
if (string.IsNullOrWhiteSpace(imageKey))
return;
if (Cache.TryGetValue(imageKey, out var cached))
{
if (cached != null)
target.sprite = cached;
return;
}
var sprite = Resources.Load(ResourceFolder + imageKey);
Cache[imageKey] = sprite;
if (sprite != null)
target.sprite = sprite;
}
}
}