BsScriptResourceRef.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. /**
  13. * @brief Interop class between C++ & CLR for ResourceRef.
  14. */
  15. class BS_SCR_BE_EXPORT ScriptResourceRef : public ScriptObject<ScriptResourceRef>
  16. {
  17. public:
  18. SCRIPT_OBJ(ENGINE_ASSEMBLY, "BansheeEngine", "ResourceRef")
  19. /**
  20. * @brief Creates a new managed ResourceRef for the provided resource.
  21. *
  22. * @param handle Handle to the resource to wrap.
  23. */
  24. template<class T>
  25. static MonoObject* create(const WeakResourceHandle<T>& handle)
  26. {
  27. return createInternal(handle);
  28. }
  29. /**
  30. * @brief Creates a new managed ResourceRef for the provided texture.
  31. *
  32. * @param handle Handle to the texture to wrap.
  33. */
  34. static MonoObject* create(const WeakResourceHandle<Texture>& handle, TextureType type = TEX_TYPE_2D);
  35. /**
  36. * @brief Returns a weak handle to the resource referenced by this object.
  37. */
  38. WeakResourceHandle<Resource> getHandle() const { return mResource; }
  39. private:
  40. friend class ScriptResourceRefBase;
  41. ScriptResourceRef(MonoObject* instance, const WeakResourceHandle<Resource>& handle);
  42. /**
  43. * @brief Creates a new managed ResourceRef for the provided resource type.
  44. *
  45. * @param 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. }