diff --git a/unity/Assets/core/upm/Runtime/Src/IL2Cpp/TypeRegister.cs b/unity/Assets/core/upm/Runtime/Src/IL2Cpp/TypeRegister.cs index 6683f59bab..4f6a55a1e0 100644 --- a/unity/Assets/core/upm/Runtime/Src/IL2Cpp/TypeRegister.cs +++ b/unity/Assets/core/upm/Runtime/Src/IL2Cpp/TypeRegister.cs @@ -208,76 +208,76 @@ private static void Register(Type type, MethodBase[] ctors = null, MethodBase[] } } - Action AddMethodToType = (string name, MethodInfo method, bool isGetter, bool isSetter, bool isExtensionMethod) => - { - method = TypeUtils.HandleMaybeGenericMethod(method); - if (method == null) return; - List usedTypes = TypeUtils.GetUsedTypes(method, isExtensionMethod); - var signature = TypeUtils.GetMethodSignature(method, false, isExtensionMethod); - // UnityEngine.Debug.Log(string.Format("add method {0}, usedTypes count: {1}", method, usedTypes.Count)); + Action AddMethodToType = (string name, MethodInfo method, bool isGetter, bool isSetter, bool isExtensionMethod) => + { + method = TypeUtils.HandleMaybeGenericMethod(method); + if (method == null) return; + List usedTypes = TypeUtils.GetUsedTypes(method, isExtensionMethod); + var signature = TypeUtils.GetMethodSignature(method, false, isExtensionMethod); + // UnityEngine.Debug.Log(string.Format("add method {0}, usedTypes count: {1}", method, usedTypes.Count)); - var wrapper = GetWrapperFunc(registerInfo, method, signature); - if (wrapper == IntPtr.Zero) - { - UnityEngine.Debug.LogWarning(string.Format("wrapper is null for {0}:{1}, signature:{2}", type, method, TypeUtils.GetMethodSignature(method, false, isExtensionMethod))); - return; - } - - var methodInfoPointer = NativeAPI.GetMethodInfoPointer(method); - var methodPointer = NativeAPI.GetMethodPointer(method); - if (methodInfoPointer == IntPtr.Zero) + var wrapper = GetWrapperFunc(registerInfo, method, signature); + if (wrapper == IntPtr.Zero) + { + UnityEngine.Debug.LogWarning(string.Format("wrapper is null for {0}:{1}, signature:{2}", type, method, TypeUtils.GetMethodSignature(method, false, isExtensionMethod))); + return; + } + + var methodInfoPointer = NativeAPI.GetMethodInfoPointer(method); + var methodPointer = NativeAPI.GetMethodPointer(method); + if (methodInfoPointer == IntPtr.Zero) + { + UnityEngine.Debug.LogWarning(string.Format("cannot get method info for {0}:{1}, signature:{2}", type, method, TypeUtils.GetMethodSignature(method, false, isExtensionMethod))); + return; + } + if (methodPointer == IntPtr.Zero) + { + UnityEngine.Debug.LogWarning(string.Format("cannot get method pointer for {0}:{1}, signature:{2}", type, method, TypeUtils.GetMethodSignature(method, false, isExtensionMethod))); + return; + } + var wrapData = NativeAPI.AddMethod( + typeInfo, + signature, + wrapper, + name, + !isExtensionMethod && method.IsStatic, + isExtensionMethod, + isGetter, + isSetter, + methodInfoPointer, + methodPointer, + usedTypes.Count + ); + if (wrapData == IntPtr.Zero) + { + if (throwIfMemberFail) { - UnityEngine.Debug.LogWarning(string.Format("cannot get method info for {0}:{1}, signature:{2}", type, method, TypeUtils.GetMethodSignature(method, false, isExtensionMethod))); - return; + throw new Exception(string.Format("add method for {0}:{1} fail, signature:{2}", type, method, TypeUtils.GetMethodSignature(method, false, isExtensionMethod))); } - if (methodPointer == IntPtr.Zero) + else { - UnityEngine.Debug.LogWarning(string.Format("cannot get method pointer for {0}:{1}, signature:{2}", type, method, TypeUtils.GetMethodSignature(method, false, isExtensionMethod))); +#if WARNING_IF_MEMBERFAIL + UnityEngine.Debug.LogWarning(string.Format("add method for {0}:{1} fail, signature:{2}", type, method, TypeUtils.GetMethodSignature(method, false, isExtensionMethod))); +#endif return; } - var wrapData = NativeAPI.AddMethod( - typeInfo, - signature, - wrapper, - name, - !isExtensionMethod && method.IsStatic, - isExtensionMethod, - isGetter, - isSetter, - methodInfoPointer, - methodPointer, - usedTypes.Count - ); - if (wrapData == IntPtr.Zero) - { - if (throwIfMemberFail) - { - throw new Exception(string.Format("add method for {0}:{1} fail, signature:{2}", type, method, TypeUtils.GetMethodSignature(method, false, isExtensionMethod))); - } - else - { - #if WARNING_IF_MEMBERFAIL - UnityEngine.Debug.LogWarning(string.Format("add method for {0}:{1} fail, signature:{2}", type, method, TypeUtils.GetMethodSignature(method, false, isExtensionMethod))); - #endif - return; - } - } - for (int i = 0; i < usedTypes.Count; ++i) - { - var usedTypeId = NativeAPI.GetTypeId(usedTypes[i]); - //UnityEngine.Debug.Log(string.Format("set used type for method {0}: {1}={2}, typeId:{3}", method, i, usedTypes[i], usedTypeId)); - NativeAPI.SetTypeInfo(wrapData, i, usedTypeId); - } - }; + } + for (int i = 0; i < usedTypes.Count; ++i) + { + var usedTypeId = NativeAPI.GetTypeId(usedTypes[i]); + //UnityEngine.Debug.Log(string.Format("set used type for method {0}: {1}={2}, typeId:{3}", method, i, usedTypes[i], usedTypeId)); + NativeAPI.SetTypeInfo(wrapData, i, usedTypeId); + } + }; - if (methods != null && (!type.IsArray || type == typeof(System.Array))) + if (methods != null && (!type.IsArray || type == typeof(System.Array))) + { + foreach (var method in methods) { - foreach (var method in methods) - { - if (method.IsAbstract) continue; - AddMethodToType(method.Name, method as MethodInfo, false, false, false); - } + if (method.IsAbstract) continue; + AddMethodToType(method.Name, method as MethodInfo, false, false, false); } + } if (!isDelegate) {