BsScriptResourceManager.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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. ScriptTexture2D* createScriptTexture2D(const HTexture& resourceHandle);
  16. /**
  17. * @note Throws an exception if resource for the handle already exists.
  18. * Creates a new managed instance of the object.
  19. */
  20. ScriptTexture3D* createScriptTexture3D(const HTexture& resourceHandle);
  21. /**
  22. * @note Throws an exception if resource for the handle already exists.
  23. * Creates a new managed instance of the object.
  24. */
  25. ScriptTextureCube* createScriptTextureCube(const HTexture& resourceHandle);
  26. /**
  27. * @note Throws an exception if resource for the handle already exists.
  28. * Initializes the ScriptResource with an existing managed instance.
  29. */
  30. ScriptTexture2D* createScriptTexture2D(MonoObject* existingInstance, const HTexture& resourceHandle);
  31. /**
  32. * @note Throws an exception if resource for the handle already exists.
  33. * Initializes the ScriptResource with an existing managed instance.
  34. */
  35. ScriptTexture3D* createScriptTexture3D(MonoObject* existingInstance, const HTexture& resourceHandle);
  36. /**
  37. * @note Throws an exception if resource for the handle already exists.
  38. * Initializes the ScriptResource with an existing managed instance.
  39. */
  40. ScriptTextureCube* createScriptTextureCube(MonoObject* existingInstance, const HTexture& resourceHandle);
  41. /**
  42. * @note Throws an exception if resource for the handle already exists.
  43. * Initializes the ScriptResource with an existing managed instance.
  44. */
  45. ScriptShader* createScriptShader(const HShader& resourceHandle);
  46. /**
  47. * @note Throws an exception if resource for the handle already exists.
  48. * Initializes the ScriptResource with an existing managed instance.
  49. */
  50. ScriptShader* createScriptShader(MonoObject* existingInstance, const HShader& resourceHandle);
  51. /**
  52. * @note Throws an exception if resource for the handle already exists.
  53. * Initializes the ScriptResource with an existing managed instance.
  54. */
  55. ScriptMaterial* createScriptMaterial(const HMaterial& resourceHandle);
  56. /**
  57. * @note Throws an exception if resource for the handle already exists.
  58. * Initializes the ScriptResource with an existing managed instance.
  59. */
  60. ScriptMaterial* createScriptMaterial(MonoObject* existingInstance, const HMaterial& resourceHandle);
  61. /**
  62. * @note Throws an exception if resource for the handle already exists.
  63. * Initializes the ScriptResource with an existing managed instance.
  64. */
  65. ScriptMesh* createScriptMesh(const HMesh& resourceHandle);
  66. /**
  67. * @note Throws an exception if resource for the handle already exists.
  68. * Initializes the ScriptResource with an existing managed instance.
  69. */
  70. ScriptMesh* createScriptMesh(MonoObject* existingInstance, const HMesh& resourceHandle);
  71. /**
  72. * @note Throws an exception if resource for the handle already exists.
  73. * Initializes the ScriptResource with an existing managed instance.
  74. */
  75. ScriptPlainText* createScriptPlainText(const HPlainText& resourceHandle);
  76. /**
  77. * @note Throws an exception if resource for the handle already exists.
  78. * Initializes the ScriptResource with an existing managed instance.
  79. */
  80. ScriptPlainText* createScriptPlainText(MonoObject* existingInstance, const HPlainText& resourceHandle);
  81. /**
  82. * @note Throws an exception if resource for the handle already exists.
  83. * Initializes the ScriptResource with an existing managed instance.
  84. */
  85. ScriptScriptCode* createScriptScriptCode(const HScriptCode& resourceHandle);
  86. /**
  87. * @note Throws an exception if resource for the handle already exists.
  88. * Initializes the ScriptResource with an existing managed instance.
  89. */
  90. ScriptScriptCode* createScriptScriptCode(MonoObject* existingInstance, const HScriptCode& resourceHandle);
  91. /**
  92. * @note Throws an exception if resource for the handle already exists.
  93. * Creates a new managed instance of the object.
  94. */
  95. ScriptSpriteTexture* createScriptSpriteTexture(const HSpriteTexture& resourceHandle);
  96. /**
  97. * @note Throws an exception if resource for the handle already exists.
  98. * Initializes the ScriptResource with an existing managed instance.
  99. */
  100. ScriptSpriteTexture* createScriptSpriteTexture(MonoObject* existingInstance, const HSpriteTexture& resourceHandle);
  101. /**
  102. * @note Throws an exception if resource for the handle already exists.
  103. * Creates a new managed instance of the object.
  104. */
  105. ScriptFont* createScriptFont(const HFont& resourceHandle);
  106. /**
  107. * @note Throws an exception if resource for the handle already exists.
  108. * Initializes the ScriptResource with an existing managed instance.
  109. */
  110. ScriptFont* createScriptFont(MonoObject* existingInstance, const HFont& resourceHandle);
  111. /**
  112. * @note Throws an exception if resource for the handle already exists.
  113. * Initializes the ScriptResource with an existing managed instance.
  114. */
  115. ScriptManagedResource* createManagedResource(MonoObject* existingInstance, const HManagedResource& resourceHandle);
  116. /**
  117. * @note Returns nullptr if script resource doesn't exist.
  118. */
  119. ScriptTexture2D* getScriptTexture2D(const HTexture& resourceHandle);
  120. /**
  121. * @note Returns nullptr if script resource doesn't exist.
  122. */
  123. ScriptTexture3D* getScriptTexture3D(const HTexture& resourceHandle);
  124. /**
  125. * @note Returns nullptr if script resource doesn't exist.
  126. */
  127. ScriptTextureCube* getScriptTextureCube(const HTexture& resourceHandle);
  128. /**
  129. * @note Returns nullptr if script resource doesn't exist.
  130. */
  131. ScriptShader* getScriptShader(const HShader& resourceHandle);
  132. /**
  133. * @note Returns nullptr if script resource doesn't exist.
  134. */
  135. ScriptMaterial* getScriptMaterial(const HMaterial& resourceHandle);
  136. /**
  137. * @note Returns nullptr if script resource doesn't exist.
  138. */
  139. ScriptMesh* getScriptMesh(const HMesh& resourceHandle);
  140. /**
  141. * @note Returns nullptr if script resource doesn't exist.
  142. */
  143. ScriptSpriteTexture* getScriptSpriteTexture(const HSpriteTexture& resourceHandle);
  144. /**
  145. * @note Returns nullptr if script resource doesn't exist.
  146. */
  147. ScriptPlainText* getScriptPlainText(const HPlainText& resourceHandle);
  148. /**
  149. * @note Returns nullptr if script resource doesn't exist.
  150. */
  151. ScriptScriptCode* getScriptScriptCode(const HScriptCode& resourceHandle);
  152. /**
  153. * @note Returns nullptr if script resource doesn't exist.
  154. */
  155. ScriptManagedResource* getScriptManagedResource(const HManagedResource& resourceHandle);
  156. /**
  157. * @note Returns nullptr if script resource doesn't exist.
  158. */
  159. ScriptResourceBase* getScriptResource(const String& UUID);
  160. /**
  161. * @note Returns nullptr if script resource doesn't exist.
  162. */
  163. ScriptResourceBase* createScriptResource(const HResource& resource);
  164. void destroyScriptResource(ScriptResourceBase* resource);
  165. private:
  166. UnorderedMap<String, ScriptResourceBase*> mScriptResources;
  167. void throwExceptionIfInvalidOrDuplicate(const String& uuid) const;
  168. };
  169. }