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 Generates or retrieves a type info object for the specified managed class,
  39. * if the class is serializable.
  40. */
  41. ManagedSerializableTypeInfoPtr getTypeInfo(MonoClass* monoClass);
  42. /**
  43. * @brief Checks if the managed serializable object info for the specified type exists.
  44. *
  45. * @param ns Namespace of the type.
  46. * @param typeName Name of the type.
  47. *
  48. * @return True if the object info was found, false otherwise.
  49. */
  50. bool hasSerializableObjectInfo(const String& ns, const String& typeName);
  51. /**
  52. * @brief Returns names of all assemblies that currently have managed serializable object
  53. * data loaded.
  54. */
  55. Vector<String> getScriptAssemblies() const;
  56. /**
  57. * @brief Gets the managed class for System.Array type.
  58. */
  59. MonoClass* getSystemArrayClass() const { return mSystemArrayClass; }
  60. /**
  61. * @brief Gets the managed class for System.Collections.Generic.List<T> type.
  62. */
  63. MonoClass* getSystemGenericListClass() const { return mSystemGenericListClass; }
  64. /**
  65. * @brief Gets the managed class for System.Collections.Generic.Dictionary<T,U> type.
  66. */
  67. MonoClass* getSystemGenericDictionaryClass() const { return mSystemGenericDictionaryClass; }
  68. /**
  69. * @brief Gets the managed class for System.Type type.
  70. */
  71. MonoClass* getSystemTypeClass() const { return mSystemTypeClass; }
  72. /**
  73. * @brief Gets the managed class for BansheeEngine.Component type.
  74. */
  75. MonoClass* getComponentClass() const { return mComponentClass; }
  76. /**
  77. * @brief Gets the managed class for BansheeEngine.MissingComponent type.
  78. */
  79. MonoClass* getMissingComponentClass() const { return mMissingComponentClass; }
  80. /**
  81. * @brief Gets the managed class for BansheeEngine.SceneObject type.
  82. */
  83. MonoClass* getSceneObjectClass() const { return mSceneObjectClass; }
  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. }