Exemple #1
0
        public void RegisterSensorListener(SENSOR_TYPE type, SENSOR_LOCATION location)
        {
            if (nibiruSensorServiceObject != null)
            {
                if (nibiruSensorDataListenerCallback == null)
                {
                    nibiruSensorDataListenerCallback = new NibiruSensorDataListenerCallback();
                }

                // UI线程执行
                RunOnUIThread(androidActivity, new AndroidJavaRunnable(() =>
                {
                    AndroidJavaClass locationClass =
                        BaseAndroidDevice.GetClass("com.nibiru.service.NibiruSensorService$SENSOR_LOCATION");
                    AndroidJavaObject locationObj =
                        locationClass.CallStatic <AndroidJavaObject>("valueOf", location.ToString());

                    AndroidJavaClass typeClass =
                        BaseAndroidDevice.GetClass("com.nibiru.service.NibiruSensorService$SENSOR_TYPE");
                    AndroidJavaObject typeObj = typeClass.CallStatic <AndroidJavaObject>("valueOf", type.ToString());

                    nibiruSensorServiceObject.Call <bool>("registerSensorListener", typeObj, locationObj,
                                                          nibiruSensorDataListenerCallback);
                    Debug.Log("registerSensorListener=" + type.ToString() + "," + location.ToString());
                }
                                                                       ));
            }
            else
            {
                Debug.LogError("RegisterControllerSensor failed, nibiruSensorServiceObject is null !");
            }
        }
Exemple #2
0
 public NibiruSensorEvent(float x, float y, float z, long timestamp, SENSOR_TYPE sensorType, SENSOR_LOCATION sensorLocation)
 {
     this.x              = x;
     this.y              = y;
     this.z              = z;
     this.timestamp      = timestamp;
     this.sensorLocation = sensorLocation;
     this.sensorType     = sensorType;
 }
Exemple #3
0
            public void onSensorDataChanged(AndroidJavaObject sensorEventObject)
            {
                float             x              = sensorEventObject.Get <float>("x");
                float             y              = sensorEventObject.Get <float>("y");
                float             z              = sensorEventObject.Get <float>("z");
                long              timestamp      = sensorEventObject.Get <long>("timestamp");
                AndroidJavaObject locationObject = sensorEventObject.Get <AndroidJavaObject>("sensorLocation");
                AndroidJavaObject typeObject     = sensorEventObject.Get <AndroidJavaObject>("sensorType");
                SENSOR_LOCATION   sensorLocation = (SENSOR_LOCATION)locationObject.Call <int>("ordinal");
                SENSOR_TYPE       sensorType     = (SENSOR_TYPE)typeObject.Call <int>("ordinal");

                NibiruSensorEvent sensorEvent = new NibiruSensorEvent(x, y, z, timestamp, sensorType, sensorLocation);

                // sensorEvent.printLog();

                // 用Loom的方法在Unity主线程中调用Text组件
                Loom.QueueOnMainThread((param) =>
                {
                    if (OnSensorDataChangedHandler != null)
                    {
                        OnSensorDataChangedHandler((NibiruSensorEvent)param);
                    }
                }, sensorEvent);
            }