/// <summary>
        /// Used internally by WearableControl to get the latest buffer of SensorFrame updates from
        /// the Wearable Device; the newest frame in that batch is set as the CurrentSensorFrame.
        /// </summary>
        private void GetLatestSensorUpdates()
        {
            _currentSensorFrames.Clear();

                        #if UNITY_IOS && !UNITY_EDITOR
            unsafe
            {
                BridgeSensorFrame *frames = null;
                int count = 0;
                WearableGetSensorFrames(&frames, &count);
                if (count > 0)
                {
                    for (int i = 0; i < count; i++)
                    {
                        var frame = frames + i;
                        _currentSensorFrames.Add(new SensorFrame {
                            timestamp       = WearableConstants.Sensor2UnityTime * frame->timestamp,
                            deltaTime       = WearableConstants.Sensor2UnityTime * frame->deltaTime,
                            acceleration    = frame->acceleration,
                            angularVelocity = frame->angularVelocity,
                            rotation        = frame->rotation,
                            gameRotation    = frame->gameRotation,
                            gestureId       = frame->gestureId
                        });
                    }

                    _lastSensorFrame = _currentSensorFrames[_currentSensorFrames.Count - 1];

                    OnSensorsUpdated(_lastSensorFrame);
                }
            }
                        #endif
        }
 public void GetLatestSensorUpdatesInternal()
 {
     unsafe
     {
         BridgeSensorFrame *frames = null;
         int count = 0;
         WearableGetSensorFrames(&frames, &count);
         if (count > 0)
         {
             for (int i = 0; i < count; i++)
             {
                 var frame = frames + i;
                 _currentSensorFrames.Add(new SensorFrame
                 {
                     timestamp       = WearableConstants.SENSOR2_UNITY_TIME * frame->timestamp,
                     deltaTime       = WearableConstants.SENSOR2_UNITY_TIME * frame->deltaTime,
                     acceleration    = frame->acceleration,
                     angularVelocity = frame->angularVelocity,
                     rotationNineDof = frame->rotationNineDof,
                     rotationSixDof  = frame->rotationSixDof,
                 });
             }
         }
     }
 }
        /// <summary>
        /// Used internally by WearableControl to get the latest buffer of SensorFrame updates from
        /// the Wearable Device; the newest frame in that batch is set as the CurrentSensorFrame.
        /// </summary>
        private void GetLatestSensorUpdates()
        {
            _currentSensorFrames.Clear();

                        #if UNITY_IOS && !UNITY_EDITOR
            unsafe
            {
                BridgeSensorFrame *frames = null;
                int count = 0;
                WearableGetSensorFrames(&frames, &count);
                if (count > 0)
                {
                    for (int i = 0; i < count; i++)
                    {
                        var frame = frames + i;
                        _currentSensorFrames.Add(new SensorFrame {
                            timestamp       = WearableConstants.Sensor2UnityTime * frame->timestamp,
                            deltaTime       = WearableConstants.Sensor2UnityTime * frame->deltaTime,
                            acceleration    = frame->acceleration,
                            angularVelocity = frame->angularVelocity,
                            rotation        = frame->rotation,
                            gestureId       = frame->gestureId
                        });
                    }

                    _lastSensorFrame = _currentSensorFrames[_currentSensorFrames.Count - 1];

                    OnSensorsOrGestureUpdated(_lastSensorFrame);
                }
            }
                        #elif UNITY_ANDROID && !UNITY_EDITOR
            const string GetLengthMethod          = "length";
            const string GetFrameAtIndexMethod    = "getFrameAtIndex";
            const string GetAccelerationMethod    = "getAcceleration";
            const string GetAngularVelocityMethod = "getAngularVelocity";
            const string GetRotationMethod        = "getRotation";

            const string GetWMethod           = "getW";
            const string GetXMethod           = "getX";
            const string GetYMethod           = "getY";
            const string GetZMethod           = "getZ";
            const string GetAccuracyMethod    = "getAccuracyValue";
            const string GetUncertaintyMethod = "getAccuracy";

            const string GetTimestampMethod = "getTimestamp";
            const string GetDeltaTimeMethod = "getDeltaTime";

            const string GetInput = "getInput";

            AndroidJavaObject androidObj = AndroidPlugin.GetFrames();
            int count = androidObj.Call <int>(GetLengthMethod);

            if (count > 0)
            {
                for (int i = 0; i < count; i++)
                {
                    AndroidJavaObject frame = androidObj.Call <AndroidJavaObject>(GetFrameAtIndexMethod, i);

                    AndroidJavaObject accelValue  = frame.Call <AndroidJavaObject>(GetAccelerationMethod);
                    AndroidJavaObject angVelValue = frame.Call <AndroidJavaObject>(GetAngularVelocityMethod);
                    AndroidJavaObject rotValue    = frame.Call <AndroidJavaObject>(GetRotationMethod);

                    byte gesture = frame.Call <byte>(GetInput);

                    SensorVector3    accel = new SensorVector3();
                    SensorVector3    gyro  = new SensorVector3();
                    SensorQuaternion rot   = new SensorQuaternion();

                    accel.value = new Vector3(
                        (float)accelValue.Call <double>(GetXMethod),
                        (float)accelValue.Call <double>(GetYMethod),
                        (float)accelValue.Call <double>(GetZMethod)
                        );
                    accel.accuracy = (SensorAccuracy)accelValue.Call <byte>(GetAccuracyMethod);

                    gyro.value = new Vector3(
                        (float)angVelValue.Call <double>(GetXMethod),
                        (float)angVelValue.Call <double>(GetYMethod),
                        (float)angVelValue.Call <double>(GetZMethod)
                        );
                    gyro.accuracy = (SensorAccuracy)angVelValue.Call <byte>(GetAccuracyMethod);

                    rot.value = new Quaternion(
                        (float)rotValue.Call <double>(GetXMethod),
                        (float)rotValue.Call <double>(GetYMethod),
                        (float)rotValue.Call <double>(GetZMethod),
                        (float)rotValue.Call <double>(GetWMethod)
                        );
                    rot.measurementUncertainty = (float)rotValue.Call <double>(GetUncertaintyMethod);

                    _currentSensorFrames.Add(
                        new SensorFrame
                    {
                        timestamp       = WearableConstants.Sensor2UnityTime * frame.Call <int>(GetTimestampMethod),
                        deltaTime       = WearableConstants.Sensor2UnityTime * frame.Call <int>(GetDeltaTimeMethod),
                        acceleration    = accel,
                        angularVelocity = gyro,
                        rotation        = rot,
                        gestureId       = (GestureId)gesture
                    }
                        );
                }

                _lastSensorFrame = _currentSensorFrames[_currentSensorFrames.Count - 1];

                OnSensorsOrGestureUpdated(_lastSensorFrame);
            }
                        #endif
        }