BsScriptAssemblyManager.h 5.8 KB

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