TH1/Unity/Assets/Scripts/TH1_Resource/VisualSpriteResolver.cs
2026-06-10 11:58:18 +08:00

50 lines
1.2 KiB
C#

using System;
using UnityEngine;
public static class VisualSpriteResolver
{
private const string MapResourcePath = "DataAssets/VisualSpriteVariantMap";
private static VisualSpriteVariantMapAsset _map;
private static VisualTheme _currentTheme = VisualTheme.Default;
public static event Action<VisualTheme> ThemeChanged;
public static VisualTheme CurrentTheme => _currentTheme;
public static bool IsEyeComfort => _currentTheme == VisualTheme.EyeComfort;
public static void SetTheme(VisualTheme theme)
{
if (_currentTheme == theme)
return;
_currentTheme = theme;
ThemeChanged?.Invoke(_currentTheme);
}
public static Sprite Resolve(Sprite source)
{
if (source == null || _currentTheme == VisualTheme.Default)
return source;
EnsureMapLoaded();
return _map != null ? _map.Resolve(source, _currentTheme) : source;
}
public static void ReloadMap()
{
_map = null;
EnsureMapLoaded();
}
private static void EnsureMapLoaded()
{
if (_map != null)
return;
_map = TH1Resource.ResourceLoader.Load<VisualSpriteVariantMapAsset>(MapResourcePath);
_map?.RebuildCache();
}
}