BsScriptResourceRef.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #pragma once
  2. #include "BsScriptEnginePrerequisites.h"
  3. #include "BsScriptObject.h"
  4. #include "BsTexture.h"
  5. #include "BsScriptResource.h"
  6. #include "BsMonoClass.h"
  7. #include "BsRTTIType.h"
  8. namespace BansheeEngine
  9. {
  10. /**
  11. * @brief Interop class between C++ & CLR for ResourceRefBase.
  12. */
  13. class BS_SCR_BE_EXPORT ScriptResourceRefBase : public ScriptObject<ScriptResourceRefBase>
  14. {
  15. public:
  16. SCRIPT_OBJ(ENGINE_ASSEMBLY, "BansheeEngine", "ResourceRefBase")
  17. ScriptResourceRefBase(MonoObject* instance, const WeakResourceHandle<Resource>& resource);
  18. /**
  19. * @brief Returns a weak handle to the resource referenced by this object.
  20. */
  21. WeakResourceHandle<Resource> getHandle() const { return mResource; }
  22. private:
  23. WeakResourceHandle<Resource> mResource;
  24. /************************************************************************/
  25. /* CLR HOOKS */
  26. /************************************************************************/
  27. static bool internal_IsLoaded(ScriptResourceRefBase* nativeInstance);
  28. static MonoObject* internal_GetResource(ScriptResourceRefBase* nativeInstance);
  29. static MonoString* internal_GetUUID(ScriptResourceRefBase* thisPtr);
  30. };
  31. /**
  32. * @brief Interop class between C++ & CLR for ResourceRef.
  33. */
  34. class BS_SCR_BE_EXPORT ScriptResourceRef : public ScriptObject<ScriptResourceRef>
  35. {
  36. public:
  37. SCRIPT_OBJ(ENGINE_ASSEMBLY, "BansheeEngine", "ResourceRef`1")
  38. /**
  39. * @brief Creates a new managed ResourceRef for the provided resource.
  40. *
  41. * @param handle Handle to the resource to wrap.
  42. */
  43. template<class T>
  44. static MonoObject* create(const WeakResourceHandle<T>& handle)
  45. {
  46. MonoClass* resourceClass = ScriptResource::getClassFromTypeId(T::getRTTIStatic()->getRTTIId());
  47. if (resourceClass == nullptr)
  48. return nullptr;
  49. return create(resourceClass->_getInternalClass(), handle);
  50. }
  51. /**
  52. * @brief Creates a new managed ResourceRef for the provided texture.
  53. *
  54. * @param handle Handle to the texture to wrap.
  55. */
  56. static MonoObject* create(const WeakResourceHandle<Texture>& handle, TextureType type = TEX_TYPE_2D);
  57. private:
  58. friend class ScriptResourceRefBase;
  59. ScriptResourceRef(MonoObject* instance);
  60. /**
  61. * @brief Creates a new managed ResourceRef for the provided resource type.
  62. *
  63. * @param resourceClass Managed class of the resource to reference.
  64. * @param handle Handle to the resource to wrap.
  65. */
  66. static MonoObject* create(::MonoClass* resourceClass, const WeakResourceHandle<Resource>& handle);
  67. };
  68. }