ResourceRef.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. using System;
  4. using System.Runtime.CompilerServices;
  5. namespace BansheeEngine
  6. {
  7. /** @addtogroup Resources
  8. * @{
  9. */
  10. /// <summary>
  11. /// Allows you to store a reference to a resource without needing to have that resource loaded.
  12. /// </summary>
  13. public class ResourceRef : ScriptObject
  14. {
  15. /// <summary>
  16. /// Constructor for internal use only.
  17. /// </summary>
  18. protected ResourceRef()
  19. { }
  20. /// <summary>
  21. /// Checks is the referenced resource loaded.
  22. /// </summary>
  23. public bool IsLoaded
  24. {
  25. get { return Internal_IsLoaded(mCachedPtr); }
  26. }
  27. /// <inheritdoc/>
  28. public override bool Equals(object other)
  29. {
  30. if (!(other is ResourceRef))
  31. return false;
  32. ResourceRef otherRef = (ResourceRef)other;
  33. UUID lhs, rhs;
  34. Internal_GetUUID(mCachedPtr, out lhs);
  35. Internal_GetUUID(otherRef.mCachedPtr, out rhs);
  36. return lhs.Equals(rhs);
  37. }
  38. /// <inheritdoc/>
  39. public override int GetHashCode()
  40. {
  41. UUID uuid;
  42. Internal_GetUUID(mCachedPtr, out uuid);
  43. return uuid.GetHashCode();
  44. }
  45. [MethodImpl(MethodImplOptions.InternalCall)]
  46. private static extern bool Internal_IsLoaded(IntPtr thisPtr);
  47. [MethodImpl(MethodImplOptions.InternalCall)]
  48. protected static extern Resource Internal_GetResource(IntPtr thisPtr);
  49. [MethodImpl(MethodImplOptions.InternalCall)]
  50. private static extern void Internal_GetUUID(IntPtr thisPtr, out UUID uuid);
  51. }
  52. /** @} */
  53. }