ResourceRef.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using System;
  2. using System.Runtime.CompilerServices;
  3. namespace BansheeEngine
  4. {
  5. /// <summary>
  6. /// Allows you to store a reference to a resource without needing to have that resource loaded.
  7. /// </summary>
  8. public class ResourceRef<T> : ScriptObject where T : Resource
  9. {
  10. /// <summary>
  11. /// Constructor for internal use only.
  12. /// </summary>
  13. private ResourceRef()
  14. { }
  15. /// <summary>
  16. /// Checks is the referenced resource loaded
  17. /// </summary>
  18. public bool IsLoaded
  19. {
  20. get { return Internal_IsLoaded(mCachedPtr); }
  21. }
  22. /// <summary>
  23. /// Retrieves the referenced resource. This will load the resources if it is not already loaded.
  24. /// </summary>
  25. /// <typeparam name="T">Type of the resource to load.</typeparam>
  26. /// <returns>Loaded resource object.</returns>
  27. public T Get()
  28. {
  29. return (T)Internal_GetResource(mCachedPtr);
  30. }
  31. [MethodImpl(MethodImplOptions.InternalCall)]
  32. private static extern bool Internal_IsLoaded(IntPtr thisPtr);
  33. [MethodImpl(MethodImplOptions.InternalCall)]
  34. private static extern Resource Internal_GetResource(IntPtr thisPtr);
  35. }
  36. }