Ejemplo n.º 1
0
        private void ToggleTracking()
        {
            _tracking = !_tracking;

            if (_motionAvailable && _tracking)
            {
                HeadphoneMotion.StartTracking();
            }
            else
            {
                HeadphoneMotion.StopTracking();
            }

            UpdateTrackingButton();
        }
Ejemplo n.º 2
0
        private void Start()
        {
            // Add event listeners to buttons and hide buttons as needed.
            _toggleTrackingButton.onClick.AddListener(ToggleTracking);
            _trackingButtonText = _toggleTrackingButton.GetComponentInChildren <Text>();

            _calibrateStartingRotationButton.onClick.AddListener(CalibrateStartingRotation);
            _resetCalibrationButton.onClick.AddListener(ResetCalibration);
            UpdateRotationOffsetButtons();

            // Init HeadphoneMotion. Always call this first.
            HeadphoneMotion.Init();

            // Check if headphone motion is available on this device.
            _motionAvailable             = HeadphoneMotion.IsHeadphoneMotionAvailable();
            _motionAvailabilityText.text =
                (_motionAvailable) ? "Headphone motion is available" : "Headphone motion is not available";

            if (_motionAvailable)
            {
                // Set headphones connected text to false to start with.
                HandleHeadphoneConnectionChange(false);

                // Subscribe to events before starting tracking, or will miss the initial headphones connected callback.
                // Subscribe to the headphones connected/disconnected event.
                HeadphoneMotion.OnHeadphoneConnectionChanged += HandleHeadphoneConnectionChange;

                // Subscribe to the rotation callback.
                HeadphoneMotion.OnHeadRotationQuaternion += HandleHeadRotationQuaternion;

                // Start tracking headphone motion.
                HeadphoneMotion.StartTracking();
                _tracking = true;
            }

            UpdateTrackingButton();
        }