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.
///
/// 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);
}
///
/// Unloads a resource, freeing its memory.
///
/// Resource to unload.
public static void Unload(Resource resource)
{
if (resource != null)
Internal_Unload(resource.GetCachedPtr());
}
///
/// 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 void Internal_Unload(IntPtr resourcePtr);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_UnloadUnused();
}
}