BsScriptAssemblyManager.cpp 20 KB

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