using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; using System.Collections.Generic; namespace AlienAttack.MonoGame.Textures; public sealed class TextureCache { private readonly Dictionary _cache = []; private ContentManager _content = default!; public void Initialize(ContentManager content) => _content = content; public Texture2D Get(string assetName) { if (_cache.TryGetValue(assetName, out var texture)) return texture; texture = _content.Load(assetName); _cache[assetName] = texture; return texture; } public void Clear() => _cache.Clear(); }