BsScriptResourceManager.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #pragma once
  2. #include "BsScriptEnginePrerequisites.h"
  3. #include "BsModule.h"
  4. #include <mono/jit/jit.h>
  5. namespace BansheeEngine
  6. {
  7. class BS_SCR_BE_EXPORT ScriptResourceManager : public Module<ScriptResourceManager>
  8. {
  9. public:
  10. ScriptResourceManager();
  11. /**
  12. * @note Throws an exception if resource for the handle already exists.
  13. * Creates a new managed instance of the object.
  14. */
  15. template<class RetType, class InType>
  16. void createScriptResource(const ResourceHandle<InType>& resourceHandle, RetType** out);
  17. /**
  18. * @note Throws an exception if resource for the handle already exists.
  19. * Initializes the ScriptResource with an existing managed instance.
  20. */
  21. template<class RetType, class InType>
  22. void createScriptResource(MonoObject* existingInstance, const ResourceHandle<InType>& resourceHandle, RetType** out);
  23. /**
  24. * @note If @p create is true, creates a new script resource if one doesn't exist,
  25. * otherwise returns nullptr if script resource doesn't exist.
  26. */
  27. template<class RetType, class InType>
  28. void getScriptResource(const ResourceHandle<InType>& resourceHandle, RetType** out, bool create = false);
  29. template<>
  30. void createScriptResource(const ResourceHandle<StringTable>& resourceHandle, ScriptStringTable** out);
  31. template<>
  32. void createScriptResource(const HResource& resourceHandle, ScriptResourceBase** out);
  33. /**
  34. * @note Returns nullptr if script resource doesn't exist.
  35. */
  36. ScriptResourceBase* getScriptResource(const String& UUID);
  37. void destroyScriptResource(ScriptResourceBase* resource);
  38. private:
  39. UnorderedMap<String, ScriptResourceBase*> mScriptResources;
  40. void throwExceptionIfInvalidOrDuplicate(const String& uuid) const;
  41. };
  42. }