BsScriptAssemblyManager.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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 Reloads assembly data for all assemblies that were previously loaded using
  25. * ::loadAssemblyInfo. Useful for quickly updating all data after an assembly reload.
  26. */
  27. void refreshAssemblyInfo();
  28. /**
  29. * @brief Returns managed serializable object info for a specific managed type.
  30. *
  31. * @param ns Namespace of the type.
  32. * @param typeName Name of the type.
  33. * @param outInfo Output object containing information about the type if the type was found, unmodified otherwise.
  34. *
  35. * @return True if the type was found, false otherwise.
  36. */
  37. bool getSerializableObjectInfo(const String& ns, const String& typeName, std::shared_ptr<ManagedSerializableObjectInfo>& outInfo);
  38. /**
  39. * @brief Checks if the managed serializable object info for the specified type exists.
  40. *
  41. * @param ns Namespace of the type.
  42. * @param typeName Name of the type.
  43. *
  44. * @return True if the object info was found, false otherwise.
  45. */
  46. bool hasSerializableObjectInfo(const String& ns, const String& typeName);
  47. /**
  48. * @brief Returns names of all assemblies that currently have managed serializable object
  49. * data loaded.
  50. */
  51. Vector<String> getScriptAssemblies() const;
  52. /**
  53. * @brief Gets the managed class for System.Array type.
  54. */
  55. MonoClass* getSystemArrayClass() const { return mSystemArrayClass; }
  56. /**
  57. * @brief Gets the managed class for System.Collections.Generic.List<T> type.
  58. */
  59. MonoClass* getSystemGenericListClass() const { return mSystemGenericListClass; }
  60. /**
  61. * @brief Gets the managed class for System.Collections.Generic.Dictionary<T,U> type.
  62. */
  63. MonoClass* getSystemGenericDictionaryClass() const { return mSystemGenericDictionaryClass; }
  64. /**
  65. * @brief Gets the managed class for System.Type type.
  66. */
  67. MonoClass* getSystemTypeClass() const { return mSystemTypeClass; }
  68. /**
  69. * @brief Gets the managed class for BansheeEngine.Component type.
  70. */
  71. MonoClass* getComponentClass() const { return mComponentClass; }
  72. /**
  73. * @brief Gets the managed class for BansheeEngine.MissingComponent type.
  74. */
  75. MonoClass* getMissingComponentClass() const { return mMissingComponentClass; }
  76. /**
  77. * @brief Gets the managed class for BansheeEngine.SceneObject type.
  78. */
  79. MonoClass* getSceneObjectClass() const { return mSceneObjectClass; }
  80. /**
  81. * @brief Generates or retrieves a type info object for the specified managed class,
  82. * if the class is serializable.
  83. */
  84. ManagedSerializableTypeInfoPtr determineType(MonoClass* monoClass);
  85. private:
  86. /**
  87. * @brief Deletes all stored managed serializable object infos for all assemblies.
  88. */
  89. void clearScriptObjects();
  90. /**
  91. * @brief Initializes the base managed types. These are the types we expect must
  92. * exist in loaded assemblies as they're used for various common operations.
  93. */
  94. void initializeBaseTypes();
  95. UnorderedMap<String, std::shared_ptr<ManagedSerializableAssemblyInfo>> mAssemblyInfos;
  96. bool mBaseTypesInitialized;
  97. MonoClass* mSystemArrayClass;
  98. MonoClass* mSystemGenericListClass;
  99. MonoClass* mSystemGenericDictionaryClass;
  100. MonoClass* mSystemTypeClass;
  101. MonoClass* mComponentClass;
  102. MonoClass* mSceneObjectClass;
  103. MonoClass* mMissingComponentClass;
  104. MonoClass* mSerializeObjectAttribute;
  105. MonoClass* mDontSerializeFieldAttribute;
  106. MonoClass* mSerializeFieldAttribute;
  107. MonoClass* mHideInInspectorAttribute;
  108. };
  109. }