BsScriptAssemblyManager.cpp 21 KB

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