For my game, I'm making a resource class which manager resources likes textures, sounds, fonts, etc. I made this ImageList class, which automatically loads textures during runtime as they're needed.
class TextureList
{
private Dictionary<string, Texture> _list;
public Texture this[string name]
{
get
{
Texture tex;
bool success = List.TryGetValue(name, out tex);
if (!success)
{
tex = Resources.LoadImage(name);
List[name] = tex;
}
return tex;
}
}
protected Dictionary<String, Texture> List
{
get
{
return _list ?? new Dictionary<String, Texture>();
}
}
}
Now I want to make to make this class generic, so that I can make a FontList or SoundList class without the hassle of changing every Texture to Sound or Font (and writing lots of duplicate code). Anyone willing to help me out on making a generic version of this?