BsScriptResourceRef.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 "BsTexture.h"
  7. #include "BsScriptResource.h"
  8. #include "BsMonoClass.h"
  9. #include "BsRTTIType.h"
  10. namespace BansheeEngine
  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. /**
  31. * Creates a new managed ResourceRef for the provided texture.
  32. *
  33. * @param[in] handle Handle to the texture to wrap.
  34. */
  35. static MonoObject* create(const WeakResourceHandle<Texture>& handle, TextureType type = TEX_TYPE_2D);
  36. /** Returns a weak handle to the resource referenced by this object. */
  37. WeakResourceHandle<Resource> getHandle() const { return mResource; }
  38. private:
  39. friend class ScriptResourceRefBase;
  40. ScriptResourceRef(MonoObject* instance, const WeakResourceHandle<Resource>& handle);
  41. /**
  42. * Creates a new managed ResourceRef for the provided resource type.
  43. *
  44. * @param[in] handle Handle to the resource to wrap.
  45. */
  46. static MonoObject* createInternal(const WeakResourceHandle<Resource>& handle);
  47. WeakResourceHandle<Resource> mResource;
  48. /************************************************************************/
  49. /* CLR HOOKS */
  50. /************************************************************************/
  51. static bool internal_IsLoaded(ScriptResourceRef* nativeInstance);
  52. static MonoObject* internal_GetResource(ScriptResourceRef* nativeInstance);
  53. static MonoString* internal_GetUUID(ScriptResourceRef* thisPtr);
  54. };
  55. /** @} */
  56. }