BsScriptResource.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #pragma once
  2. #include "BsScriptEnginePrerequisites.h"
  3. #include "BsScriptObject.h"
  4. namespace BansheeEngine
  5. {
  6. /**
  7. * @brief Types of resources accessible from script code.
  8. */
  9. // Note: Must be the same as C# enum ScriptResourceType
  10. enum class ScriptResourceType
  11. {
  12. Texture, SpriteTexture, Mesh, Font, Shader, Material, Prefab, PlainText, ScriptCode, StringTable, GUISkin, Undefined
  13. };
  14. /**
  15. * @brief Base class for all resource interop objects.
  16. */
  17. class BS_SCR_BE_EXPORT ScriptResourceBase : public PersistentScriptObjectBase
  18. {
  19. public:
  20. /**
  21. * @brief Returns the internal wrapped resource.
  22. */
  23. virtual HResource getNativeHandle() const = 0;
  24. /**
  25. * @brief Sets the internal resource this object wraps.
  26. */
  27. virtual void setNativeHandle(const HResource& resource) = 0;
  28. /**
  29. * @copydoc ScriptObjectBase::beginRefresh
  30. */
  31. virtual ScriptObjectBackup beginRefresh() override;
  32. /**
  33. * @copydoc ScriptObjectBase::endRefresh
  34. */
  35. virtual void endRefresh(const ScriptObjectBackup& backupData) override;
  36. protected:
  37. friend class ScriptResourceManager;
  38. ScriptResourceBase(MonoObject* instance);
  39. virtual ~ScriptResourceBase() {}
  40. bool mRefreshInProgress;
  41. };
  42. /**
  43. * @brief Interop class between C++ & CLR for Resource.
  44. */
  45. class BS_SCR_BE_EXPORT ScriptResource : public ScriptObject<ScriptResource, ScriptResourceBase>
  46. {
  47. public:
  48. SCRIPT_OBJ(ENGINE_ASSEMBLY, "BansheeEngine", "Resource")
  49. /**
  50. * @brief Converts a RTTI id belonging to a resource type into a ScriptResourceType.
  51. */
  52. static ScriptResourceType getTypeFromTypeId(UINT32 typeId);
  53. /**
  54. * @brief Converts a ScriptResourceType into a RTTI id belonging to that resource type.
  55. */
  56. static UINT32 getTypeIdFromType(ScriptResourceType type);
  57. private:
  58. ScriptResource(MonoObject* instance)
  59. :ScriptObject(instance)
  60. { }
  61. };
  62. }