public static List <ResourcePtr> ScanForAssetType(string Scheme) { List <ResourcePtr> ResourcePtrs = new List <ResourcePtr>(); //First, Get a list of file extensions we are looking for. IEnumerable <string> FileExts = Factories.Where(x => x.ResourceSchemes.Contains(Scheme)) .SelectMany(x => x.FileExtensions); //Get the files from the search paths where we have a file extension IEnumerable <string> Paths = pathOrder.SelectMany(x => x.Files(FileExts.ToArray())); foreach (string Path in Paths) { foreach (string Ext in FileExts) { if (Path.EndsWith(Ext, StringComparison.InvariantCultureIgnoreCase)) { ResourcePtr ptr = new ResourcePtr(string.Format("{0}:{1}", Scheme, Path)); ResourcePtrs.Add(ptr); break; } } } return(ResourcePtrs); }
public static void BulkLoadAssets(IEnumerable <ResourcePtr> Resources, Action LoadCompleteDelegate, ResourceLoadingProgress resourceLoadingProgressDelegate) { if (Resources == null) { LoadCompleteDelegate?.Invoke(); return; } //If the engine doesn't exist, just process them now if (Engine.Instance == null) { for (int i = 0; i < Resources.Count(); i++) { ResourcePtr Ptr = Resources.ElementAt(i); resourceLoadingProgressDelegate?.Invoke(Ptr, i, Resources.Count()); Ptr.Load(); } LoadCompleteDelegate?.Invoke(); } else { //Create a bulk task for the engine to process ResourceLoadingTask Task = new ResourceLoadingTask(Resources); Task.LoadingProgressDelegate = resourceLoadingProgressDelegate; Task.PostLoadAction = LoadCompleteDelegate; LoadingTasks.Add(Task); Engine.Instance.AddTickfunc(Task.TickFunc); } }
public static object LoadResource(ResourcePtr Ptr) { if (!IsResourceLoaded(Ptr)) { if (!ResourceExists(Ptr)) { throw new ArgumentException("Cannot find file: " + Ptr.ToString() + " In any search path!"); } ResourceFactory factory = GetFactoryForResource(Ptr); if (factory == null) { Logger.Error("Failed to find Factory for resource: {0}", Ptr.ToString()); return(null); } using (Stream stream = GetFileStream(Ptr)) { object resource = factory.GetResource(stream); if (resource is IIsResource) { (resource as IIsResource).ResourcePtr = Ptr; } ResourceCache.Add(Ptr, resource); } Logger.Info("Loaded Resource {0}", Ptr.ToString()); } return(ResourceCache[Ptr]); }
internal static object GetLoadedResource(ResourcePtr Ptr) { if (IsResourceLoaded(Ptr)) { return(ResourceCache[Ptr]); } return(null); }
public static bool EmplaceInMemoryResource(ResourcePtr Ptr, object Resource) { if (ResourceCache.ContainsKey(Ptr)) { return(false); } Logger.Info("Emplaced object: {0} into {1}", Resource.ToString(), Ptr.ToString()); ResourceCache.Add(Ptr, Resource); return(true); }
public virtual object GetResource(ResourcePtr Ptr) { object instance = null; using (Stream s = FileSystem.GetFileStream(Ptr)) { instance = GetResource(s); } return(instance); }
internal static Stream GetFileStream(ResourcePtr Ptr) { for (int i = 0; i < pathOrder.Length; i++) { if (pathOrder[i].ExistsInPath(Ptr)) { return(pathOrder[i].GetFileStream(Ptr)); } } return(null); }
internal static bool ResourceExists(ResourcePtr Ptr) { for (int i = 0; i < pathOrder.Length; i++) { if (pathOrder[i].ExistsInPath(Ptr)) { return(true); } } return(false); }
internal static ResourceFactory GetFactoryForResource(ResourcePtr Ptr) { return(Factories.FirstOrDefault((f) => f.ResourceSchemes.Contains(Ptr.ResourceScheme) && f.FileExtensions.Select(x => x.ToLower()).Contains(Path.GetExtension(Ptr.Path).ToLower()))); }
public static void UnloadResource(ResourcePtr Ptr) { ResourceCache.Remove(Ptr); }
public static bool IsResourceLoaded(ResourcePtr Ptr) { return(ResourceCache.ContainsKey(Ptr)); }
public static T LoadResource <T>(ResourcePtr Ptr) where T : class { return(LoadResource(Ptr) as T); }
public virtual Stream GetFileStream(ResourcePtr Ptr) { return(GetFileStream(Ptr.FilePath)); }
public virtual bool ExistsInPath(ResourcePtr Ptr) { return(ExistsInPath(Ptr.FilePath)); }
public abstract object GetResource(ResourcePtr ptr, Stream stream);