BsScriptAssemblyManager.cpp 20 KB

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