Resources.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using System;
  2. using System.Runtime.CompilerServices;
  3. namespace BansheeEngine
  4. {
  5. /// <summary>
  6. /// Handles dynamic loading of resources during runtime.
  7. /// </summary>
  8. public static class Resources
  9. {
  10. /// <summary>
  11. /// Loads a resource at the specified path. If running outside of the editor you must make sure to mark that
  12. /// the resource gets included in the build. If running inside the editor this has similar functionality as
  13. /// if loading using the project library.
  14. /// </summary>
  15. /// <typeparam name="T">Type of the resource.</typeparam>
  16. /// <param name="path">Path of the resource, relative to game directory. If running from editor this will be
  17. /// the same location as resource location in the project library.</param>
  18. /// <returns>Loaded resource, or null if resource cannot be found.</returns>
  19. public static T Load<T>(string path) where T : Resource
  20. {
  21. return (T)Internal_Load(path);
  22. }
  23. /// <summary>
  24. /// Unloads all resources that are no longer referenced. Usually the system keeps resources in memory even if
  25. /// they are no longer referenced to avoid constant loading/unloading if resource is often passed around.
  26. /// </summary>
  27. public static void UnloadUnused()
  28. {
  29. Internal_UnloadUnused();
  30. }
  31. [MethodImpl(MethodImplOptions.InternalCall)]
  32. private static extern Resource Internal_Load(string path);
  33. [MethodImpl(MethodImplOptions.InternalCall)]
  34. private static extern void Internal_UnloadUnused();
  35. }
  36. }