A Smoll game engine
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

46 righe
1.4 KiB

  1. using Raylib_cs;
  2. namespace Smoll.Ex2
  3. {
  4. class RaylibAssetManagerModule : IEngineModule {
  5. string path;
  6. Dictionary<string, Image> images;
  7. Dictionary<string, Texture2D> textures;
  8. Dictionary<string, Sound> sounds;
  9. public RaylibAssetManagerModule(string path = "./assets") {
  10. this.path = path;
  11. images = new Dictionary<string, Image>();
  12. textures = new Dictionary<string, Texture2D>();
  13. sounds = new Dictionary<string, Sound>();
  14. }
  15. public Image GetImage(string name) {
  16. Image image;
  17. if(! images.TryGetValue(name, out image)) {
  18. image = Raylib.LoadImage(path+"/"+name);
  19. images.Add(name, image);
  20. }
  21. return image;
  22. }
  23. public Texture2D GetTexture(string name) {
  24. Texture2D texture;
  25. if(! textures.TryGetValue(name, out texture)) {
  26. Image image = GetImage(name);
  27. texture = Raylib.LoadTextureFromImage(image);
  28. textures.Add(name, texture);
  29. }
  30. return texture;
  31. }
  32. public Sound GetSound(string name) {
  33. Sound sound;
  34. if(! sounds.TryGetValue(name, out sound)) {
  35. sound = Raylib.LoadSound(path+"/"+name);
  36. sounds.Add(name, sound);
  37. }
  38. return sound;
  39. }
  40. }
  41. }