BsScriptAssemblyManager.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557
  1. #include "BsScriptAssemblyManager.h"
  2. #include "BsScriptResourceManager.h"
  3. #include "BsScriptGameObjectManager.h"
  4. #include "BsManagedSerializableObjectInfo.h"
  5. #include "BsMonoManager.h"
  6. #include "BsMonoAssembly.h"
  7. #include "BsMonoClass.h"
  8. #include "BsMonoField.h"
  9. #include "BsMonoMethod.h"
  10. #include "BsMonoProperty.h"
  11. #include "BsScriptManagedResource.h"
  12. #include "BsScriptTexture2D.h"
  13. #include "BsScriptTexture3D.h"
  14. #include "BsScriptTextureCube.h"
  15. #include "BsScriptSpriteTexture.h"
  16. #include "BsScriptMaterial.h"
  17. #include "BsScriptMesh.h"
  18. #include "BsScriptFont.h"
  19. #include "BsScriptShader.h"
  20. #include "BsScriptPlainText.h"
  21. #include "BsScriptScriptCode.h"
  22. #include "BsScriptStringTable.h"
  23. #include "BsScriptGUISkin.h"
  24. #include "BsScriptPrefab.h"
  25. #include "BsMonoUtil.h"
  26. #include "BsRTTIType.h"
  27. namespace BansheeEngine
  28. {
  29. ScriptAssemblyManager::ScriptAssemblyManager()
  30. :mBaseTypesInitialized(false), mSerializeObjectAttribute(nullptr), mDontSerializeFieldAttribute(nullptr),
  31. mComponentClass(nullptr), mSceneObjectClass(nullptr), mSerializeFieldAttribute(nullptr), mHideInInspectorAttribute(nullptr),
  32. mSystemArrayClass(nullptr), mSystemGenericListClass(nullptr), mSystemGenericDictionaryClass(nullptr), mMissingComponentClass(nullptr),
  33. mSystemTypeClass(nullptr)
  34. {
  35. }
  36. ScriptAssemblyManager::~ScriptAssemblyManager()
  37. {
  38. }
  39. Vector<String> ScriptAssemblyManager::getScriptAssemblies() const
  40. {
  41. Vector<String> initializedAssemblies;
  42. for (auto& assemblyPair : mAssemblyInfos)
  43. initializedAssemblies.push_back(assemblyPair.first);
  44. return initializedAssemblies;
  45. }
  46. void ScriptAssemblyManager::loadAssemblyInfo(const String& assemblyName)
  47. {
  48. if(!mBaseTypesInitialized)
  49. initializeBaseTypes();
  50. // Process all classes and fields
  51. UINT32 mUniqueTypeId = 1;
  52. MonoAssembly* curAssembly = MonoManager::instance().getAssembly(assemblyName);
  53. if(curAssembly == nullptr)
  54. return;
  55. std::shared_ptr<ManagedSerializableAssemblyInfo> assemblyInfo = bs_shared_ptr_new<ManagedSerializableAssemblyInfo>();
  56. assemblyInfo->mName = assemblyName;
  57. mAssemblyInfos[assemblyName] = assemblyInfo;
  58. MonoClass* managedResourceClass = ScriptManagedResource::getMetaData()->scriptClass;
  59. // Populate class data
  60. const Vector<MonoClass*>& allClasses = curAssembly->getAllClasses();
  61. for(auto& curClass : allClasses)
  62. {
  63. if ((curClass->isSubClassOf(mComponentClass) || curClass->isSubClassOf(managedResourceClass) ||
  64. curClass->hasAttribute(mSerializeObjectAttribute)) && curClass != mComponentClass && curClass != managedResourceClass)
  65. {
  66. std::shared_ptr<ManagedSerializableTypeInfoObject> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoObject>();
  67. typeInfo->mTypeNamespace = curClass->getNamespace();
  68. typeInfo->mTypeName = curClass->getTypeName();
  69. typeInfo->mTypeId = mUniqueTypeId++;
  70. MonoType* monoType = mono_class_get_type(curClass->_getInternalClass());
  71. int monoPrimitiveType = mono_type_get_type(monoType);
  72. if(monoPrimitiveType == MONO_TYPE_VALUETYPE)
  73. typeInfo->mValueType = true;
  74. else
  75. typeInfo->mValueType = false;
  76. std::shared_ptr<ManagedSerializableObjectInfo> objInfo = bs_shared_ptr_new<ManagedSerializableObjectInfo>();
  77. objInfo->mTypeInfo = typeInfo;
  78. objInfo->mMonoClass = curClass;
  79. assemblyInfo->mTypeNameToId[objInfo->getFullTypeName()] = typeInfo->mTypeId;
  80. assemblyInfo->mObjectInfos[typeInfo->mTypeId] = objInfo;
  81. }
  82. }
  83. // Populate field data
  84. for(auto& curClassInfo : assemblyInfo->mObjectInfos)
  85. {
  86. std::shared_ptr<ManagedSerializableObjectInfo> objInfo = curClassInfo.second;
  87. UINT32 mUniqueFieldId = 1;
  88. const Vector<MonoField*>& fields = objInfo->mMonoClass->getAllFields();
  89. for(auto& field : fields)
  90. {
  91. if(field->isStatic())
  92. continue;
  93. ManagedSerializableTypeInfoPtr typeInfo = determineType(field->getType());
  94. if (typeInfo == nullptr)
  95. continue;
  96. std::shared_ptr<ManagedSerializableFieldInfo> fieldInfo = bs_shared_ptr_new<ManagedSerializableFieldInfo>();
  97. fieldInfo->mFieldId = mUniqueFieldId++;
  98. fieldInfo->mName = field->getName();
  99. fieldInfo->mMonoField = field;
  100. fieldInfo->mTypeInfo = typeInfo;
  101. fieldInfo->mParentTypeId = objInfo->mTypeInfo->mTypeId;
  102. MonoFieldVisibility visibility = field->getVisibility();
  103. if (visibility == MonoFieldVisibility::Public)
  104. {
  105. if (!field->hasAttribute(mDontSerializeFieldAttribute))
  106. fieldInfo->mFlags = (ScriptFieldFlags)((UINT32)fieldInfo->mFlags | (UINT32)ScriptFieldFlags::Serializable);
  107. if (!field->hasAttribute(mHideInInspectorAttribute))
  108. fieldInfo->mFlags = (ScriptFieldFlags)((UINT32)fieldInfo->mFlags | (UINT32)ScriptFieldFlags::Inspectable);
  109. }
  110. else
  111. {
  112. if (field->hasAttribute(mSerializeFieldAttribute))
  113. fieldInfo->mFlags = (ScriptFieldFlags)((UINT32)fieldInfo->mFlags | (UINT32)ScriptFieldFlags::Serializable);
  114. }
  115. objInfo->mFieldNameToId[fieldInfo->mName] = fieldInfo->mFieldId;
  116. objInfo->mFields[fieldInfo->mFieldId] = fieldInfo;
  117. }
  118. }
  119. // Form parent/child connections
  120. for(auto& curClass : assemblyInfo->mObjectInfos)
  121. {
  122. MonoClass* base = curClass.second->mMonoClass->getBaseClass();
  123. while(base != nullptr)
  124. {
  125. std::shared_ptr<ManagedSerializableObjectInfo> baseObjInfo;
  126. if(getSerializableObjectInfo(base->getNamespace(), base->getTypeName(), baseObjInfo))
  127. {
  128. curClass.second->mBaseClass = baseObjInfo;
  129. baseObjInfo->mDerivedClasses.push_back(curClass.second);
  130. break;
  131. }
  132. base = base->getBaseClass();
  133. }
  134. }
  135. }
  136. void ScriptAssemblyManager::refreshAssemblyInfo()
  137. {
  138. for (auto& assemblyInfoEntry : mAssemblyInfos)
  139. assemblyInfoEntry.second = nullptr;
  140. clearScriptObjects();
  141. for (auto& assemblyInfoEntry : mAssemblyInfos)
  142. {
  143. loadAssemblyInfo(assemblyInfoEntry.first);
  144. }
  145. }
  146. ManagedSerializableTypeInfoPtr ScriptAssemblyManager::determineType(MonoClass* monoClass)
  147. {
  148. if(!mBaseTypesInitialized)
  149. BS_EXCEPT(InvalidStateException, "Calling determineType without previously initializing base types.");
  150. MonoType* monoType = mono_class_get_type(monoClass->_getInternalClass());
  151. int monoPrimitiveType = mono_type_get_type(monoType);
  152. // If enum get the enum base data type
  153. bool isEnum = mono_class_is_enum(monoClass->_getInternalClass()) == 1;
  154. if (isEnum)
  155. {
  156. MonoType* underlyingType = mono_type_get_underlying_type(monoType);
  157. monoPrimitiveType = mono_type_get_type(underlyingType);
  158. }
  159. // Determine field type
  160. switch(monoPrimitiveType)
  161. {
  162. case MONO_TYPE_BOOLEAN:
  163. {
  164. std::shared_ptr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>();
  165. typeInfo->mType = ScriptPrimitiveType::Bool;
  166. return typeInfo;
  167. }
  168. case MONO_TYPE_CHAR:
  169. {
  170. std::shared_ptr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>();
  171. typeInfo->mType = ScriptPrimitiveType::Char;
  172. return typeInfo;
  173. }
  174. case MONO_TYPE_I1:
  175. {
  176. std::shared_ptr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>();
  177. typeInfo->mType = ScriptPrimitiveType::I8;
  178. return typeInfo;
  179. }
  180. case MONO_TYPE_U1:
  181. {
  182. std::shared_ptr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>();
  183. typeInfo->mType = ScriptPrimitiveType::U8;
  184. return typeInfo;
  185. }
  186. case MONO_TYPE_I2:
  187. {
  188. std::shared_ptr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>();
  189. typeInfo->mType = ScriptPrimitiveType::I16;
  190. return typeInfo;
  191. }
  192. case MONO_TYPE_U2:
  193. {
  194. std::shared_ptr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>();
  195. typeInfo->mType = ScriptPrimitiveType::U16;
  196. return typeInfo;
  197. }
  198. case MONO_TYPE_I4:
  199. {
  200. std::shared_ptr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>();
  201. typeInfo->mType = ScriptPrimitiveType::I32;
  202. return typeInfo;
  203. }
  204. case MONO_TYPE_U4:
  205. {
  206. std::shared_ptr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>();
  207. typeInfo->mType = ScriptPrimitiveType::U32;
  208. return typeInfo;
  209. }
  210. case MONO_TYPE_I8:
  211. {
  212. std::shared_ptr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>();
  213. typeInfo->mType = ScriptPrimitiveType::I64;
  214. return typeInfo;
  215. }
  216. case MONO_TYPE_U8:
  217. {
  218. std::shared_ptr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>();
  219. typeInfo->mType = ScriptPrimitiveType::U64;
  220. return typeInfo;
  221. }
  222. case MONO_TYPE_STRING:
  223. {
  224. std::shared_ptr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>();
  225. typeInfo->mType = ScriptPrimitiveType::String;
  226. return typeInfo;
  227. }
  228. case MONO_TYPE_R4:
  229. {
  230. std::shared_ptr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>();
  231. typeInfo->mType = ScriptPrimitiveType::Float;
  232. return typeInfo;
  233. }
  234. case MONO_TYPE_R8:
  235. {
  236. std::shared_ptr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>();
  237. typeInfo->mType = ScriptPrimitiveType::Double;
  238. return typeInfo;
  239. }
  240. case MONO_TYPE_CLASS:
  241. if(monoClass->isSubClassOf(ScriptTexture2D::getMetaData()->scriptClass))
  242. {
  243. std::shared_ptr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>();
  244. typeInfo->mType = ScriptPrimitiveType::Texture2DRef;
  245. return typeInfo;
  246. }
  247. if (monoClass->isSubClassOf(ScriptTexture3D::getMetaData()->scriptClass))
  248. {
  249. std::shared_ptr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>();
  250. typeInfo->mType = ScriptPrimitiveType::Texture3DRef;
  251. return typeInfo;
  252. }
  253. if (monoClass->isSubClassOf(ScriptTextureCube::getMetaData()->scriptClass))
  254. {
  255. std::shared_ptr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>();
  256. typeInfo->mType = ScriptPrimitiveType::TextureCubeRef;
  257. return typeInfo;
  258. }
  259. else if (monoClass->isSubClassOf(ScriptSpriteTexture::getMetaData()->scriptClass))
  260. {
  261. std::shared_ptr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>();
  262. typeInfo->mType = ScriptPrimitiveType::SpriteTextureRef;
  263. return typeInfo;
  264. }
  265. else if (monoClass->isSubClassOf(ScriptManagedResource::getMetaData()->scriptClass))
  266. {
  267. std::shared_ptr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>();
  268. typeInfo->mType = ScriptPrimitiveType::ManagedResourceRef;
  269. return typeInfo;
  270. }
  271. else if (monoClass->isSubClassOf(ScriptShader::getMetaData()->scriptClass))
  272. {
  273. std::shared_ptr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>();
  274. typeInfo->mType = ScriptPrimitiveType::ShaderRef;
  275. return typeInfo;
  276. }
  277. else if (monoClass->isSubClassOf(ScriptMaterial::getMetaData()->scriptClass))
  278. {
  279. std::shared_ptr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>();
  280. typeInfo->mType = ScriptPrimitiveType::MaterialRef;
  281. return typeInfo;
  282. }
  283. else if (monoClass->isSubClassOf(ScriptMesh::getMetaData()->scriptClass))
  284. {
  285. std::shared_ptr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>();
  286. typeInfo->mType = ScriptPrimitiveType::MeshRef;
  287. return typeInfo;
  288. }
  289. else if (monoClass->isSubClassOf(ScriptPlainText::getMetaData()->scriptClass))
  290. {
  291. std::shared_ptr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>();
  292. typeInfo->mType = ScriptPrimitiveType::PlainTextRef;
  293. return typeInfo;
  294. }
  295. else if (monoClass->isSubClassOf(ScriptScriptCode::getMetaData()->scriptClass))
  296. {
  297. std::shared_ptr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>();
  298. typeInfo->mType = ScriptPrimitiveType::ScriptCodeRef;
  299. return typeInfo;
  300. }
  301. else if (monoClass->isSubClassOf(ScriptPrefab::getMetaData()->scriptClass))
  302. {
  303. std::shared_ptr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>();
  304. typeInfo->mType = ScriptPrimitiveType::PrefabRef;
  305. return typeInfo;
  306. }
  307. else if (monoClass->isSubClassOf(ScriptFont::getMetaData()->scriptClass))
  308. {
  309. std::shared_ptr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>();
  310. typeInfo->mType = ScriptPrimitiveType::FontRef;
  311. return typeInfo;
  312. }
  313. else if (monoClass->isSubClassOf(ScriptStringTable::getMetaData()->scriptClass))
  314. {
  315. std::shared_ptr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>();
  316. typeInfo->mType = ScriptPrimitiveType::StringTableRef;
  317. return typeInfo;
  318. }
  319. else if (monoClass->isSubClassOf(ScriptGUISkin::getMetaData()->scriptClass))
  320. {
  321. std::shared_ptr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>();
  322. typeInfo->mType = ScriptPrimitiveType::GUISkinRef;
  323. return typeInfo;
  324. }
  325. else if(monoClass->isSubClassOf(mSceneObjectClass))
  326. {
  327. std::shared_ptr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>();
  328. typeInfo->mType = ScriptPrimitiveType::SceneObjectRef;
  329. return typeInfo;
  330. }
  331. else if(monoClass->isSubClassOf(mComponentClass))
  332. {
  333. std::shared_ptr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>();
  334. typeInfo->mType = ScriptPrimitiveType::ComponentRef;
  335. return typeInfo;
  336. }
  337. else
  338. {
  339. std::shared_ptr<ManagedSerializableObjectInfo> objInfo;
  340. if (getSerializableObjectInfo(monoClass->getNamespace(), monoClass->getTypeName(), objInfo))
  341. return objInfo->mTypeInfo;
  342. }
  343. break;
  344. case MONO_TYPE_VALUETYPE:
  345. {
  346. std::shared_ptr<ManagedSerializableObjectInfo> objInfo;
  347. if (getSerializableObjectInfo(monoClass->getNamespace(), monoClass->getTypeName(), objInfo))
  348. return objInfo->mTypeInfo;
  349. }
  350. break;
  351. case MONO_TYPE_GENERICINST:
  352. if(monoClass->getFullName() == mSystemGenericListClass->getFullName()) // Full name is part of CIL spec, so it is just fine to compare like this
  353. {
  354. std::shared_ptr<ManagedSerializableTypeInfoList> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoList>();
  355. MonoProperty& itemProperty = monoClass->getProperty("Item");
  356. MonoClass* itemClass = itemProperty.getReturnType();
  357. if(itemClass != nullptr)
  358. typeInfo->mElementType = determineType(itemClass);
  359. return typeInfo;
  360. }
  361. else if(monoClass->getFullName() == mSystemGenericDictionaryClass->getFullName())
  362. {
  363. std::shared_ptr<ManagedSerializableTypeInfoDictionary> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoDictionary>();
  364. MonoMethod* getEnumerator = monoClass->getMethod("GetEnumerator");
  365. MonoClass* enumClass = getEnumerator->getReturnType();
  366. MonoProperty& currentProp = enumClass->getProperty("Current");
  367. MonoClass* keyValuePair = currentProp.getReturnType();
  368. MonoProperty& keyProperty = keyValuePair->getProperty("Key");
  369. MonoProperty& valueProperty = keyValuePair->getProperty("Value");
  370. MonoClass* keyClass = keyProperty.getReturnType();
  371. if(keyClass != nullptr)
  372. typeInfo->mKeyType = determineType(keyClass);
  373. MonoClass* valueClass = valueProperty.getReturnType();
  374. if(valueClass != nullptr)
  375. typeInfo->mValueType = determineType(valueClass);
  376. return typeInfo;
  377. }
  378. break;
  379. case MONO_TYPE_SZARRAY:
  380. case MONO_TYPE_ARRAY:
  381. {
  382. std::shared_ptr<ManagedSerializableTypeInfoArray> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoArray>();
  383. ::MonoClass* elementClass = mono_class_get_element_class(monoClass->_getInternalClass());
  384. if(elementClass != nullptr)
  385. {
  386. MonoClass* monoElementClass = MonoManager::instance().findClass(elementClass);
  387. if(monoElementClass != nullptr)
  388. typeInfo->mElementType = determineType(monoElementClass);
  389. }
  390. typeInfo->mRank = (UINT32)mono_class_get_rank(monoClass->_getInternalClass());
  391. return typeInfo;
  392. }
  393. }
  394. return nullptr;
  395. }
  396. void ScriptAssemblyManager::clearScriptObjects()
  397. {
  398. mBaseTypesInitialized = false;
  399. mSystemArrayClass = nullptr;
  400. mSystemGenericListClass = nullptr;
  401. mSystemGenericDictionaryClass = nullptr;
  402. mSystemTypeClass = nullptr;
  403. mSerializeObjectAttribute = nullptr;
  404. mDontSerializeFieldAttribute = nullptr;
  405. mComponentClass = nullptr;
  406. mSceneObjectClass = nullptr;
  407. mMissingComponentClass = nullptr;
  408. mSerializeFieldAttribute = nullptr;
  409. mHideInInspectorAttribute = nullptr;
  410. }
  411. void ScriptAssemblyManager::initializeBaseTypes()
  412. {
  413. // Get necessary classes for detecting needed class & field information
  414. MonoAssembly* corlib = MonoManager::instance().getAssembly("corlib");
  415. if(corlib == nullptr)
  416. BS_EXCEPT(InvalidStateException, "corlib assembly is not loaded.");
  417. MonoAssembly* bansheeEngineAssembly = MonoManager::instance().getAssembly(ENGINE_ASSEMBLY);
  418. if(bansheeEngineAssembly == nullptr)
  419. BS_EXCEPT(InvalidStateException, String(ENGINE_ASSEMBLY) + " assembly is not loaded.");
  420. mSystemArrayClass = corlib->getClass("System", "Array");
  421. if(mSystemArrayClass == nullptr)
  422. BS_EXCEPT(InvalidStateException, "Cannot find System.Array managed class.");
  423. mSystemGenericListClass = corlib->getClass("System.Collections.Generic", "List`1");
  424. if(mSystemGenericListClass == nullptr)
  425. BS_EXCEPT(InvalidStateException, "Cannot find List<T> managed class.");
  426. mSystemGenericDictionaryClass = corlib->getClass("System.Collections.Generic", "Dictionary`2");
  427. if(mSystemGenericDictionaryClass == nullptr)
  428. BS_EXCEPT(InvalidStateException, "Cannot find Dictionary<TKey, TValue> managed class.");
  429. mSystemTypeClass = corlib->getClass("System", "Type");
  430. if (mSystemTypeClass == nullptr)
  431. BS_EXCEPT(InvalidStateException, "Cannot find Type managed class.");
  432. mSerializeObjectAttribute = bansheeEngineAssembly->getClass("BansheeEngine", "SerializeObject");
  433. if(mSerializeObjectAttribute == nullptr)
  434. BS_EXCEPT(InvalidStateException, "Cannot find SerializableObject managed class.");
  435. mDontSerializeFieldAttribute = bansheeEngineAssembly->getClass("BansheeEngine", "DontSerializeField");
  436. if(mDontSerializeFieldAttribute == nullptr)
  437. BS_EXCEPT(InvalidStateException, "Cannot find DontSerializeField managed class.");
  438. mComponentClass = bansheeEngineAssembly->getClass("BansheeEngine", "Component");
  439. if(mComponentClass == nullptr)
  440. BS_EXCEPT(InvalidStateException, "Cannot find Component managed class.");
  441. mMissingComponentClass = bansheeEngineAssembly->getClass("BansheeEngine", "MissingComponent");
  442. if (mMissingComponentClass == nullptr)
  443. BS_EXCEPT(InvalidStateException, "Cannot find MissingComponent managed class.");
  444. mSceneObjectClass = bansheeEngineAssembly->getClass("BansheeEngine", "SceneObject");
  445. if(mSceneObjectClass == nullptr)
  446. BS_EXCEPT(InvalidStateException, "Cannot find SceneObject managed class.");
  447. mSerializeFieldAttribute = bansheeEngineAssembly->getClass("BansheeEngine", "SerializeField");
  448. if(mSerializeFieldAttribute == nullptr)
  449. BS_EXCEPT(InvalidStateException, "Cannot find SerializeField managed class.");
  450. mHideInInspectorAttribute = bansheeEngineAssembly->getClass("BansheeEngine", "HideInInspector");
  451. if(mHideInInspectorAttribute == nullptr)
  452. BS_EXCEPT(InvalidStateException, "Cannot find HideInInspector managed class.");
  453. mBaseTypesInitialized = true;
  454. }
  455. bool ScriptAssemblyManager::getSerializableObjectInfo(const String& ns, const String& typeName, std::shared_ptr<ManagedSerializableObjectInfo>& outInfo)
  456. {
  457. String fullName = ns + "." + typeName;
  458. for(auto& curAssembly : mAssemblyInfos)
  459. {
  460. if (curAssembly.second == nullptr)
  461. continue;
  462. auto iterFind = curAssembly.second->mTypeNameToId.find(fullName);
  463. if(iterFind != curAssembly.second->mTypeNameToId.end())
  464. {
  465. outInfo = curAssembly.second->mObjectInfos[iterFind->second];
  466. return true;
  467. }
  468. }
  469. return false;
  470. }
  471. bool ScriptAssemblyManager::hasSerializableObjectInfo(const String& ns, const String& typeName)
  472. {
  473. String fullName = ns + "." + typeName;
  474. for(auto& curAssembly : mAssemblyInfos)
  475. {
  476. auto iterFind = curAssembly.second->mTypeNameToId.find(fullName);
  477. if(iterFind != curAssembly.second->mTypeNameToId.end())
  478. return true;
  479. }
  480. return false;
  481. }
  482. }