A Smoll game engine
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

58 satır
1.8 KiB

using Raylib_cs;
namespace Smoll.Ex2
{
class RaylibAssetManagerModule : IEngineModule {
string path;
Dictionary<string, Image> images;
Dictionary<string, Texture2D> textures;
Dictionary<string, Sound> sounds;
Dictionary<string, string> scripts;
public RaylibAssetManagerModule(string path = "./assets") {
this.path = path;
images = new Dictionary<string, Image>();
textures = new Dictionary<string, Texture2D>();
sounds = new Dictionary<string, Sound>();
scripts = new Dictionary<string, string>();
}
public Image GetImage(string name) {
Image image;
if(! images.TryGetValue(name, out image)) {
image = Raylib.LoadImage(path+"/"+name);
images.Add(name, image);
}
return image;
}
public Texture2D GetTexture(string name) {
Texture2D texture;
if(! textures.TryGetValue(name, out texture)) {
Image image = GetImage(name);
texture = Raylib.LoadTextureFromImage(image);
textures.Add(name, texture);
}
return texture;
}
public Sound GetSound(string name) {
Sound sound;
if(! sounds.TryGetValue(name, out sound)) {
sound = Raylib.LoadSound(path+"/"+name);
sounds.Add(name, sound);
}
return sound;
}
public string GetScript(string name) {
string script;
if(! scripts.TryGetValue(name, out script)) {
script = File.ReadAllText(path+"/"+name);
scripts.Add(name, script);
}
return script;
}
}
}