BsScriptAssemblyManager.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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 "BsManagedSerializableObjectInfo.h"
  6. #include "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. * Checks if the managed serializable object info for the specified type exists.
  53. *
  54. * @param[in] ns Namespace of the type.
  55. * @param[in] typeName Name of the type.
  56. * @return True if the object info was found, false otherwise.
  57. */
  58. bool hasSerializableObjectInfo(const String& ns, const String& typeName);
  59. /** Returns names of all assemblies that currently have managed serializable object data loaded. */
  60. Vector<String> getScriptAssemblies() const;
  61. /** Gets the managed class for System.Array type. */
  62. MonoClass* getSystemArrayClass() const { return mSystemArrayClass; }
  63. /** Gets the managed class for System.Collections.Generic.List<T> type. */
  64. MonoClass* getSystemGenericListClass() const { return mSystemGenericListClass; }
  65. /** Gets the managed class for System.Collections.Generic.Dictionary<T,U> type. */
  66. MonoClass* getSystemGenericDictionaryClass() const { return mSystemGenericDictionaryClass; }
  67. /** Gets the managed class for System.Type type. */
  68. MonoClass* getSystemTypeClass() const { return mSystemTypeClass; }
  69. /** Gets the managed class for BansheeEngine.Component type. */
  70. MonoClass* getComponentClass() const { return mComponentClass; }
  71. /** Gets the managed class for BansheeEngine.ManagedComponent type. */
  72. MonoClass* getManagedComponentClass() const { return mManagedComponentClass; }
  73. /** Gets the managed class for BansheeEngine.MissingComponent type. */
  74. MonoClass* getMissingComponentClass() const { return mMissingComponentClass; }
  75. /** Gets the managed class for BansheeEngine.SceneObject type. */
  76. MonoClass* getSceneObjectClass() const { return mSceneObjectClass; }
  77. /** Gets the managed class for BansheeEngine.Range attribute */
  78. MonoClass* getRangeAttribute() const { return mRangeAttribute; }
  79. /** Gets the managed class for BansheeEngine.Step attribute */
  80. MonoClass* getStepAttribute() const { return mStepAttribute; }
  81. private:
  82. /** Deletes all stored managed serializable object infos for all assemblies. */
  83. void clearScriptObjects();
  84. /**
  85. * Initializes the base managed types. These are the types we expect must exist in loaded assemblies as they're used
  86. * for various common operations.
  87. */
  88. void initializeBaseTypes();
  89. /** Initializes information required for mapping builtin components to managed components. */
  90. void initializeBuiltinComponentInfos();
  91. UnorderedMap<String, SPtr<ManagedSerializableAssemblyInfo>> mAssemblyInfos;
  92. UnorderedMap<::MonoReflectionType*, BuiltinComponentInfo> mBuiltinComponentInfos;
  93. UnorderedMap<UINT32, BuiltinComponentInfo> mBuiltinComponentInfosByTID;
  94. bool mBaseTypesInitialized;
  95. MonoClass* mSystemArrayClass;
  96. MonoClass* mSystemGenericListClass;
  97. MonoClass* mSystemGenericDictionaryClass;
  98. MonoClass* mSystemTypeClass;
  99. MonoClass* mComponentClass;
  100. MonoClass* mManagedComponentClass;
  101. MonoClass* mSceneObjectClass;
  102. MonoClass* mMissingComponentClass;
  103. MonoClass* mSerializeObjectAttribute;
  104. MonoClass* mDontSerializeFieldAttribute;
  105. MonoClass* mSerializeFieldAttribute;
  106. MonoClass* mHideInInspectorAttribute;
  107. MonoClass* mShowInInspectorAttribute;
  108. MonoClass* mRangeAttribute;
  109. MonoClass* mStepAttribute;
  110. };
  111. /** @} */
  112. }