Esempio n. 1
0
        /// <summary>
        /// Check that the required rotation sensor is enabled and rate is sufficient, resolve differences if not.
        /// Adds a <see cref="WearableRequirement"/> component on this GameObject if needed.
        /// </summary>
        private void CheckAndResolveRequirement()
        {
            bool showChangedRequirementWarnings = true;

            if (_requirement == null)
            {
                // If we don't have a requirement, look for one on the parent GameObject.
                _requirement = GetComponent <WearableRequirement>();
                if (_requirement == null)
                {
                    // If there isn't one, create it.
                    _requirement = gameObject.AddComponent <WearableRequirement>();
                    Debug.LogFormat(WearableConstants.ROTATION_MATCHER_ADDED_REQUIREMENT_MESSAGE_FORMAT, name);

                    // If it's a new requirement, suppress the alteration warnings.
                    showChangedRequirementWarnings = false;
                }
            }

            // Check that the attached requirement's update interval is fast enough.
            if (_requirement.DeviceConfig.updateInterval.IsSlowerThan(_updateInterval))
            {
                _requirement.SetSensorUpdateInterval(_updateInterval);
                if (showChangedRequirementWarnings)
                {
                    Debug.LogWarningFormat(
                        WearableConstants.ROTATION_MATCHER_CHANGED_REQUIREMENT_UPDATE_INTERVAL_WARNING_FORMAT,
                        name);
                }
            }

            // Check to ensure the proper sensor is enabled
            SensorId rotationSensorId = _rotationSource == RotationSensorSource.NineDof ?
                                        SensorId.RotationNineDof :
                                        SensorId.RotationSixDof;
            var config = _requirement.DeviceConfig.GetSensorConfig(rotationSensorId);

            if (!config.isEnabled)
            {
                // Switch to proper sensor and turn off the unused one.
                // If the user has manually enabled both sensors, this will not turn any sensors off when changing mode.
                _requirement.EnableSensor(rotationSensorId);
                _requirement.DisableSensor(
                    rotationSensorId == SensorId.RotationSixDof ?
                    SensorId.RotationNineDof :
                    SensorId.RotationSixDof);

                if (showChangedRequirementWarnings)
                {
                    Debug.LogWarningFormat(
                        WearableConstants.ROTATION_MATCHER_CHANGED_REQUIREMENT_SENSORS_WARNING_FORMAT,
                        name);
                }
            }
        }
Esempio n. 2
0
        private void Awake()
        {
            // Begin in absolute mode and cache the wearable controller.
            _wearableControl = WearableControl.Instance;


            // Establish a requirement for the rotation sensor
            WearableRequirement requirement = GetComponent <WearableRequirement>();

            if (requirement == null)
            {
                requirement = gameObject.AddComponent <WearableRequirement>();
            }

            requirement.EnableSensor(SensorId.Accelerometer);
            requirement.SetSensorUpdateInterval(SensorUpdateInterval.EightyMs);
        }
Esempio n. 3
0
        private void Awake()
        {
            // Begin in absolute mode and cache the wearable controller.
            _wearableControl  = WearableControl.Instance;
            _mode             = RotationReference.Absolute;
            _inverseReference = Quaternion.identity;

            // Establish a requirement for the rotation sensor
            WearableRequirement requirement = GetComponent <WearableRequirement>();

            if (requirement == null)
            {
                requirement = gameObject.AddComponent <WearableRequirement>();
            }
            requirement.EnableSensor(SensorId.Rotation);
            requirement.SetSensorUpdateInterval(SensorUpdateInterval.EightyMs);
        }