BsScriptResourceRef.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. return createInternal(handle);
  26. }
  27. /**
  28. * @brief Creates a new managed ResourceRef for the provided texture.
  29. *
  30. * @param handle Handle to the texture to wrap.
  31. */
  32. static MonoObject* create(const WeakResourceHandle<Texture>& handle, TextureType type = TEX_TYPE_2D);
  33. /**
  34. * @brief Returns a weak handle to the resource referenced by this object.
  35. */
  36. WeakResourceHandle<Resource> getHandle() const { return mResource; }
  37. private:
  38. friend class ScriptResourceRefBase;
  39. ScriptResourceRef(MonoObject* instance, const WeakResourceHandle<Resource>& handle);
  40. /**
  41. * @brief Creates a new managed ResourceRef for the provided resource type.
  42. *
  43. * @param handle Handle to the resource to wrap.
  44. */
  45. static MonoObject* createInternal(const WeakResourceHandle<Resource>& handle);
  46. WeakResourceHandle<Resource> mResource;
  47. /************************************************************************/
  48. /* CLR HOOKS */
  49. /************************************************************************/
  50. static bool internal_IsLoaded(ScriptResourceRef* nativeInstance);
  51. static MonoObject* internal_GetResource(ScriptResourceRef* nativeInstance);
  52. static MonoString* internal_GetUUID(ScriptResourceRef* thisPtr);
  53. };
  54. }