BsScriptResourceRef.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsScriptEnginePrerequisites.h"
  5. #include "BsScriptObject.h"
  6. #include "Image/BsTexture.h"
  7. #include "Wrappers/BsScriptResource.h"
  8. #include "BsMonoClass.h"
  9. #include "Reflection/BsRTTIType.h"
  10. namespace bs
  11. {
  12. /** @addtogroup ScriptInteropEngine
  13. * @{
  14. */
  15. /** Interop class between C++ & CLR for ResourceRef. */
  16. class BS_SCR_BE_EXPORT ScriptResourceRef : public ScriptObject<ScriptResourceRef>
  17. {
  18. public:
  19. SCRIPT_OBJ(ENGINE_ASSEMBLY, "BansheeEngine", "ResourceRef")
  20. /**
  21. * Creates a new managed ResourceRef for the provided resource.
  22. *
  23. * @param[in] handle Handle to the resource to wrap.
  24. */
  25. template<class T>
  26. static MonoObject* create(const WeakResourceHandle<T>& handle)
  27. {
  28. return createInternal(handle);
  29. }
  30. /** Returns a weak handle to the resource referenced by this object. */
  31. WeakResourceHandle<Resource> getHandle() const { return mResource; }
  32. private:
  33. friend class ScriptResourceRefBase;
  34. ScriptResourceRef(MonoObject* instance, const WeakResourceHandle<Resource>& handle);
  35. /**
  36. * Creates a new managed ResourceRef for the provided resource type.
  37. *
  38. * @param[in] handle Handle to the resource to wrap.
  39. */
  40. static MonoObject* createInternal(const WeakResourceHandle<Resource>& handle);
  41. WeakResourceHandle<Resource> mResource;
  42. /************************************************************************/
  43. /* CLR HOOKS */
  44. /************************************************************************/
  45. static bool internal_IsLoaded(ScriptResourceRef* nativeInstance);
  46. static MonoObject* internal_GetResource(ScriptResourceRef* nativeInstance);
  47. static void internal_GetUUID(ScriptResourceRef* thisPtr, UUID* uuid);
  48. };
  49. /** @} */
  50. }