BsScriptAssemblyManager.h 5.6 KB

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