BsScriptAssemblyManager.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. #pragma once
  2. #include "BsScriptEnginePrerequisites.h"
  3. #include "BsManagedSerializableObjectInfo.h"
  4. #include "BsModule.h"
  5. #include <mono/jit/jit.h>
  6. namespace BansheeEngine
  7. {
  8. /**
  9. * @brief Stores data about managed serializable objects in specified assemblies.
  10. */
  11. class BS_SCR_BE_EXPORT ScriptAssemblyManager : public Module<ScriptAssemblyManager>
  12. {
  13. public:
  14. ScriptAssemblyManager();
  15. ~ScriptAssemblyManager();
  16. /**
  17. * @brief Loads all information about managed serializable objects in an assembly with the specified name.
  18. * Assembly must be currently loaded. Once the data has been loaded you will be able to call
  19. * ::getSerializableObjectInfo and ::hasSerializableObjectInfo to retrieve information about
  20. * those objects. If an assembly already had data loaded it will be rebuilt.
  21. */
  22. void loadAssemblyInfo(const String& assemblyName);
  23. /**
  24. * @brief Clears any assembly data previously loaded with ::loadAssemblyInfo.
  25. */
  26. void clearAssemblyInfo();
  27. /**
  28. * @brief Returns managed serializable object info for a specific managed type.
  29. *
  30. * @param ns Namespace of the type.
  31. * @param typeName Name of the type.
  32. * @param outInfo Output object containing information about the type if the type was found, unmodified otherwise.
  33. *
  34. * @return True if the type was found, false otherwise.
  35. */
  36. bool getSerializableObjectInfo(const String& ns, const String& typeName, std::shared_ptr<ManagedSerializableObjectInfo>& outInfo);
  37. /**
  38. * @brief Checks if the managed serializable object info for the specified type exists.
  39. *
  40. * @param ns Namespace of the type.
  41. * @param typeName Name of the type.
  42. *
  43. * @return True if the object info was found, false otherwise.
  44. */
  45. bool hasSerializableObjectInfo(const String& ns, const String& typeName);
  46. /**
  47. * @brief Returns names of all assemblies that currently have managed serializable object
  48. * data loaded.
  49. */
  50. Vector<String> getScriptAssemblies() const;
  51. /**
  52. * @brief Gets the managed class for System.Array type.
  53. */
  54. MonoClass* getSystemArrayClass() const { return mSystemArrayClass; }
  55. /**
  56. * @brief Gets the managed class for System.Collections.Generic.List<T> type.
  57. */
  58. MonoClass* getSystemGenericListClass() const { return mSystemGenericListClass; }
  59. /**
  60. * @brief Gets the managed class for System.Collections.Generic.Dictionary<T,U> type.
  61. */
  62. MonoClass* getSystemGenericDictionaryClass() const { return mSystemGenericDictionaryClass; }
  63. /**
  64. * @brief Gets the managed class for System.Type type.
  65. */
  66. MonoClass* getSystemTypeClass() const { return mSystemTypeClass; }
  67. /**
  68. * @brief Gets the managed class for BansheeEngine.Component type.
  69. */
  70. MonoClass* getComponentClass() const { return mComponentClass; }
  71. /**
  72. * @brief Gets the managed class for BansheeEngine.MissingComponent type.
  73. */
  74. MonoClass* getMissingComponentClass() const { return mMissingComponentClass; }
  75. /**
  76. * @brief Gets the managed class for BansheeEngine.SceneObject type.
  77. */
  78. MonoClass* getSceneObjectClass() const { return mSceneObjectClass; }
  79. /**
  80. * @brief Generates or retrieves a type info object for the specified managed class,
  81. * if the class is serializable.
  82. */
  83. ManagedSerializableTypeInfoPtr determineType(MonoClass* monoClass);
  84. private:
  85. /**
  86. * @brief Deletes all stored managed serializable object infos for all assemblies.
  87. */
  88. void clearScriptObjects();
  89. /**
  90. * @brief Initializes the base managed types. These are the types we expect must
  91. * exist in loaded assemblies as they're used for various common operations.
  92. */
  93. void initializeBaseTypes();
  94. UnorderedMap<String, std::shared_ptr<ManagedSerializableAssemblyInfo>> mAssemblyInfos;
  95. bool mBaseTypesInitialized;
  96. MonoClass* mSystemArrayClass;
  97. MonoClass* mSystemGenericListClass;
  98. MonoClass* mSystemGenericDictionaryClass;
  99. MonoClass* mSystemTypeClass;
  100. MonoClass* mComponentClass;
  101. MonoClass* mSceneObjectClass;
  102. MonoClass* mMissingComponentClass;
  103. MonoClass* mSerializeObjectAttribute;
  104. MonoClass* mDontSerializeFieldAttribute;
  105. MonoClass* mSerializeFieldAttribute;
  106. MonoClass* mHideInInspectorAttribute;
  107. };
  108. }