コード例 #1
0
        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);
        }
コード例 #2
0
        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);
            }
        }
コード例 #3
0
        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]);
        }
コード例 #4
0
 internal static object GetLoadedResource(ResourcePtr Ptr)
 {
     if (IsResourceLoaded(Ptr))
     {
         return(ResourceCache[Ptr]);
     }
     return(null);
 }
コード例 #5
0
        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);
        }
コード例 #6
0
        public virtual object GetResource(ResourcePtr Ptr)
        {
            object instance = null;

            using (Stream s = FileSystem.GetFileStream(Ptr))
            {
                instance = GetResource(s);
            }

            return(instance);
        }
コード例 #7
0
        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);
        }
コード例 #8
0
        internal static bool ResourceExists(ResourcePtr Ptr)
        {
            for (int i = 0; i < pathOrder.Length; i++)
            {
                if (pathOrder[i].ExistsInPath(Ptr))
                {
                    return(true);
                }
            }

            return(false);
        }
コード例 #9
0
 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())));
 }
コード例 #10
0
 public static void UnloadResource(ResourcePtr Ptr)
 {
     ResourceCache.Remove(Ptr);
 }
コード例 #11
0
 public static bool IsResourceLoaded(ResourcePtr Ptr)
 {
     return(ResourceCache.ContainsKey(Ptr));
 }
コード例 #12
0
 public static T LoadResource <T>(ResourcePtr Ptr) where T : class
 {
     return(LoadResource(Ptr) as T);
 }
コード例 #13
0
 public virtual Stream GetFileStream(ResourcePtr Ptr)
 {
     return(GetFileStream(Ptr.FilePath));
 }
コード例 #14
0
 public virtual bool ExistsInPath(ResourcePtr Ptr)
 {
     return(ExistsInPath(Ptr.FilePath));
 }
コード例 #15
0
 public abstract object GetResource(ResourcePtr ptr, Stream stream);