void IContentRegistry.RegisterHandler <T>(string key, FileLoadMethod <T> method) { try { Interceptor.RegisterHandler(key, method); } catch (Exception err) { EntoFramework.Logger.ExitGameImmediately("Was unable to register custom handler in loader" + err); } }
public static void RegisterFileLoader <T>(string assetName, FileLoadMethod <T> handler) { if (_HandledAssets.Exists(x => x.Key == assetName && x.Value == typeof(T))) { Log.Warning($"Load handler conflict on asset {assetName}. Using first"); return; } KeyValuePair <string, Type> key = new KeyValuePair <string, Type>(assetName, typeof(T)); _HandledAssets.Add(key); _LoaderRegistry.Add(key, handler); }
/// <summary>Register a delegate which loads an asset.</summary> /// <typeparam name="T">The expected asset type.</typeparam> /// <param name="assetName">The asset name to intercept.</param> /// <param name="handler">The handler which loads the asset.</param> internal void RegisterHandler <T>(string assetName, FileLoadMethod <T> handler) { // validate key assetName = this.NormaliseAssetName(assetName); if (!this.MarkHandledOrWarn(assetName)) { return; } // add this.LoaderDelegate.Add(assetName, new KeyValuePair <Type, Delegate>(typeof(T), handler)); this.ContentHelper.InvalidateCache(assetName); }
/// <summary>Load a matched asset.</summary> /// <param name="asset">Basic metadata about the asset being loaded.</param> public T Load <T>(IAssetInfo asset) { // texture redirect string redirectPath = this.GetRedirect <T>(asset); if (redirectPath != null) { string relativePath = ContentHandler.GetRelativePath(redirectPath, this.ModPath); // underlying content manager doesn't allow absolute paths return(this.ContentHelper.Load <T>(relativePath)); } // loader delegate FileLoadMethod <T> loader = this.GetLoaderDelegate <T>(asset); if (loader != null) { return(loader.Invoke(asset.AssetName)); } // none found? throw new InvalidOperationException("ContentManager: no asset loaders found. This shouldn't happen."); }
public void RegisterHandler <T>(string assetName, FileLoadMethod <T> handler) { Registry.RegisterHandler(assetName, handler); }