BsScriptAssemblyManager.h 4.3 KB

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