BsScriptResourceRef.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 ResourceRef.
  12. */
  13. class BS_SCR_BE_EXPORT ScriptResourceRef : public ScriptObject<ScriptResourceRef>
  14. {
  15. public:
  16. SCRIPT_OBJ(ENGINE_ASSEMBLY, "BansheeEngine", "ResourceRef")
  17. /**
  18. * @brief Creates a new managed ResourceRef for the provided resource.
  19. *
  20. * @param handle Handle to the resource to wrap.
  21. */
  22. template<class T>
  23. static MonoObject* create(const WeakResourceHandle<T>& handle)
  24. {
  25. MonoClass* resourceClass = ScriptResource::getClassFromTypeId(T::getRTTIStatic()->getRTTIId());
  26. if (resourceClass == nullptr)
  27. return nullptr;
  28. return create(resourceClass->_getInternalClass(), handle);
  29. }
  30. /**
  31. * @brief Creates a new managed ResourceRef for the provided texture.
  32. *
  33. * @param handle Handle to the texture to wrap.
  34. */
  35. static MonoObject* create(const WeakResourceHandle<Texture>& handle, TextureType type = TEX_TYPE_2D);
  36. /**
  37. * @brief Returns a weak handle to the resource referenced by this object.
  38. */
  39. WeakResourceHandle<Resource> getHandle() const { return mResource; }
  40. private:
  41. friend class ScriptResourceRefBase;
  42. ScriptResourceRef(MonoObject* instance, const WeakResourceHandle<Resource>& handle);
  43. /**
  44. * @brief Creates a new managed ResourceRef for the provided resource type.
  45. *
  46. * @param resourceClass Managed class of the resource to reference.
  47. * @param handle Handle to the resource to wrap.
  48. */
  49. static MonoObject* create(::MonoClass* resourceClass, const WeakResourceHandle<Resource>& handle);
  50. WeakResourceHandle<Resource> mResource;
  51. /************************************************************************/
  52. /* CLR HOOKS */
  53. /************************************************************************/
  54. static bool internal_IsLoaded(ScriptResourceRef* nativeInstance);
  55. static MonoObject* internal_GetResource(ScriptResourceRef* nativeInstance);
  56. static MonoString* internal_GetUUID(ScriptResourceRef* thisPtr);
  57. };
  58. }