BsScriptAssemblyManager.h 4.5 KB

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