BsScriptAssemblyManager.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  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 = getTypeInfo(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::clearAssemblyInfo()
  137. {
  138. clearScriptObjects();
  139. mAssemblyInfos.clear();
  140. }
  141. ManagedSerializableTypeInfoPtr ScriptAssemblyManager::getTypeInfo(MonoClass* monoClass)
  142. {
  143. if(!mBaseTypesInitialized)
  144. BS_EXCEPT(InvalidStateException, "Calling determineType without previously initializing base types.");
  145. MonoType* monoType = mono_class_get_type(monoClass->_getInternalClass());
  146. int monoPrimitiveType = mono_type_get_type(monoType);
  147. // If enum get the enum base data type
  148. bool isEnum = mono_class_is_enum(monoClass->_getInternalClass()) == 1;
  149. if (isEnum)
  150. {
  151. MonoType* underlyingType = mono_type_get_underlying_type(monoType);
  152. monoPrimitiveType = mono_type_get_type(underlyingType);
  153. }
  154. // Determine field type
  155. switch(monoPrimitiveType)
  156. {
  157. case MONO_TYPE_BOOLEAN:
  158. {
  159. std::shared_ptr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>();
  160. typeInfo->mType = ScriptPrimitiveType::Bool;
  161. return typeInfo;
  162. }
  163. case MONO_TYPE_CHAR:
  164. {
  165. std::shared_ptr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>();
  166. typeInfo->mType = ScriptPrimitiveType::Char;
  167. return typeInfo;
  168. }
  169. case MONO_TYPE_I1:
  170. {
  171. std::shared_ptr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>();
  172. typeInfo->mType = ScriptPrimitiveType::I8;
  173. return typeInfo;
  174. }
  175. case MONO_TYPE_U1:
  176. {
  177. std::shared_ptr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>();
  178. typeInfo->mType = ScriptPrimitiveType::U8;
  179. return typeInfo;
  180. }
  181. case MONO_TYPE_I2:
  182. {
  183. std::shared_ptr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>();
  184. typeInfo->mType = ScriptPrimitiveType::I16;
  185. return typeInfo;
  186. }
  187. case MONO_TYPE_U2:
  188. {
  189. std::shared_ptr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>();
  190. typeInfo->mType = ScriptPrimitiveType::U16;
  191. return typeInfo;
  192. }
  193. case MONO_TYPE_I4:
  194. {
  195. std::shared_ptr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>();
  196. typeInfo->mType = ScriptPrimitiveType::I32;
  197. return typeInfo;
  198. }
  199. case MONO_TYPE_U4:
  200. {
  201. std::shared_ptr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>();
  202. typeInfo->mType = ScriptPrimitiveType::U32;
  203. return typeInfo;
  204. }
  205. case MONO_TYPE_I8:
  206. {
  207. std::shared_ptr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>();
  208. typeInfo->mType = ScriptPrimitiveType::I64;
  209. return typeInfo;
  210. }
  211. case MONO_TYPE_U8:
  212. {
  213. std::shared_ptr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>();
  214. typeInfo->mType = ScriptPrimitiveType::U64;
  215. return typeInfo;
  216. }
  217. case MONO_TYPE_STRING:
  218. {
  219. std::shared_ptr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>();
  220. typeInfo->mType = ScriptPrimitiveType::String;
  221. return typeInfo;
  222. }
  223. case MONO_TYPE_R4:
  224. {
  225. std::shared_ptr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>();
  226. typeInfo->mType = ScriptPrimitiveType::Float;
  227. return typeInfo;
  228. }
  229. case MONO_TYPE_R8:
  230. {
  231. std::shared_ptr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>();
  232. typeInfo->mType = ScriptPrimitiveType::Double;
  233. return typeInfo;
  234. }
  235. case MONO_TYPE_CLASS:
  236. if(monoClass->isSubClassOf(ScriptTexture2D::getMetaData()->scriptClass))
  237. {
  238. std::shared_ptr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>();
  239. typeInfo->mType = ScriptPrimitiveType::Texture2DRef;
  240. return typeInfo;
  241. }
  242. if (monoClass->isSubClassOf(ScriptTexture3D::getMetaData()->scriptClass))
  243. {
  244. std::shared_ptr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>();
  245. typeInfo->mType = ScriptPrimitiveType::Texture3DRef;
  246. return typeInfo;
  247. }
  248. if (monoClass->isSubClassOf(ScriptTextureCube::getMetaData()->scriptClass))
  249. {
  250. std::shared_ptr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>();
  251. typeInfo->mType = ScriptPrimitiveType::TextureCubeRef;
  252. return typeInfo;
  253. }
  254. else if (monoClass->isSubClassOf(ScriptSpriteTexture::getMetaData()->scriptClass))
  255. {
  256. std::shared_ptr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>();
  257. typeInfo->mType = ScriptPrimitiveType::SpriteTextureRef;
  258. return typeInfo;
  259. }
  260. else if (monoClass->isSubClassOf(ScriptManagedResource::getMetaData()->scriptClass))
  261. {
  262. std::shared_ptr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>();
  263. typeInfo->mType = ScriptPrimitiveType::ManagedResourceRef;
  264. return typeInfo;
  265. }
  266. else if (monoClass->isSubClassOf(ScriptShader::getMetaData()->scriptClass))
  267. {
  268. std::shared_ptr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>();
  269. typeInfo->mType = ScriptPrimitiveType::ShaderRef;
  270. return typeInfo;
  271. }
  272. else if (monoClass->isSubClassOf(ScriptMaterial::getMetaData()->scriptClass))
  273. {
  274. std::shared_ptr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>();
  275. typeInfo->mType = ScriptPrimitiveType::MaterialRef;
  276. return typeInfo;
  277. }
  278. else if (monoClass->isSubClassOf(ScriptMesh::getMetaData()->scriptClass))
  279. {
  280. std::shared_ptr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>();
  281. typeInfo->mType = ScriptPrimitiveType::MeshRef;
  282. return typeInfo;
  283. }
  284. else if (monoClass->isSubClassOf(ScriptPlainText::getMetaData()->scriptClass))
  285. {
  286. std::shared_ptr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>();
  287. typeInfo->mType = ScriptPrimitiveType::PlainTextRef;
  288. return typeInfo;
  289. }
  290. else if (monoClass->isSubClassOf(ScriptScriptCode::getMetaData()->scriptClass))
  291. {
  292. std::shared_ptr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>();
  293. typeInfo->mType = ScriptPrimitiveType::ScriptCodeRef;
  294. return typeInfo;
  295. }
  296. else if (monoClass->isSubClassOf(ScriptPrefab::getMetaData()->scriptClass))
  297. {
  298. std::shared_ptr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>();
  299. typeInfo->mType = ScriptPrimitiveType::PrefabRef;
  300. return typeInfo;
  301. }
  302. else if (monoClass->isSubClassOf(ScriptFont::getMetaData()->scriptClass))
  303. {
  304. std::shared_ptr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>();
  305. typeInfo->mType = ScriptPrimitiveType::FontRef;
  306. return typeInfo;
  307. }
  308. else if (monoClass->isSubClassOf(ScriptStringTable::getMetaData()->scriptClass))
  309. {
  310. std::shared_ptr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>();
  311. typeInfo->mType = ScriptPrimitiveType::StringTableRef;
  312. return typeInfo;
  313. }
  314. else if (monoClass->isSubClassOf(ScriptGUISkin::getMetaData()->scriptClass))
  315. {
  316. std::shared_ptr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>();
  317. typeInfo->mType = ScriptPrimitiveType::GUISkinRef;
  318. return typeInfo;
  319. }
  320. else if(monoClass->isSubClassOf(mSceneObjectClass))
  321. {
  322. std::shared_ptr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>();
  323. typeInfo->mType = ScriptPrimitiveType::SceneObjectRef;
  324. return typeInfo;
  325. }
  326. else if(monoClass->isSubClassOf(mComponentClass))
  327. {
  328. std::shared_ptr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>();
  329. typeInfo->mType = ScriptPrimitiveType::ComponentRef;
  330. return typeInfo;
  331. }
  332. else
  333. {
  334. std::shared_ptr<ManagedSerializableObjectInfo> objInfo;
  335. if (getSerializableObjectInfo(monoClass->getNamespace(), monoClass->getTypeName(), objInfo))
  336. return objInfo->mTypeInfo;
  337. }
  338. break;
  339. case MONO_TYPE_VALUETYPE:
  340. {
  341. std::shared_ptr<ManagedSerializableObjectInfo> objInfo;
  342. if (getSerializableObjectInfo(monoClass->getNamespace(), monoClass->getTypeName(), objInfo))
  343. return objInfo->mTypeInfo;
  344. }
  345. break;
  346. case MONO_TYPE_GENERICINST:
  347. if(monoClass->getFullName() == mSystemGenericListClass->getFullName()) // Full name is part of CIL spec, so it is just fine to compare like this
  348. {
  349. std::shared_ptr<ManagedSerializableTypeInfoList> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoList>();
  350. MonoProperty& itemProperty = monoClass->getProperty("Item");
  351. MonoClass* itemClass = itemProperty.getReturnType();
  352. if(itemClass != nullptr)
  353. typeInfo->mElementType = getTypeInfo(itemClass);
  354. return typeInfo;
  355. }
  356. else if(monoClass->getFullName() == mSystemGenericDictionaryClass->getFullName())
  357. {
  358. std::shared_ptr<ManagedSerializableTypeInfoDictionary> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoDictionary>();
  359. MonoMethod* getEnumerator = monoClass->getMethod("GetEnumerator");
  360. MonoClass* enumClass = getEnumerator->getReturnType();
  361. MonoProperty& currentProp = enumClass->getProperty("Current");
  362. MonoClass* keyValuePair = currentProp.getReturnType();
  363. MonoProperty& keyProperty = keyValuePair->getProperty("Key");
  364. MonoProperty& valueProperty = keyValuePair->getProperty("Value");
  365. MonoClass* keyClass = keyProperty.getReturnType();
  366. if(keyClass != nullptr)
  367. typeInfo->mKeyType = getTypeInfo(keyClass);
  368. MonoClass* valueClass = valueProperty.getReturnType();
  369. if(valueClass != nullptr)
  370. typeInfo->mValueType = getTypeInfo(valueClass);
  371. return typeInfo;
  372. }
  373. break;
  374. case MONO_TYPE_SZARRAY:
  375. case MONO_TYPE_ARRAY:
  376. {
  377. std::shared_ptr<ManagedSerializableTypeInfoArray> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoArray>();
  378. ::MonoClass* elementClass = mono_class_get_element_class(monoClass->_getInternalClass());
  379. if(elementClass != nullptr)
  380. {
  381. MonoClass* monoElementClass = MonoManager::instance().findClass(elementClass);
  382. if(monoElementClass != nullptr)
  383. typeInfo->mElementType = getTypeInfo(monoElementClass);
  384. }
  385. typeInfo->mRank = (UINT32)mono_class_get_rank(monoClass->_getInternalClass());
  386. return typeInfo;
  387. }
  388. }
  389. return nullptr;
  390. }
  391. void ScriptAssemblyManager::clearScriptObjects()
  392. {
  393. mBaseTypesInitialized = false;
  394. mSystemArrayClass = nullptr;
  395. mSystemGenericListClass = nullptr;
  396. mSystemGenericDictionaryClass = nullptr;
  397. mSystemTypeClass = nullptr;
  398. mSerializeObjectAttribute = nullptr;
  399. mDontSerializeFieldAttribute = nullptr;
  400. mComponentClass = nullptr;
  401. mSceneObjectClass = nullptr;
  402. mMissingComponentClass = nullptr;
  403. mSerializeFieldAttribute = nullptr;
  404. mHideInInspectorAttribute = nullptr;
  405. }
  406. void ScriptAssemblyManager::initializeBaseTypes()
  407. {
  408. // Get necessary classes for detecting needed class & field information
  409. MonoAssembly* corlib = MonoManager::instance().getAssembly("corlib");
  410. if(corlib == nullptr)
  411. BS_EXCEPT(InvalidStateException, "corlib assembly is not loaded.");
  412. MonoAssembly* bansheeEngineAssembly = MonoManager::instance().getAssembly(ENGINE_ASSEMBLY);
  413. if(bansheeEngineAssembly == nullptr)
  414. BS_EXCEPT(InvalidStateException, String(ENGINE_ASSEMBLY) + " assembly is not loaded.");
  415. mSystemArrayClass = corlib->getClass("System", "Array");
  416. if(mSystemArrayClass == nullptr)
  417. BS_EXCEPT(InvalidStateException, "Cannot find System.Array managed class.");
  418. mSystemGenericListClass = corlib->getClass("System.Collections.Generic", "List`1");
  419. if(mSystemGenericListClass == nullptr)
  420. BS_EXCEPT(InvalidStateException, "Cannot find List<T> managed class.");
  421. mSystemGenericDictionaryClass = corlib->getClass("System.Collections.Generic", "Dictionary`2");
  422. if(mSystemGenericDictionaryClass == nullptr)
  423. BS_EXCEPT(InvalidStateException, "Cannot find Dictionary<TKey, TValue> managed class.");
  424. mSystemTypeClass = corlib->getClass("System", "Type");
  425. if (mSystemTypeClass == nullptr)
  426. BS_EXCEPT(InvalidStateException, "Cannot find Type managed class.");
  427. mSerializeObjectAttribute = bansheeEngineAssembly->getClass("BansheeEngine", "SerializeObject");
  428. if(mSerializeObjectAttribute == nullptr)
  429. BS_EXCEPT(InvalidStateException, "Cannot find SerializableObject managed class.");
  430. mDontSerializeFieldAttribute = bansheeEngineAssembly->getClass("BansheeEngine", "DontSerializeField");
  431. if(mDontSerializeFieldAttribute == nullptr)
  432. BS_EXCEPT(InvalidStateException, "Cannot find DontSerializeField managed class.");
  433. mComponentClass = bansheeEngineAssembly->getClass("BansheeEngine", "Component");
  434. if(mComponentClass == nullptr)
  435. BS_EXCEPT(InvalidStateException, "Cannot find Component managed class.");
  436. mMissingComponentClass = bansheeEngineAssembly->getClass("BansheeEngine", "MissingComponent");
  437. if (mMissingComponentClass == nullptr)
  438. BS_EXCEPT(InvalidStateException, "Cannot find MissingComponent managed class.");
  439. mSceneObjectClass = bansheeEngineAssembly->getClass("BansheeEngine", "SceneObject");
  440. if(mSceneObjectClass == nullptr)
  441. BS_EXCEPT(InvalidStateException, "Cannot find SceneObject managed class.");
  442. mSerializeFieldAttribute = bansheeEngineAssembly->getClass("BansheeEngine", "SerializeField");
  443. if(mSerializeFieldAttribute == nullptr)
  444. BS_EXCEPT(InvalidStateException, "Cannot find SerializeField managed class.");
  445. mHideInInspectorAttribute = bansheeEngineAssembly->getClass("BansheeEngine", "HideInInspector");
  446. if(mHideInInspectorAttribute == nullptr)
  447. BS_EXCEPT(InvalidStateException, "Cannot find HideInInspector managed class.");
  448. mBaseTypesInitialized = true;
  449. }
  450. bool ScriptAssemblyManager::getSerializableObjectInfo(const String& ns, const String& typeName, std::shared_ptr<ManagedSerializableObjectInfo>& outInfo)
  451. {
  452. String fullName = ns + "." + typeName;
  453. for(auto& curAssembly : mAssemblyInfos)
  454. {
  455. if (curAssembly.second == nullptr)
  456. continue;
  457. auto iterFind = curAssembly.second->mTypeNameToId.find(fullName);
  458. if(iterFind != curAssembly.second->mTypeNameToId.end())
  459. {
  460. outInfo = curAssembly.second->mObjectInfos[iterFind->second];
  461. return true;
  462. }
  463. }
  464. return false;
  465. }
  466. bool ScriptAssemblyManager::hasSerializableObjectInfo(const String& ns, const String& typeName)
  467. {
  468. String fullName = ns + "." + typeName;
  469. for(auto& curAssembly : mAssemblyInfos)
  470. {
  471. auto iterFind = curAssembly.second->mTypeNameToId.find(fullName);
  472. if(iterFind != curAssembly.second->mTypeNameToId.end())
  473. return true;
  474. }
  475. return false;
  476. }
  477. }