BsScriptAssemblyManager.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. /** Contains all the built-in script classes that are always available. */
  14. struct BuiltinScriptClasses
  15. {
  16. MonoClass* systemArrayClass = nullptr;
  17. MonoClass* systemGenericListClass = nullptr;
  18. MonoClass* systemGenericDictionaryClass = nullptr;
  19. MonoClass* systemTypeClass = nullptr;
  20. MonoClass* componentClass = nullptr;
  21. MonoClass* managedComponentClass = nullptr;
  22. MonoClass* sceneObjectClass = nullptr;
  23. MonoClass* missingComponentClass = nullptr;
  24. MonoClass* rrefBaseClass = nullptr;
  25. MonoClass* genericRRefClass = nullptr;
  26. MonoClass* serializeObjectAttribute = nullptr;
  27. MonoClass* dontSerializeFieldAttribute = nullptr;
  28. MonoClass* serializeFieldAttribute = nullptr;
  29. MonoClass* hideInInspectorAttribute = nullptr;
  30. MonoClass* showInInspectorAttribute = nullptr;
  31. MonoClass* rangeAttribute = nullptr;
  32. MonoClass* stepAttribute = nullptr;
  33. MonoClass* layerMaskAttribute = nullptr;
  34. MonoClass* nativeWrapperAttribute = nullptr;
  35. MonoClass* notNullAttribute = nullptr;
  36. MonoClass* passByCopyAttribute = nullptr;
  37. MonoClass* applyOnDirtyAttribute = nullptr;
  38. };
  39. /** Stores data about managed serializable objects in specified assemblies. */
  40. class BS_SCR_BE_EXPORT ScriptAssemblyManager : public Module<ScriptAssemblyManager>
  41. {
  42. public:
  43. /**
  44. * Loads all information about managed serializable objects in an assembly with the specified name. Assembly must be
  45. * currently loaded. Once the data has been loaded you will be able to call getSerializableObjectInfo() and
  46. * hasSerializableObjectInfo() to retrieve information about those objects. If an assembly already had data loaded
  47. * it will be rebuilt.
  48. */
  49. void loadAssemblyInfo(const String& assemblyName);
  50. /** Clears any assembly data previously loaded with loadAssemblyInfo(). */
  51. void clearAssemblyInfo();
  52. /**
  53. * Returns managed serializable object info for a specific managed type.
  54. *
  55. * @param[in] ns Namespace of the type.
  56. * @param[in] typeName Name of the type.
  57. * @param[out] outInfo Output object containing information about the type if the type was found, unmodified
  58. * otherwise.
  59. * @return True if the type was found, false otherwise.
  60. */
  61. bool getSerializableObjectInfo(const String& ns, const String& typeName,
  62. SPtr<ManagedSerializableObjectInfo>& outInfo);
  63. /** Generates or retrieves a type info object for the specified managed class, if the class is serializable. */
  64. SPtr<ManagedSerializableTypeInfo> getTypeInfo(MonoClass* monoClass);
  65. /**
  66. * Maps a mono type to information about a wrapped built-in component. Returns null if type doesn't correspond to
  67. * a builtin component.
  68. */
  69. BuiltinComponentInfo* getBuiltinComponentInfo(::MonoReflectionType* type);
  70. /**
  71. * Maps a type id to information about a wrapped built-in component. Returns null if type id doesn't correspond to
  72. * a builtin component.
  73. */
  74. BuiltinComponentInfo* getBuiltinComponentInfo(UINT32 rttiTypeId);
  75. /**
  76. * Maps a mono type to information about a wrapped built-in resource. Returns null if type doesn't correspond to
  77. * a builtin resource.
  78. */
  79. BuiltinResourceInfo* getBuiltinResourceInfo(::MonoReflectionType* type);
  80. /**
  81. * Maps a type id to information about a wrapped built-in resource. Returns null if type id doesn't correspond to
  82. * a builtin resource.
  83. */
  84. BuiltinResourceInfo* getBuiltinResourceInfo(UINT32 rttiTypeId);
  85. /**
  86. * Maps a resource type to information about a wrapped built-in resource. Returns null if type id doesn't correspond to
  87. * a builtin resource.
  88. */
  89. BuiltinResourceInfo* getBuiltinResourceInfo(ScriptResourceType type);
  90. /**
  91. * Checks if the managed serializable object info for the specified type exists.
  92. *
  93. * @param[in] ns Namespace of the type.
  94. * @param[in] typeName Name of the type.
  95. * @return True if the object info was found, false otherwise.
  96. */
  97. bool hasSerializableObjectInfo(const String& ns, const String& typeName);
  98. /** Returns names of all assemblies that currently have managed serializable object data loaded. */
  99. Vector<String> getScriptAssemblies() const;
  100. /** Returns type information for various built-in classes. */
  101. const BuiltinScriptClasses& getBuiltinClasses() const { return mBuiltin; }
  102. private:
  103. /** Deletes all stored managed serializable object infos for all assemblies. */
  104. void clearScriptObjects();
  105. /**
  106. * Initializes the base managed types. These are the types we expect must exist in loaded assemblies as they're used
  107. * for various common operations.
  108. */
  109. void initializeBaseTypes();
  110. /** Initializes information required for mapping builtin components to managed components. */
  111. void initializeBuiltinComponentInfos();
  112. /** Initializes information required for mapping builtin resources to managed resources. */
  113. void initializeBuiltinResourceInfos();
  114. UnorderedMap<String, SPtr<ManagedSerializableAssemblyInfo>> mAssemblyInfos;
  115. UnorderedMap<::MonoReflectionType*, BuiltinComponentInfo> mBuiltinComponentInfos;
  116. UnorderedMap<UINT32, BuiltinComponentInfo> mBuiltinComponentInfosByTID;
  117. UnorderedMap<::MonoReflectionType*, BuiltinResourceInfo> mBuiltinResourceInfos;
  118. UnorderedMap<UINT32, BuiltinResourceInfo> mBuiltinResourceInfosByTID;
  119. UnorderedMap<UINT32, BuiltinResourceInfo> mBuiltinResourceInfosByType;
  120. bool mBaseTypesInitialized = false;
  121. BuiltinScriptClasses mBuiltin;
  122. };
  123. /** @} */
  124. }