BsScriptResourceManager.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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. * Creates a new managed instance of the object.
  114. */
  115. ScriptPrefab* createScriptPrefab(const HPrefab& resourceHandle);
  116. /**
  117. * @note Throws an exception if resource for the handle already exists.
  118. * Initializes the ScriptResource with an existing managed instance.
  119. */
  120. ScriptPrefab* createScriptPrefab(MonoObject* existingInstance, const HPrefab& resourceHandle);
  121. /**
  122. * @note Throws an exception if resource for the handle already exists.
  123. * Initializes the ScriptResource with an existing managed instance.
  124. */
  125. ScriptManagedResource* createManagedResource(MonoObject* existingInstance, const HManagedResource& resourceHandle);
  126. /**
  127. * @note Returns nullptr if script resource doesn't exist.
  128. */
  129. ScriptTexture2D* getScriptTexture2D(const HTexture& resourceHandle);
  130. /**
  131. * @note Returns nullptr if script resource doesn't exist.
  132. */
  133. ScriptTexture3D* getScriptTexture3D(const HTexture& resourceHandle);
  134. /**
  135. * @note Returns nullptr if script resource doesn't exist.
  136. */
  137. ScriptTextureCube* getScriptTextureCube(const HTexture& resourceHandle);
  138. /**
  139. * @note Returns nullptr if script resource doesn't exist.
  140. */
  141. ScriptShader* getScriptShader(const HShader& resourceHandle);
  142. /**
  143. * @note Returns nullptr if script resource doesn't exist.
  144. */
  145. ScriptMaterial* getScriptMaterial(const HMaterial& resourceHandle);
  146. /**
  147. * @note Returns nullptr if script resource doesn't exist.
  148. */
  149. ScriptMesh* getScriptMesh(const HMesh& resourceHandle);
  150. /**
  151. * @note Returns nullptr if script resource doesn't exist.
  152. */
  153. ScriptSpriteTexture* getScriptSpriteTexture(const HSpriteTexture& resourceHandle);
  154. /**
  155. * @note Returns nullptr if script resource doesn't exist.
  156. */
  157. ScriptPlainText* getScriptPlainText(const HPlainText& resourceHandle);
  158. /**
  159. * @note Returns nullptr if script resource doesn't exist.
  160. */
  161. ScriptScriptCode* getScriptScriptCode(const HScriptCode& resourceHandle);
  162. /**
  163. * @note Returns nullptr if script resource doesn't exist.
  164. */
  165. ScriptManagedResource* getScriptManagedResource(const HManagedResource& resourceHandle);
  166. /**
  167. * @note Returns nullptr if script resource doesn't exist.
  168. */
  169. ScriptPrefab* getScriptPrefab(const HPrefab& resourceHandle);
  170. /**
  171. * @note Returns nullptr if script resource doesn't exist.
  172. */
  173. ScriptResourceBase* getScriptResource(const String& UUID);
  174. /**
  175. * @note Returns nullptr if script resource doesn't exist.
  176. */
  177. ScriptResourceBase* createScriptResource(const HResource& resource);
  178. void destroyScriptResource(ScriptResourceBase* resource);
  179. private:
  180. UnorderedMap<String, ScriptResourceBase*> mScriptResources;
  181. void throwExceptionIfInvalidOrDuplicate(const String& uuid) const;
  182. };
  183. }