void ManagedDropDownWindow::reloadMonoTypes(MonoClass* windowClass) { MonoMethod* updateMethod = windowClass->getMethod("OnEditorUpdate", 0); if (updateMethod != nullptr) mUpdateThunk = (UpdateThunkDef)updateMethod->getThunk(); MonoMethod* onInitializeMethod = windowClass->getMethod("OnInitialize", 0); if (onInitializeMethod != nullptr) mOnInitializeThunk = (OnInitializeThunkDef)onInitializeMethod->getThunk(); MonoMethod* onDestroyMethod = windowClass->getMethod("OnDestroy", 0); if (onDestroyMethod != nullptr) mOnDestroyThunk = (OnDestroyThunkDef)onDestroyMethod->getThunk(); }
void ScriptEditorWidget::reloadMonoTypes(MonoClass* windowClass) { MonoMethod* updateMethod = windowClass->getMethod("OnEditorUpdate", 0); if (updateMethod != nullptr) mUpdateThunk = (UpdateThunkDef)updateMethod->getThunk(); MonoMethod* onInitializeMethod = windowClass->getMethod("OnInitialize", 0); if (onInitializeMethod != nullptr) mOnInitializeThunk = (OnInitializeThunkDef)onInitializeMethod->getThunk(); MonoMethod* onDestroyMethod = windowClass->getMethod("OnDestroy", 0); if (onDestroyMethod != nullptr) mOnDestroyThunk = (OnDestroyThunkDef)onDestroyMethod->getThunk(); mGetDisplayName = windowClass->getMethod("GetDisplayName", 0); }
SPtr<ManagedSerializableTypeInfo> ScriptAssemblyManager::getTypeInfo(MonoClass* monoClass) { if(!mBaseTypesInitialized) BS_EXCEPT(InvalidStateException, "Calling getTypeInfo without previously initializing base types."); MonoPrimitiveType monoPrimitiveType = MonoUtil::getPrimitiveType(monoClass->_getInternalClass()); // If enum get the enum base data type bool isEnum = MonoUtil::isEnum(monoClass->_getInternalClass()); if (isEnum) monoPrimitiveType = MonoUtil::getEnumPrimitiveType(monoClass->_getInternalClass()); // Determine field type switch(monoPrimitiveType) { case MonoPrimitiveType::Boolean: { SPtr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>(); typeInfo->mType = ScriptPrimitiveType::Bool; return typeInfo; } case MonoPrimitiveType::Char: { SPtr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>(); typeInfo->mType = ScriptPrimitiveType::Char; return typeInfo; } case MonoPrimitiveType::I8: { SPtr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>(); typeInfo->mType = ScriptPrimitiveType::I8; return typeInfo; } case MonoPrimitiveType::U8: { SPtr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>(); typeInfo->mType = ScriptPrimitiveType::U8; return typeInfo; } case MonoPrimitiveType::I16: { SPtr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>(); typeInfo->mType = ScriptPrimitiveType::I16; return typeInfo; } case MonoPrimitiveType::U16: { SPtr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>(); typeInfo->mType = ScriptPrimitiveType::U16; return typeInfo; } case MonoPrimitiveType::I32: { SPtr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>(); typeInfo->mType = ScriptPrimitiveType::I32; return typeInfo; } case MonoPrimitiveType::U32: { SPtr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>(); typeInfo->mType = ScriptPrimitiveType::U32; return typeInfo; } case MonoPrimitiveType::I64: { SPtr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>(); typeInfo->mType = ScriptPrimitiveType::I64; return typeInfo; } case MonoPrimitiveType::U64: { SPtr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>(); typeInfo->mType = ScriptPrimitiveType::U64; return typeInfo; } case MonoPrimitiveType::String: { SPtr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>(); typeInfo->mType = ScriptPrimitiveType::String; return typeInfo; } case MonoPrimitiveType::R32: { SPtr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>(); typeInfo->mType = ScriptPrimitiveType::Float; return typeInfo; } case MonoPrimitiveType::R64: { SPtr<ManagedSerializableTypeInfoPrimitive> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoPrimitive>(); typeInfo->mType = ScriptPrimitiveType::Double; return typeInfo; } case MonoPrimitiveType::Class: if(monoClass->isSubClassOf(ScriptResource::getMetaData()->scriptClass)) // Resource { SPtr<ManagedSerializableTypeInfoRef> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoRef>(); typeInfo->mTypeNamespace = monoClass->getNamespace(); typeInfo->mTypeName = monoClass->getTypeName(); typeInfo->mRTIITypeId = 0; if(monoClass == ScriptResource::getMetaData()->scriptClass) typeInfo->mType = ScriptReferenceType::BuiltinResourceBase; else if (monoClass == ScriptManagedResource::getMetaData()->scriptClass) typeInfo->mType = ScriptReferenceType::ManagedResourceBase; else if (monoClass->isSubClassOf(ScriptManagedResource::getMetaData()->scriptClass)) typeInfo->mType = ScriptReferenceType::ManagedResource; else if (monoClass->isSubClassOf(ScriptResource::getMetaData()->scriptClass)) { typeInfo->mType = ScriptReferenceType::BuiltinResource; ::MonoReflectionType* type = MonoUtil::getType(monoClass->_getInternalClass()); BuiltinResourceInfo* builtinInfo = getBuiltinResourceInfo(type); if (builtinInfo == nullptr) { assert(false && "Unable to find information about a built-in resource. Did you update BuiltinResourceTypes list?"); return nullptr; } typeInfo->mRTIITypeId = builtinInfo->typeId; } return typeInfo; } else if (monoClass->isSubClassOf(mSceneObjectClass) || monoClass->isSubClassOf(mComponentClass)) // Game object { SPtr<ManagedSerializableTypeInfoRef> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoRef>(); typeInfo->mTypeNamespace = monoClass->getNamespace(); typeInfo->mTypeName = monoClass->getTypeName(); typeInfo->mRTIITypeId = 0; if (monoClass == mComponentClass) typeInfo->mType = ScriptReferenceType::BuiltinComponentBase; else if (monoClass == mManagedComponentClass) typeInfo->mType = ScriptReferenceType::ManagedComponentBase; else if (monoClass->isSubClassOf(mSceneObjectClass)) typeInfo->mType = ScriptReferenceType::SceneObject; else if (monoClass->isSubClassOf(mManagedComponentClass)) typeInfo->mType = ScriptReferenceType::ManagedComponent; else if (monoClass->isSubClassOf(mComponentClass)) { typeInfo->mType = ScriptReferenceType::BuiltinComponent; ::MonoReflectionType* type = MonoUtil::getType(monoClass->_getInternalClass()); BuiltinComponentInfo* builtinInfo = getBuiltinComponentInfo(type); if(builtinInfo == nullptr) { assert(false && "Unable to find information about a built-in component. Did you update BuiltinComponents list?"); return nullptr; } typeInfo->mRTIITypeId = builtinInfo->typeId; } return typeInfo; } else { SPtr<ManagedSerializableObjectInfo> objInfo; if (getSerializableObjectInfo(monoClass->getNamespace(), monoClass->getTypeName(), objInfo)) return objInfo->mTypeInfo; } break; case MonoPrimitiveType::ValueType: { SPtr<ManagedSerializableObjectInfo> objInfo; if (getSerializableObjectInfo(monoClass->getNamespace(), monoClass->getTypeName(), objInfo)) return objInfo->mTypeInfo; } break; case MonoPrimitiveType::Generic: if(monoClass->getFullName() == mSystemGenericListClass->getFullName()) // Full name is part of CIL spec, so it is just fine to compare like this { SPtr<ManagedSerializableTypeInfoList> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoList>(); MonoProperty* itemProperty = monoClass->getProperty("Item"); MonoClass* itemClass = itemProperty->getReturnType(); if (itemClass != nullptr) typeInfo->mElementType = getTypeInfo(itemClass); if (typeInfo->mElementType == nullptr) return nullptr; return typeInfo; } else if(monoClass->getFullName() == mSystemGenericDictionaryClass->getFullName()) { SPtr<ManagedSerializableTypeInfoDictionary> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoDictionary>(); MonoMethod* getEnumerator = monoClass->getMethod("GetEnumerator"); MonoClass* enumClass = getEnumerator->getReturnType(); MonoProperty* currentProp = enumClass->getProperty("Current"); MonoClass* keyValuePair = currentProp->getReturnType(); MonoProperty* keyProperty = keyValuePair->getProperty("Key"); MonoProperty* valueProperty = keyValuePair->getProperty("Value"); MonoClass* keyClass = keyProperty->getReturnType(); if(keyClass != nullptr) typeInfo->mKeyType = getTypeInfo(keyClass); MonoClass* valueClass = valueProperty->getReturnType(); if(valueClass != nullptr) typeInfo->mValueType = getTypeInfo(valueClass); if (typeInfo->mKeyType == nullptr || typeInfo->mValueType == nullptr) return nullptr; return typeInfo; } break; case MonoPrimitiveType::Array: { SPtr<ManagedSerializableTypeInfoArray> typeInfo = bs_shared_ptr_new<ManagedSerializableTypeInfoArray>(); ::MonoClass* elementClass = ScriptArray::getElementClass(monoClass->_getInternalClass()); if(elementClass != nullptr) { MonoClass* monoElementClass = MonoManager::instance().findClass(elementClass); if(monoElementClass != nullptr) typeInfo->mElementType = getTypeInfo(monoElementClass); } if (typeInfo->mElementType == nullptr) return nullptr; typeInfo->mRank = ScriptArray::getRank(monoClass->_getInternalClass()); return typeInfo; } default: break; } return nullptr; }