BsScriptAssemblyManager.cpp 20 KB

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