45 lines
No EOL
1.4 KiB
C#
45 lines
No EOL
1.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using ShiroginSDK.Runtime.Modules.UI.Theme.Enums;
|
|
using UnityEngine;
|
|
|
|
namespace ShiroginSDK.Runtime.Modules.UI.Theme.Scripts.SO
|
|
{
|
|
/// <summary>
|
|
/// Defines a set of themed sprites for one visual profile (e.g. Default, Dark, Halloween).
|
|
/// </summary>
|
|
[CreateAssetMenu(fileName = "ThemeProfile", menuName = "ShiroginSDK/Theme/Theme Profile")]
|
|
public class ThemeProfile : ScriptableObject
|
|
{
|
|
[Header("Theme Info")]
|
|
public string ThemeName = "Default";
|
|
|
|
[SerializeField]
|
|
private List<ThemeEntry> entries = new();
|
|
|
|
private Dictionary<ThemeAssetType, Sprite> _cache;
|
|
|
|
/// <summary>
|
|
/// Returns a sprite associated with the given asset type.
|
|
/// </summary>
|
|
public Sprite GetSprite(ThemeAssetType type)
|
|
{
|
|
if (_cache == null)
|
|
{
|
|
_cache = new Dictionary<ThemeAssetType, Sprite>();
|
|
foreach (var entry in entries)
|
|
if (!_cache.ContainsKey(entry.Type))
|
|
_cache.Add(entry.Type, entry.Sprite);
|
|
}
|
|
|
|
return _cache.TryGetValue(type, out var sprite) ? sprite : null;
|
|
}
|
|
|
|
[Serializable]
|
|
public class ThemeEntry
|
|
{
|
|
public ThemeAssetType Type;
|
|
public Sprite Sprite;
|
|
}
|
|
}
|
|
} |