BsScriptAssemblyManager.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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 "Serialization/BsManagedSerializableObjectInfo.h"
  6. #include "Utility/BsModule.h"
  7. namespace bs
  8. {
  9. struct BuiltinComponentInfo;
  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. SPtr<ManagedSerializableTypeInfo> getTypeInfo(MonoClass* monoClass);
  41. /**
  42. * Maps a mono type to information about a wrapped built-in component. Returns null if type doesn't correspond to
  43. * a builtin component.
  44. */
  45. BuiltinComponentInfo* getBuiltinComponentInfo(::MonoReflectionType* type);
  46. /**
  47. * Maps a type id to information about a wrapped built-in component. Returns null if type id doesn't correspond to
  48. * a builtin component.
  49. */
  50. BuiltinComponentInfo* getBuiltinComponentInfo(UINT32 rttiTypeId);
  51. /**
  52. * Maps a mono type to information about a wrapped built-in resource. Returns null if type doesn't correspond to
  53. * a builtin resource.
  54. */
  55. BuiltinResourceInfo* getBuiltinResourceInfo(::MonoReflectionType* type);
  56. /**
  57. * Maps a type id to information about a wrapped built-in resource. Returns null if type id doesn't correspond to
  58. * a builtin resource.
  59. */
  60. BuiltinResourceInfo* getBuiltinResourceInfo(UINT32 rttiTypeId);
  61. /**
  62. * Maps a resource type to information about a wrapped built-in resource. Returns null if type id doesn't correspond to
  63. * a builtin resource.
  64. */
  65. BuiltinResourceInfo* getBuiltinResourceInfo(ScriptResourceType type);
  66. /**
  67. * Checks if the managed serializable object info for the specified type exists.
  68. *
  69. * @param[in] ns Namespace of the type.
  70. * @param[in] typeName Name of the type.
  71. * @return True if the object info was found, false otherwise.
  72. */
  73. bool hasSerializableObjectInfo(const String& ns, const String& typeName);
  74. /** Returns names of all assemblies that currently have managed serializable object data loaded. */
  75. Vector<String> getScriptAssemblies() const;
  76. /** Gets the managed class for System.Array type. */
  77. MonoClass* getSystemArrayClass() const { return mSystemArrayClass; }
  78. /** Gets the managed class for System.Collections.Generic.List<T> type. */
  79. MonoClass* getSystemGenericListClass() const { return mSystemGenericListClass; }
  80. /** Gets the managed class for System.Collections.Generic.Dictionary<T,U> type. */
  81. MonoClass* getSystemGenericDictionaryClass() const { return mSystemGenericDictionaryClass; }
  82. /** Gets the managed class for System.Type type. */
  83. MonoClass* getSystemTypeClass() const { return mSystemTypeClass; }
  84. /** Gets the managed class for BansheeEngine.Component type. */
  85. MonoClass* getComponentClass() const { return mComponentClass; }
  86. /** Gets the managed class for BansheeEngine.ManagedComponent type. */
  87. MonoClass* getManagedComponentClass() const { return mManagedComponentClass; }
  88. /** Gets the managed class for BansheeEngine.MissingComponent type. */
  89. MonoClass* getMissingComponentClass() const { return mMissingComponentClass; }
  90. /** Gets the managed class for BansheeEngine.SceneObject type. */
  91. MonoClass* getSceneObjectClass() const { return mSceneObjectClass; }
  92. /** Gets the managed class for BansheeEngine.Range attribute */
  93. MonoClass* getRangeAttribute() const { return mRangeAttribute; }
  94. /** Gets the managed class for BansheeEngine.Step attribute */
  95. MonoClass* getStepAttribute() const { return mStepAttribute; }
  96. private:
  97. /** Deletes all stored managed serializable object infos for all assemblies. */
  98. void clearScriptObjects();
  99. /**
  100. * Initializes the base managed types. These are the types we expect must exist in loaded assemblies as they're used
  101. * for various common operations.
  102. */
  103. void initializeBaseTypes();
  104. /** Initializes information required for mapping builtin components to managed components. */
  105. void initializeBuiltinComponentInfos();
  106. /** Initializes information required for mapping builtin resources to managed resources. */
  107. void initializeBuiltinResourceInfos();
  108. UnorderedMap<String, SPtr<ManagedSerializableAssemblyInfo>> mAssemblyInfos;
  109. UnorderedMap<::MonoReflectionType*, BuiltinComponentInfo> mBuiltinComponentInfos;
  110. UnorderedMap<UINT32, BuiltinComponentInfo> mBuiltinComponentInfosByTID;
  111. UnorderedMap<::MonoReflectionType*, BuiltinResourceInfo> mBuiltinResourceInfos;
  112. UnorderedMap<UINT32, BuiltinResourceInfo> mBuiltinResourceInfosByTID;
  113. UnorderedMap<UINT32, BuiltinResourceInfo> mBuiltinResourceInfosByType;
  114. bool mBaseTypesInitialized;
  115. MonoClass* mSystemArrayClass;
  116. MonoClass* mSystemGenericListClass;
  117. MonoClass* mSystemGenericDictionaryClass;
  118. MonoClass* mSystemTypeClass;
  119. MonoClass* mComponentClass;
  120. MonoClass* mManagedComponentClass;
  121. MonoClass* mSceneObjectClass;
  122. MonoClass* mMissingComponentClass;
  123. MonoClass* mSerializeObjectAttribute;
  124. MonoClass* mDontSerializeFieldAttribute;
  125. MonoClass* mSerializeFieldAttribute;
  126. MonoClass* mHideInInspectorAttribute;
  127. MonoClass* mShowInInspectorAttribute;
  128. MonoClass* mRangeAttribute;
  129. MonoClass* mStepAttribute;
  130. };
  131. /** @} */
  132. }