diff --git a/unity/native_src_il2cpp/Src/JSClassRegister.cpp b/unity/native_src_il2cpp/Src/JSClassRegister.cpp index a0a7156243..74403b1497 100644 --- a/unity/native_src_il2cpp/Src/JSClassRegister.cpp +++ b/unity/native_src_il2cpp/Src/JSClassRegister.cpp @@ -40,13 +40,11 @@ JSClassDefinition* JSClassDefinitionDuplicate(const JSClassDefinition* ClassDefi Ret->Functions = PropertyInfoDuplicate(ClassDefinition->Functions); Ret->Properties = PropertyInfoDuplicate(ClassDefinition->Properties); Ret->Variables = PropertyInfoDuplicate(ClassDefinition->Variables); -#if USING_IN_UNREAL_ENGINE Ret->ConstructorInfos = PropertyInfoDuplicate(ClassDefinition->ConstructorInfos); Ret->MethodInfos = PropertyInfoDuplicate(ClassDefinition->MethodInfos); Ret->FunctionInfos = PropertyInfoDuplicate(ClassDefinition->FunctionInfos); Ret->PropertyInfos = PropertyInfoDuplicate(ClassDefinition->PropertyInfos); Ret->VariableInfos = PropertyInfoDuplicate(ClassDefinition->VariableInfos); -#endif return Ret; } @@ -56,13 +54,11 @@ void JSClassDefinitionDelete(JSClassDefinition* ClassDefinition) delete[] ClassDefinition->Functions; delete[] ClassDefinition->Properties; delete[] ClassDefinition->Variables; -#if USING_IN_UNREAL_ENGINE delete[] ClassDefinition->ConstructorInfos; delete[] ClassDefinition->MethodInfos; delete[] ClassDefinition->FunctionInfos; delete[] ClassDefinition->PropertyInfos; delete[] ClassDefinition->VariableInfos; -#endif delete ClassDefinition; } @@ -85,7 +81,7 @@ class JSClassRegister void ForeachRegisterClass(std::function); - const JSClassDefinition* FindClassByID(const void* TypeId, bool TryLazyLoad); + const JSClassDefinition* FindClassByID(const void* TypeId, bool TryLazyLoad = false); void SetLazyLoadCallback(LoadTypeFunc InCallback) { @@ -147,6 +143,7 @@ void JSClassRegister::RegisterClass(const JSClassDefinition& ClassDefinition) CDataIdToClassDefinition[ClassDefinition.TypeId] = JSClassDefinitionDuplicate(&ClassDefinition); std::string SN = ClassDefinition.ScriptName; CDataNameToClassDefinition[SN] = CDataIdToClassDefinition[ClassDefinition.TypeId]; + CDataIdToClassDefinition[ClassDefinition.TypeId]->ScriptName = CDataNameToClassDefinition.find(SN)->first.c_str(); } #if USING_IN_UNREAL_ENGINE else if (ClassDefinition.UETypeName) @@ -162,6 +159,53 @@ void JSClassRegister::RegisterClass(const JSClassDefinition& ClassDefinition) #endif } +void SetReflectoinInfo(JSFunctionInfo* Methods, const NamedFunctionInfo* MethodInfos) +{ + std::map> InfoMap; + const NamedFunctionInfo* MethodInfo = MethodInfos; + while (MethodInfo->Name) + { + auto Iter = InfoMap.find(MethodInfo->Name); + if (Iter == InfoMap.end()) + { + InfoMap[MethodInfo->Name] = std::make_tuple(1, MethodInfo); + } + else + { + std::get<0>(Iter->second) = 2; + } + ++MethodInfo; + } + + JSFunctionInfo* Method = Methods; + while (Method->Name) + { + auto Iter = InfoMap.find(Method->Name); + if (Iter != InfoMap.end() && std::get<0>(Iter->second) == 1) + { + Method->ReflectionInfo = std::get<1>(Iter->second)->Type; + } + ++Method; + } +} + +void JSClassRegister::SetClassTypeInfo(const void* TypeId, const NamedFunctionInfo* ConstructorInfos, + const NamedFunctionInfo* MethodInfos, const NamedFunctionInfo* FunctionInfos, const NamedPropertyInfo* PropertyInfos, + const NamedPropertyInfo* VariableInfos) +{ + auto ClassDef = const_cast(FindClassByID(TypeId)); + if (ClassDef) + { + ClassDef->ConstructorInfos = PropertyInfoDuplicate(const_cast(ConstructorInfos)); + ClassDef->MethodInfos = PropertyInfoDuplicate(const_cast(MethodInfos)); + ClassDef->FunctionInfos = PropertyInfoDuplicate(const_cast(FunctionInfos)); + ClassDef->PropertyInfos = PropertyInfoDuplicate(const_cast(PropertyInfos)); + ClassDef->VariableInfos = PropertyInfoDuplicate(const_cast(VariableInfos)); + SetReflectoinInfo(ClassDef->Methods, ClassDef->MethodInfos); + SetReflectoinInfo(ClassDef->Functions, ClassDef->FunctionInfos); + } +} + const JSClassDefinition* JSClassRegister::FindClassByID(const void* TypeId, bool TryLazyLoad) { std::lock_guard guard(RegInfoMutex); @@ -254,6 +298,12 @@ void RegisterJSClass(const JSClassDefinition& ClassDefinition) GetJSClassRegister()->RegisterClass(ClassDefinition); } +void SetClassTypeInfo(const void* TypeId, const NamedFunctionInfo* ConstructorInfos, const NamedFunctionInfo* MethodInfos, + const NamedFunctionInfo* FunctionInfos, const NamedPropertyInfo* PropertyInfos, const NamedPropertyInfo* VariableInfos) +{ + GetJSClassRegister()->SetClassTypeInfo(TypeId, ConstructorInfos, MethodInfos, FunctionInfos, PropertyInfos, VariableInfos); +} + std::recursive_mutex& RegisterMutex() { return GetJSClassRegister()->RegisterMutex(); diff --git a/unity/native_src_il2cpp/Src/PesapiV8Impl.cpp b/unity/native_src_il2cpp/Src/PesapiV8Impl.cpp index 000c43ceb3..488b8982d9 100644 --- a/unity/native_src_il2cpp/Src/PesapiV8Impl.cpp +++ b/unity/native_src_il2cpp/Src/PesapiV8Impl.cpp @@ -879,7 +879,6 @@ MSVC_PRAGMA(warning(pop)) void pesapi_class_type_info(const char* proto_magic_id, const void* type_id, const void* constructor_info, const void* methods_info, const void* functions_info, const void* properties_info, const void* variables_info) { -#if USING_IN_UNREAL_ENGINE if (strcmp(proto_magic_id, PUERTS_BINDING_PROTO_ID()) != 0) { return; @@ -889,7 +888,6 @@ void pesapi_class_type_info(const char* proto_magic_id, const void* type_id, con static_cast(methods_info), static_cast(functions_info), static_cast(properties_info), static_cast(variables_info)); -#endif } const void* pesapi_find_type_id(const char* module_name, const char* type_name)