我为Unity制作了一个Android插件(主要指this),我调用静态方法的代码是:
plugin = new AndroidJavaClass("com.aoshitang.demo.UnitySensorPlugin").CallStatic<AndroidJavaObject>("getInstance");
执行代码时,控制台向我报告“ NullReferenceException:对象引用未设置为对象的实例”。我发现plugin
参数为null,因此无法采取进一步措施。我的Android代码是:
public static UnitySensorPlugin getInstance() {
// double check synchronization
UnitySensorPlugin result = instance;
if (result == null) {
synchronized (SINGLETON_LOCK) {
result = instance;
if (result == null) {
result = new UnitySensorPlugin();
result.sensorManager = (SensorManager) UnityPlayer.currentActivity.getSystemService(Context.SENSOR_SERVICE);
instance = result;
}
}
}
return result;
}
我该如何解决这个问题?