using System; using System.Runtime.CompilerServices; namespace BansheeEngine { /// /// Handles dynamic loading of resources during runtime. /// public static class Resources { /// /// Loads a resource at the specified path. If running outside of the editor you must make sure to mark that /// the resource gets included in the build. If running inside the editor this has similar functionality as /// if loading using the project library. If resource is already loaded an existing instance is returned. /// /// Type of the resource. /// Path of the resource, relative to game directory. If running from editor this will be /// the same location as resource location in the project library. /// Loaded resource, or null if resource cannot be found. public static T Load(string path) where T : Resource { return (T)Internal_Load(path); } /// /// Loads a resource referenced by the provided reference. If running outside of the editor you must make sure /// to mark that the resource gets included in the build. If running inside the editor this has similar functionality /// as if loading using the project library. If resource is already loaded an existing instance is returned. /// /// Type of the resource. /// Reference to the resource to load. /// Loaded resource, or null if resource cannot be found. public static T Load(ResourceRefBase reference) where T : Resource { return (T)Internal_LoadRef(reference); } /// /// Unloads all resources that are no longer referenced. Usually the system keeps resources in memory even if /// they are no longer referenced to avoid constant loading/unloading if resource is often passed around. /// public static void UnloadUnused() { Internal_UnloadUnused(); } [MethodImpl(MethodImplOptions.InternalCall)] private static extern Resource Internal_Load(string path); [MethodImpl(MethodImplOptions.InternalCall)] private static extern Resource Internal_LoadRef(ResourceRefBase reference); [MethodImpl(MethodImplOptions.InternalCall)] private static extern void Internal_UnloadUnused(); } }