public SoundEffect Load(AssetLoaderContext context, string assetName) { using (var stream = context.Open(assetName)) { return(SoundEffect.FromStream(stream)); } }
public Texture2D Load(AssetLoaderContext context, string assetName) { using (var stream = context.Open(assetName)) { return(Texture2DExtensions.FromStream(context.GraphicsDevice, stream, context.Settings.PremultiplyAlphaForTextures)); } }
public T Load <T>(string assetName) { var type = typeof(T); assetName = assetName.Replace('\\', SeparatorSymbol); Dictionary <string, object> cache; if (_cache.TryGetValue(type, out cache)) { object cached; if (cache.TryGetValue(assetName, out cached)) { // Found in cache return((T)cached); } } LoaderInfo loaderBase; if (!Loaders.TryGetValue(type, out loaderBase)) { // Try determine it using AssetLoader attribute var attr = type.FindAttribute <AssetLoaderAttribute>(); if (attr == null) { throw new Exception(string.Format("Unable to resolve AssetLoader for type {0}", type.Name)); } // Create loader loaderBase = new LoaderInfo(Activator.CreateInstance(attr.AssetLoaderType), attr.StoreInCache); // Save in the _loaders Loaders[type] = loaderBase; } var loader = (IAssetLoader <T>)loaderBase.Loader; var baseFolder = string.Empty; var assetFileName = assetName; var separatorIndex = assetName.LastIndexOf(SeparatorSymbol); if (separatorIndex != -1) { baseFolder = assetName.Substring(0, separatorIndex); assetFileName = assetName.Substring(separatorIndex + 1); } var context = new AssetLoaderContext(this, baseFolder); var result = loader.Load(context, assetFileName); if (loaderBase.StoreInCache) { // Store in cache if (cache == null) { cache = new Dictionary <string, object>(); _cache[type] = cache; } cache[assetName] = result; } return(result); }
private TextureWithOffset TextureGetter(AssetLoaderContext context, string name) { var texture = context.Load <Texture2D>(name); return(new TextureWithOffset(texture)); }
public SpriteFont Load(AssetLoaderContext context, string assetName) { var fontData = context.Load <string>(assetName); return(BMFontLoader.Load(fontData, name => TextureGetter(context, name))); }