2
0

BsScriptResourceRef.h 2.3 KB

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