Version: 2023.1
public IntPtr fnPtr ;

描述

The function pointer.

This should be obtained using Marshal.GetFunctionPointerForDelegate, and delegate should refer to a method annotated with MonoPInvokeCallback attribute and having such signature: static ReturnType MyMethod(IntPtr jniEnv, IntPtr objectOrClass, ...);

// Delegate difinition
delegate void JavaToCs(IntPtr jniEnv, IntPtr klass, int x);

// Method definition [MonoPInvokeCallback(typeof(JavaToCs))] static void CsMethod(IntPtr jniEnv, IntPtr klass, int x) { Debug.Log("From Java: " + x); }

// Array to be passed to AndroidJNI.RegisterNative var methods = new JNINativeMethod[] { new JNINativeMethod { name = "csMethod", signature = "(I)V", fnPtr = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate(new JavaToCs(CsMethod)), } };

// Register method for Java class AndroidJNI.RegisterNatives(clazz, methods);
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961