示例#1
0
 private void OnValidate()
 {
     // Set using the variable not the method, so the provider doesn't get prematurely initialized
                 #if UNITY_EDITOR
     _activeProvider = GetOrCreateProvider(_editorDefaultProvider);
                 #else
     _activeProvider = GetOrCreateProvider(_runtimeDefaultProvider);
                 #endif
 }
示例#2
0
        /// <summary>
        /// Set the active provider to a specific provider instance
        /// </summary>
        /// <param name="provider"></param>
        public void SetActiveProvider(WearableProviderBase provider)
        {
            // Uninitialized providers should never have OnEnable/Disable called
            if (_activeProvider != null)
            {
                if (_activeProvider.Initialized)
                {
                    _activeProvider.OnDisableProvider();
                }

                // Unsubscribe after disabling in case OnDisableProvider invokes an event
                // Using an invocation method here rather than the event proper ensures that any events added or removed
                // after setting the provider will be accounted for.
                _activeProvider.DeviceConnecting        -= OnDeviceConnecting;
                _activeProvider.DeviceConnected         -= OnDeviceConnected;
                _activeProvider.DeviceDisconnected      -= OnDeviceDisconnected;
                _activeProvider.SensorsOrGestureUpdated -= OnSensorsOrGestureUpdated;
            }

            _activeProvider = provider;

            // Initialize if this is the first time the provider is active
            if (!_activeProvider.Initialized)
            {
                _activeProvider.OnInitializeProvider();
            }

            // Subscribe to the provider's events
            _activeProvider.DeviceConnecting        += OnDeviceConnecting;
            _activeProvider.DeviceConnected         += OnDeviceConnected;
            _activeProvider.DeviceDisconnected      += OnDeviceDisconnected;
            _activeProvider.SensorsOrGestureUpdated += OnSensorsOrGestureUpdated;

            // Enable the new provider after subscribing in case enabling the provider invokes an event
            _activeProvider.OnEnableProvider();
        }