BsScriptAssemblyManager.cpp 22 KB

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