BsScriptAssemblyManager.h 5.6 KB

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