BsScriptAssemblyManager.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #include "BsScriptAssemblyManager.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 "BsScriptShaderInclude.h"
  21. #include "BsScriptPlainText.h"
  22. #include "BsScriptScriptCode.h"
  23. #include "BsScriptStringTable.h"
  24. #include "BsScriptGUISkin.h"
  25. #include "BsScriptPhysicsMaterial.h"
  26. #include "BsScriptPhysicsMesh.h"
  27. #include "BsScriptPrefab.h"
  28. namespace BansheeEngine
  29. {
  30. ScriptAssemblyManager::ScriptAssemblyManager()
  31. : mBaseTypesInitialized(false), mSystemArrayClass(nullptr), mSystemGenericListClass(nullptr)
  32. , mSystemGenericDictionaryClass(nullptr), mSystemTypeClass(nullptr), mComponentClass(nullptr)
  33. , mSceneObjectClass(nullptr), mMissingComponentClass(nullptr), mSerializeObjectAttribute(nullptr)
  34. , mDontSerializeFieldAttribute(nullptr), mSerializeFieldAttribute(nullptr), mHideInInspectorAttribute(nullptr)
  35. {
  36. }
  37. ScriptAssemblyManager::~ScriptAssemblyManager()
  38. {
  39. }
  40. Vector<String> ScriptAssemblyManager::getScriptAssemblies() const
  41. {
  42. Vector<String> initializedAssemblies;
  43. for (auto& assemblyPair : mAssemblyInfos)
  44. initializedAssemblies.push_back(assemblyPair.first);
  45. return initializedAssemblies;
  46. }
  47. void ScriptAssemblyManager::loadAssemblyInfo(const String& assemblyName)
  48. {
  49. if(!mBaseTypesInitialized)
  50. initializeBaseTypes();
  51. // Process all classes and fields
  52. UINT32 mUniqueTypeId = 1;
  53. MonoAssembly* curAssembly = MonoManager::instance().getAssembly(assemblyName);
  54. if(curAssembly == nullptr)
  55. return;
  56. SPtr<ManagedSerializableAssemblyInfo> assemblyInfo = bs_shared_ptr_new<ManagedSerializableAssemblyInfo>();
  57. assemblyInfo->mName = assemblyName;
  58. mAssemblyInfos[assemblyName] = assemblyInfo;
  59. MonoClass* managedResourceClass = ScriptManagedResource::getMetaData()->scriptClass;
  60. // Populate class data
  61. const Vector<MonoClass*>& allClasses = curAssembly->getAllClasses();
  62. for(auto& curClass : allClasses)
  63. {
  64. if ((curClass->isSubClassOf(mComponentClass) || curClass->isSubClassOf(managedResourceClass) ||
  65. curClass->hasAttribute(mSerializeObjectAttribute)) && curClass != mComponentClass && curClass != managedResourceClass)
  66. {
  67. SPtr<ManagedSerializableTypeInfoObject> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoObject>();
  68. typeInfo->mTypeNamespace = curClass->getNamespace();
  69. typeInfo->mTypeName = curClass->getTypeName();
  70. typeInfo->mTypeId = mUniqueTypeId++;
  71. MonoPrimitiveType monoPrimitiveType = MonoUtil::getPrimitiveType(curClass->_getInternalClass());
  72. if(monoPrimitiveType == MonoPrimitiveType::ValueType)
  73. typeInfo->mValueType = true;
  74. else
  75. typeInfo->mValueType = false;
  76. SPtr<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. SPtr<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. SPtr<ManagedSerializableTypeInfo> typeInfo = getTypeInfo(field->getType());
  94. if (typeInfo == nullptr)
  95. continue;
  96. SPtr<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. SPtr<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. SPtr<ManagedSerializableTypeInfo> ScriptAssemblyManager::getTypeInfo(MonoClass* monoClass)
  142. {
  143. if(!mBaseTypesInitialized)
  144. BS_EXCEPT(InvalidStateException, "Calling determineType without previously initializing base types.");
  145. MonoPrimitiveType monoPrimitiveType = MonoUtil::getPrimitiveType(monoClass->_getInternalClass());
  146. // If enum get the enum base data type
  147. bool isEnum = MonoUtil::isEnum(monoClass->_getInternalClass());
  148. if (isEnum)
  149. monoPrimitiveType = MonoUtil::getEnumPrimitiveType(monoClass->_getInternalClass());
  150. // Determine field type
  151. switch(monoPrimitiveType)
  152. {
  153. case MonoPrimitiveType::Boolean:
  154. {
  155. SPtr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>();
  156. typeInfo->mType = ScriptPrimitiveType::Bool;
  157. return typeInfo;
  158. }
  159. case MonoPrimitiveType::Char:
  160. {
  161. SPtr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>();
  162. typeInfo->mType = ScriptPrimitiveType::Char;
  163. return typeInfo;
  164. }
  165. case MonoPrimitiveType::I8:
  166. {
  167. SPtr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>();
  168. typeInfo->mType = ScriptPrimitiveType::I8;
  169. return typeInfo;
  170. }
  171. case MonoPrimitiveType::U8:
  172. {
  173. SPtr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>();
  174. typeInfo->mType = ScriptPrimitiveType::U8;
  175. return typeInfo;
  176. }
  177. case MonoPrimitiveType::I16:
  178. {
  179. SPtr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>();
  180. typeInfo->mType = ScriptPrimitiveType::I16;
  181. return typeInfo;
  182. }
  183. case MonoPrimitiveType::U16:
  184. {
  185. SPtr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>();
  186. typeInfo->mType = ScriptPrimitiveType::U16;
  187. return typeInfo;
  188. }
  189. case MonoPrimitiveType::I32:
  190. {
  191. SPtr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>();
  192. typeInfo->mType = ScriptPrimitiveType::I32;
  193. return typeInfo;
  194. }
  195. case MonoPrimitiveType::U32:
  196. {
  197. SPtr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>();
  198. typeInfo->mType = ScriptPrimitiveType::U32;
  199. return typeInfo;
  200. }
  201. case MonoPrimitiveType::I64:
  202. {
  203. SPtr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>();
  204. typeInfo->mType = ScriptPrimitiveType::I64;
  205. return typeInfo;
  206. }
  207. case MonoPrimitiveType::U64:
  208. {
  209. SPtr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>();
  210. typeInfo->mType = ScriptPrimitiveType::U64;
  211. return typeInfo;
  212. }
  213. case MonoPrimitiveType::String:
  214. {
  215. SPtr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>();
  216. typeInfo->mType = ScriptPrimitiveType::String;
  217. return typeInfo;
  218. }
  219. case MonoPrimitiveType::R32:
  220. {
  221. SPtr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>();
  222. typeInfo->mType = ScriptPrimitiveType::Float;
  223. return typeInfo;
  224. }
  225. case MonoPrimitiveType::R64:
  226. {
  227. SPtr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>();
  228. typeInfo->mType = ScriptPrimitiveType::Double;
  229. return typeInfo;
  230. }
  231. case MonoPrimitiveType::Class:
  232. if(monoClass->isSubClassOf(ScriptResource::getMetaData()->scriptClass)) // Resource
  233. {
  234. SPtr<ManagedSerializableTypeInfoRef> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoRef>();
  235. typeInfo->mTypeNamespace = monoClass->getNamespace();
  236. typeInfo->mTypeName = monoClass->getTypeName();
  237. if(monoClass == ScriptResource::getMetaData()->scriptClass)
  238. typeInfo->mType = ScriptReferenceType::Resource;
  239. else if (monoClass->isSubClassOf(ScriptTexture2D::getMetaData()->scriptClass))
  240. typeInfo->mType = ScriptReferenceType::Texture2D;
  241. else if (monoClass->isSubClassOf(ScriptTexture3D::getMetaData()->scriptClass))
  242. typeInfo->mType = ScriptReferenceType::Texture3D;
  243. else if (monoClass->isSubClassOf(ScriptTextureCube::getMetaData()->scriptClass))
  244. typeInfo->mType = ScriptReferenceType::TextureCube;
  245. else if (monoClass->isSubClassOf(ScriptSpriteTexture::getMetaData()->scriptClass))
  246. typeInfo->mType = ScriptReferenceType::SpriteTexture;
  247. else if (monoClass->isSubClassOf(ScriptManagedResource::getMetaData()->scriptClass))
  248. typeInfo->mType = ScriptReferenceType::ManagedResource;
  249. else if (monoClass->isSubClassOf(ScriptShader::getMetaData()->scriptClass))
  250. typeInfo->mType = ScriptReferenceType::Shader;
  251. else if (monoClass->isSubClassOf(ScriptShaderInclude::getMetaData()->scriptClass))
  252. typeInfo->mType = ScriptReferenceType::ShaderInclude;
  253. else if (monoClass->isSubClassOf(ScriptMaterial::getMetaData()->scriptClass))
  254. typeInfo->mType = ScriptReferenceType::Material;
  255. else if (monoClass->isSubClassOf(ScriptMesh::getMetaData()->scriptClass))
  256. typeInfo->mType = ScriptReferenceType::Mesh;
  257. else if (monoClass->isSubClassOf(ScriptPlainText::getMetaData()->scriptClass))
  258. typeInfo->mType = ScriptReferenceType::PlainText;
  259. else if (monoClass->isSubClassOf(ScriptScriptCode::getMetaData()->scriptClass))
  260. typeInfo->mType = ScriptReferenceType::ScriptCode;
  261. else if (monoClass->isSubClassOf(ScriptPrefab::getMetaData()->scriptClass))
  262. typeInfo->mType = ScriptReferenceType::Prefab;
  263. else if (monoClass->isSubClassOf(ScriptFont::getMetaData()->scriptClass))
  264. typeInfo->mType = ScriptReferenceType::Font;
  265. else if (monoClass->isSubClassOf(ScriptStringTable::getMetaData()->scriptClass))
  266. typeInfo->mType = ScriptReferenceType::StringTable;
  267. else if (monoClass->isSubClassOf(ScriptGUISkin::getMetaData()->scriptClass))
  268. typeInfo->mType = ScriptReferenceType::GUISkin;
  269. else if (monoClass->isSubClassOf(ScriptPhysicsMaterial::getMetaData()->scriptClass))
  270. typeInfo->mType = ScriptReferenceType::PhysicsMaterial;
  271. else if (monoClass->isSubClassOf(ScriptPhysicsMesh::getMetaData()->scriptClass))
  272. typeInfo->mType = ScriptReferenceType::PhysicsMesh;
  273. else
  274. {
  275. assert(false && "Unrecognized resource type");
  276. }
  277. return typeInfo;
  278. }
  279. else if (monoClass->isSubClassOf(mSceneObjectClass) || monoClass->isSubClassOf(mComponentClass)) // Game object
  280. {
  281. SPtr<ManagedSerializableTypeInfoRef> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoRef>();
  282. typeInfo->mTypeNamespace = monoClass->getNamespace();
  283. typeInfo->mTypeName = monoClass->getTypeName();
  284. if (monoClass == mComponentClass)
  285. typeInfo->mType = ScriptReferenceType::Component;
  286. else if (monoClass->isSubClassOf(mSceneObjectClass))
  287. typeInfo->mType = ScriptReferenceType::SceneObject;
  288. else if (monoClass->isSubClassOf(mComponentClass))
  289. typeInfo->mType = ScriptReferenceType::ManagedComponent;
  290. return typeInfo;
  291. }
  292. else
  293. {
  294. SPtr<ManagedSerializableObjectInfo> objInfo;
  295. if (getSerializableObjectInfo(monoClass->getNamespace(), monoClass->getTypeName(), objInfo))
  296. return objInfo->mTypeInfo;
  297. }
  298. break;
  299. case MonoPrimitiveType::ValueType:
  300. {
  301. SPtr<ManagedSerializableObjectInfo> objInfo;
  302. if (getSerializableObjectInfo(monoClass->getNamespace(), monoClass->getTypeName(), objInfo))
  303. return objInfo->mTypeInfo;
  304. }
  305. break;
  306. case MonoPrimitiveType::Generic:
  307. if(monoClass->getFullName() == mSystemGenericListClass->getFullName()) // Full name is part of CIL spec, so it is just fine to compare like this
  308. {
  309. SPtr<ManagedSerializableTypeInfoList> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoList>();
  310. MonoProperty& itemProperty = monoClass->getProperty("Item");
  311. MonoClass* itemClass = itemProperty.getReturnType();
  312. if (itemClass != nullptr)
  313. typeInfo->mElementType = getTypeInfo(itemClass);
  314. if (typeInfo->mElementType == nullptr)
  315. return nullptr;
  316. return typeInfo;
  317. }
  318. else if(monoClass->getFullName() == mSystemGenericDictionaryClass->getFullName())
  319. {
  320. SPtr<ManagedSerializableTypeInfoDictionary> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoDictionary>();
  321. MonoMethod* getEnumerator = monoClass->getMethod("GetEnumerator");
  322. MonoClass* enumClass = getEnumerator->getReturnType();
  323. MonoProperty& currentProp = enumClass->getProperty("Current");
  324. MonoClass* keyValuePair = currentProp.getReturnType();
  325. MonoProperty& keyProperty = keyValuePair->getProperty("Key");
  326. MonoProperty& valueProperty = keyValuePair->getProperty("Value");
  327. MonoClass* keyClass = keyProperty.getReturnType();
  328. if(keyClass != nullptr)
  329. typeInfo->mKeyType = getTypeInfo(keyClass);
  330. MonoClass* valueClass = valueProperty.getReturnType();
  331. if(valueClass != nullptr)
  332. typeInfo->mValueType = getTypeInfo(valueClass);
  333. if (typeInfo->mKeyType == nullptr || typeInfo->mValueType == nullptr)
  334. return nullptr;
  335. return typeInfo;
  336. }
  337. break;
  338. case MonoPrimitiveType::Array:
  339. {
  340. SPtr<ManagedSerializableTypeInfoArray> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoArray>();
  341. ::MonoClass* elementClass = ScriptArray::getElementClass(monoClass->_getInternalClass());
  342. if(elementClass != nullptr)
  343. {
  344. MonoClass* monoElementClass = MonoManager::instance().findClass(elementClass);
  345. if(monoElementClass != nullptr)
  346. typeInfo->mElementType = getTypeInfo(monoElementClass);
  347. }
  348. if (typeInfo->mElementType == nullptr)
  349. return nullptr;
  350. typeInfo->mRank = ScriptArray::getRank(monoClass->_getInternalClass());
  351. return typeInfo;
  352. }
  353. default:
  354. break;
  355. }
  356. return nullptr;
  357. }
  358. void ScriptAssemblyManager::clearScriptObjects()
  359. {
  360. mBaseTypesInitialized = false;
  361. mSystemArrayClass = nullptr;
  362. mSystemGenericListClass = nullptr;
  363. mSystemGenericDictionaryClass = nullptr;
  364. mSystemTypeClass = nullptr;
  365. mSerializeObjectAttribute = nullptr;
  366. mDontSerializeFieldAttribute = nullptr;
  367. mComponentClass = nullptr;
  368. mSceneObjectClass = nullptr;
  369. mMissingComponentClass = nullptr;
  370. mSerializeFieldAttribute = nullptr;
  371. mHideInInspectorAttribute = nullptr;
  372. }
  373. void ScriptAssemblyManager::initializeBaseTypes()
  374. {
  375. // Get necessary classes for detecting needed class & field information
  376. MonoAssembly* corlib = MonoManager::instance().getAssembly("corlib");
  377. if(corlib == nullptr)
  378. BS_EXCEPT(InvalidStateException, "corlib assembly is not loaded.");
  379. MonoAssembly* bansheeEngineAssembly = MonoManager::instance().getAssembly(ENGINE_ASSEMBLY);
  380. if(bansheeEngineAssembly == nullptr)
  381. BS_EXCEPT(InvalidStateException, String(ENGINE_ASSEMBLY) + " assembly is not loaded.");
  382. mSystemArrayClass = corlib->getClass("System", "Array");
  383. if(mSystemArrayClass == nullptr)
  384. BS_EXCEPT(InvalidStateException, "Cannot find System.Array managed class.");
  385. mSystemGenericListClass = corlib->getClass("System.Collections.Generic", "List`1");
  386. if(mSystemGenericListClass == nullptr)
  387. BS_EXCEPT(InvalidStateException, "Cannot find List<T> managed class.");
  388. mSystemGenericDictionaryClass = corlib->getClass("System.Collections.Generic", "Dictionary`2");
  389. if(mSystemGenericDictionaryClass == nullptr)
  390. BS_EXCEPT(InvalidStateException, "Cannot find Dictionary<TKey, TValue> managed class.");
  391. mSystemTypeClass = corlib->getClass("System", "Type");
  392. if (mSystemTypeClass == nullptr)
  393. BS_EXCEPT(InvalidStateException, "Cannot find Type managed class.");
  394. mSerializeObjectAttribute = bansheeEngineAssembly->getClass("BansheeEngine", "SerializeObject");
  395. if(mSerializeObjectAttribute == nullptr)
  396. BS_EXCEPT(InvalidStateException, "Cannot find SerializableObject managed class.");
  397. mDontSerializeFieldAttribute = bansheeEngineAssembly->getClass("BansheeEngine", "DontSerializeField");
  398. if(mDontSerializeFieldAttribute == nullptr)
  399. BS_EXCEPT(InvalidStateException, "Cannot find DontSerializeField managed class.");
  400. mComponentClass = bansheeEngineAssembly->getClass("BansheeEngine", "Component");
  401. if(mComponentClass == nullptr)
  402. BS_EXCEPT(InvalidStateException, "Cannot find Component managed class.");
  403. mMissingComponentClass = bansheeEngineAssembly->getClass("BansheeEngine", "MissingComponent");
  404. if (mMissingComponentClass == nullptr)
  405. BS_EXCEPT(InvalidStateException, "Cannot find MissingComponent managed class.");
  406. mSceneObjectClass = bansheeEngineAssembly->getClass("BansheeEngine", "SceneObject");
  407. if(mSceneObjectClass == nullptr)
  408. BS_EXCEPT(InvalidStateException, "Cannot find SceneObject managed class.");
  409. mSerializeFieldAttribute = bansheeEngineAssembly->getClass("BansheeEngine", "SerializeField");
  410. if(mSerializeFieldAttribute == nullptr)
  411. BS_EXCEPT(InvalidStateException, "Cannot find SerializeField managed class.");
  412. mHideInInspectorAttribute = bansheeEngineAssembly->getClass("BansheeEngine", "HideInInspector");
  413. if(mHideInInspectorAttribute == nullptr)
  414. BS_EXCEPT(InvalidStateException, "Cannot find HideInInspector managed class.");
  415. mBaseTypesInitialized = true;
  416. }
  417. bool ScriptAssemblyManager::getSerializableObjectInfo(const String& ns, const String& typeName, SPtr<ManagedSerializableObjectInfo>& outInfo)
  418. {
  419. String fullName = ns + "." + typeName;
  420. for(auto& curAssembly : mAssemblyInfos)
  421. {
  422. if (curAssembly.second == nullptr)
  423. continue;
  424. auto iterFind = curAssembly.second->mTypeNameToId.find(fullName);
  425. if(iterFind != curAssembly.second->mTypeNameToId.end())
  426. {
  427. outInfo = curAssembly.second->mObjectInfos[iterFind->second];
  428. return true;
  429. }
  430. }
  431. return false;
  432. }
  433. bool ScriptAssemblyManager::hasSerializableObjectInfo(const String& ns, const String& typeName)
  434. {
  435. String fullName = ns + "." + typeName;
  436. for(auto& curAssembly : mAssemblyInfos)
  437. {
  438. auto iterFind = curAssembly.second->mTypeNameToId.find(fullName);
  439. if(iterFind != curAssembly.second->mTypeNameToId.end())
  440. return true;
  441. }
  442. return false;
  443. }
  444. }