Example #1
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="name"></param>
 /// <param name="pointers"></param>
 public BaseGenericInputSource(string name, IMixedRealityPointer[] pointers = null, InputSourceType sourceType = InputSourceType.Other)
 {
     SourceId   = MixedRealityToolkit.InputSystem.GenerateNewSourceId();
     SourceName = name;
     Pointers   = pointers ?? new[] { MixedRealityToolkit.InputSystem.GazeProvider.GazePointer };
     SourceType = sourceType;
 }
Example #2
0
        private int SetInputSource(InputSourceType sourceType, InputSourceNumber sourceNumber)
        {
            byte[] msgData = new byte[]
            {
                0x07,
                0x01,
                (byte)MessageSet.InputSourceSet,
                (byte)sourceType,
                (byte)sourceNumber,
                0x01,
                0x00,
                0x00
            };

            byte[] responseData = null;

            if (this.SendMessage(msgData, ref responseData) == 0)
            {
                return(0);
            }
            else
            {
                return(1);
            }
        }
Example #3
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="name"></param>
 /// <param name="pointers"></param>
 public BaseGenericInputSource(string name, IMixedRealityPointer[] pointers = null, InputSourceType sourceType = InputSourceType.Other)
 {
     SourceId   = (InputSystem != null) ? InputSystem.GenerateNewSourceId() : 0;
     SourceName = name;
     Pointers   = pointers ?? new[] { InputSystem?.GazeProvider?.GazePointer };
     SourceType = sourceType;
 }
        /// <summary>
        /// Gets the ray assosiciated with the desired input source type
        /// and hand.
        /// </summary>
        /// <param name="sourceType">The type of input source</param>
        /// <param name="hand">The handedness of the input source</param>
        /// <param name="ray">The ray being returned</param>
        /// <returns>
        /// True if the ray is being returned, false otherwise.
        /// </returns>
        public static bool TryGetRay(InputSourceType sourceType, Handedness hand, out Ray ray)
        {
            bool success = false;

            switch (sourceType)
            {
            case InputSourceType.Head:
                // The head does not have a handedness, so we ignore the hand parameter.
                ray     = GetHeadGazeRay();
                success = true;
                break;

            case InputSourceType.Eyes:
                // The eyes do not have a handedness, so we ignore the hand parameter.
                success = TryGetEyeGazeRay(out ray);
                break;

            case InputSourceType.Hand:
                success = TryGetHandRay(hand, out ray);
                break;

            case InputSourceType.Controller:
                success = TryGetMotionControllerRay(hand, out ray);
                break;

            default:
                Debug.Log($"It is not supported to get the ray for {sourceType} sources.");
                ray     = new Ray();
                success = false;
                break;
            }
            return(success);
        }
        /// <inheritdoc />
        protected override bool TryRenderControllerModel(Type controllerType, InputSourceType inputSourceType)
        {
            MixedRealityControllerVisualizationProfile visualizationProfile = GetControllerVisualizationProfile();

            // Intercept this call if we are using the default driver provided models.
            if (visualizationProfile == null ||
                !visualizationProfile.GetUseDefaultModelsOverride(GetType(), ControllerHandedness))
            {
                return(base.TryRenderControllerModel(controllerType, inputSourceType));
            }
            else if (controllerDictionary.TryGetValue(ControllerHandedness, out GameObject controllerModel))
            {
                TryAddControllerModelToSceneHierarchy(controllerModel);
                controllerModel.SetActive(true);
                return(true);
            }

            Debug.Log("Trying to load controller model from platform SDK");

            GameObject controllerModelGameObject = new GameObject($"{ControllerHandedness} OpenVR Controller");

            bool failedToObtainControllerModel;

            var visualizationType = visualizationProfile.GetControllerVisualizationTypeOverride(GetType(), ControllerHandedness);

            if (visualizationType != null)
            {
                // Set the platform controller model to not be destroyed when the source is lost. It'll be disabled instead,
                // and re-enabled when the same controller is re-detected.
                if (controllerModelGameObject.AddComponent(visualizationType.Type) is IMixedRealityControllerPoseSynchronizer visualizer)
                {
                    visualizer.DestroyOnSourceLost = false;
                }

                OpenVRRenderModel openVRRenderModel = controllerModelGameObject.AddComponent <OpenVRRenderModel>();
                openVRRenderModel.shader      = visualizationProfile.GetDefaultControllerModelMaterialOverride(GetType(), ControllerHandedness).shader;
                failedToObtainControllerModel = !openVRRenderModel.LoadModel(ControllerHandedness);

                if (!failedToObtainControllerModel)
                {
                    TryAddControllerModelToSceneHierarchy(controllerModelGameObject);
                    controllerDictionary.Add(ControllerHandedness, controllerModelGameObject);
                }
            }
            else
            {
                Debug.LogError("Controller visualization type not defined for controller visualization profile");
                failedToObtainControllerModel = true;
            }

            if (failedToObtainControllerModel)
            {
                Debug.LogWarning("Failed to create controller model from driver, defaulting to BaseController behavior");
                UnityEngine.Object.Destroy(controllerModelGameObject);
                return(base.TryRenderControllerModel(GetType(), InputSourceType.Controller));
            }

            return(true);
        }
        /// <summary>
        /// Constructor.
        /// </summary>
        public BaseGlobalInputSource(string name, IMixedRealityFocusProvider focusProvider, InputSourceType sourceType = InputSourceType.Other)
        {
            SourceId      = (CoreServices.InputSystem != null) ? CoreServices.InputSystem.GenerateNewSourceId() : 0;
            SourceName    = name;
            FocusProvider = focusProvider;
            SourceType    = sourceType;

            UpdateActivePointers();
        }
Example #7
0
        /// <summary>
        /// Gets or adds a controller using the InputDevice name provided.
        /// </summary>
        /// <param name="inputDevice">The InputDevice from XR SDK.</param>
        /// <returns>The controller reference.</returns>
        protected virtual GenericXRSDKController GetOrAddController(InputDevice inputDevice)
        {
            using (GetOrAddControllerPerfMarker.Auto())
            {
                // If a device is already registered with the ID provided, just return it.
                if (ActiveControllers.ContainsKey(inputDevice))
                {
                    var controller = ActiveControllers[inputDevice];
                    Debug.Assert(controller != null);
                    return(controller);
                }

                Handedness controllingHand;

                if (inputDevice.characteristics.HasFlag(InputDeviceCharacteristics.Left))
                {
                    controllingHand = Handedness.Left;
                }
                else if (inputDevice.characteristics.HasFlag(InputDeviceCharacteristics.Right))
                {
                    controllingHand = Handedness.Right;
                }
                else
                {
                    controllingHand = Handedness.None;
                }

                SupportedControllerType currentControllerType = GetCurrentControllerType(inputDevice);
                Type            controllerType  = GetControllerType(currentControllerType);
                InputSourceType inputSourceType = GetInputSourceType(currentControllerType);

                IMixedRealityPointer[]   pointers           = RequestPointers(currentControllerType, controllingHand);
                IMixedRealityInputSource inputSource        = Service?.RequestNewGenericInputSource($"{currentControllerType} Controller {controllingHand}", pointers, inputSourceType);
                GenericXRSDKController   detectedController = Activator.CreateInstance(controllerType, TrackingState.NotTracked, controllingHand, inputSource, null) as GenericXRSDKController;

                if (detectedController == null || !detectedController.Enabled)
                {
                    // Controller failed to be set up correctly.
                    Debug.LogError($"Failed to create {controllerType.Name} controller");

                    // Return null so we don't raise the source detected.
                    return(null);
                }

                for (int i = 0; i < detectedController.InputSource?.Pointers?.Length; i++)
                {
                    detectedController.InputSource.Pointers[i].Controller = detectedController;
                }

                ActiveControllers.Add(inputDevice, detectedController);

                CoreServices.InputSystem?.RaiseSourceDetected(detectedController.InputSource, detectedController);

                return(detectedController);
            }
        }
Example #8
0
        /// <summary>
        /// Try to render a controller model for this controller from the visualization profile.
        /// </summary>
        /// <param name="controllerType">The type of controller to load the model for.</param>
        /// <param name="inputSourceType">Whether the model represents a hand or a controller.</param>
        /// <returns>True if a model was successfully loaded or model rendering is disabled. False if a model tried to load but failed.</returns>
        protected virtual bool TryRenderControllerModel(Type controllerType, InputSourceType inputSourceType)
        {
            MixedRealityControllerVisualizationProfile controllerVisualizationProfile = GetControllerVisualizationProfile();
            bool controllerVisualizationProfilePresent = controllerVisualizationProfile != null;

            if (!controllerVisualizationProfilePresent || !controllerVisualizationProfile.RenderMotionControllers)
            {
                return(true);
            }

            // Try to use the profile's override model first
            GameObject controllerModel = controllerVisualizationProfile.GetControllerModelOverride(controllerType, ControllerHandedness);

            // If the Controller model is still null in the end, use the global defaults.
            if (controllerModel == null)
            {
                if (inputSourceType == InputSourceType.Controller)
                {
                    if (ControllerHandedness == Handedness.Left &&
                        controllerVisualizationProfile.GlobalLeftHandModel != null)
                    {
                        controllerModel = controllerVisualizationProfile.GlobalLeftHandModel;
                    }
                    else if (ControllerHandedness == Handedness.Right &&
                             controllerVisualizationProfile.GlobalRightHandModel != null)
                    {
                        controllerModel = controllerVisualizationProfile.GlobalRightHandModel;
                    }
                }
                else if (inputSourceType == InputSourceType.Hand)
                {
                    if (ControllerHandedness == Handedness.Left &&
                        controllerVisualizationProfile.GlobalLeftHandVisualizer != null)
                    {
                        controllerModel = controllerVisualizationProfile.GlobalLeftHandVisualizer;
                    }
                    else if (ControllerHandedness == Handedness.Right &&
                             controllerVisualizationProfile.GlobalRightHandVisualizer != null)
                    {
                        controllerModel = controllerVisualizationProfile.GlobalRightHandVisualizer;
                    }
                }
            }

            if (controllerModel == null)
            {
                // no controller model available
                return(false);
            }

            // If we've got a controller model prefab, then create it and place it in the scene.
            GameObject controllerObject = UnityEngine.Object.Instantiate(controllerModel);

            return(TryAddControllerModelToSceneHierarchy(controllerObject));
        }
 private void SetToggleHelper <T>(Interactable toggle, string toggleName, InputSourceType inputType) where T : class, IMixedRealityPointer
 {
     if (toggle == null)
     {
         Debug.LogWarning($"Button {toggleName} is null on GameObject {gameObject.name}. Did you forget to set it?");
     }
     else
     {
         toggle.IsToggled = PointerUtils.GetPointerBehavior <T>(Handedness.Any, inputType) != PointerBehavior.AlwaysOff;
     }
 }
 /// <inheritdoc/>
 /// <remarks>
 /// If UseMRTKControllerVisualization is false, Oculus Touch controller model visualization will not be managed by MRTK
 /// Ensure that the Oculus Integration Package is installed and the Ovr Camera Rig is set correctly in the Oculus XRSDK Device Manager
 /// </remarks>
 protected override bool TryRenderControllerModel(Type controllerType, InputSourceType inputSourceType)
 {
     if (UseMRTKControllerVisualization)
     {
         return(base.TryRenderControllerModel(controllerType, inputSourceType));
     }
     else
     {
         return(false);
     }
 }
Example #11
0
        public void Initialize(string subscriptionKey, string region, InputSourceType inputSource, string wavFilename)
        {
            subscriptionKey.EnsureIsNotNull(nameof(subscriptionKey));
            subscriptionKey.EnsureIsNotNull(nameof(region));

            speechConfiguration = SpeechTranslationConfig.FromSubscription(subscriptionKey, region);
            speechConfiguration.OutputFormat = OutputFormat.Detailed;
            SendMessage($"Created the SpeechConfiguration with {subscriptionKey} | {region}");

            audioConfig = GetAudioConfig(inputSource, wavFilename);
        }
Example #12
0
 /// <summary>
 /// Sets the behavior for the given pointer type and input type.
 /// </summary>
 /// <typeparam name="T">All pointer types that equal or derive from this type will be set.</typeparam>
 /// <param name="pointerBehavior">Desired <seealso cref="Microsoft.MixedReality.Toolkit.Input.PointerBehavior"/>.</param>
 /// <param name="sourceType">Allows setting different behaviors for different input types (hands, controllers, etc.)</param>
 /// <param name="handedness">Specify handedness to restrict to only right, left.</param>
 public static void SetPointerBehavior <T>(PointerBehavior pointerBehavior, InputSourceType sourceType, Handedness handedness = Handedness.Any) where T : class, IMixedRealityPointer
 {
     if (CoreServices.InputSystem.FocusProvider is IPointerPreferences preferences)
     {
         preferences.SetPointerBehavior <T>(handedness, sourceType, pointerBehavior);
     }
     else
     {
         WarnAboutSettingCustomPointerBehaviors();
     }
 }
Example #13
0
 /// <summary>
 /// Returns all pointers with given handedness and input type.
 /// </summary>
 /// <param name="handedness">Handedness of pointer</param>
 /// <param name="sourceType">Only return pointers of this input source type</param>
 /// <returns>Iterator over all pointers that match the source type, with specific handedness</returns>
 public static IEnumerable <T> GetPointers <T>(Handedness handedness, InputSourceType sourceType) where T : IMixedRealityPointer
 {
     foreach (var pointer in GetPointers <T>(handedness))
     {
         if (pointer.Controller?.ControllerHandedness.IsMatch(handedness) == true &&
             pointer.InputSourceParent.SourceType == sourceType)
         {
             yield return(pointer);
         }
     }
 }
        private void Awake()
        {
            bool spawnControllers = false;

/*
 #if UNITY_2017_2_OR_NEWER
 *          spawnControllers = !XRDevice.isPresent && XRSettings.enabled && simulateHandsInEditor;
 #else
 *          spawnControllers = simulateHandsInEditor;
 #endif
 */
            // Hack to enable mouse clicks
            // https://github.com/Microsoft/MixedRealityToolkit-Unity/issues/1537
            spawnControllers = simulateHandsInEditor;
            if (spawnControllers)
            {
                sourceType   = InputSourceType.Hand;
                sourceNumber = InputSourceNumber.Two;
            }

            if (!spawnControllers)
            {
                return;
            }

            switch (sourceType)
            {
            case InputSourceType.Hand:
                GameObject newRightInputSource = Instantiate(rightHand);

                newRightInputSource.name = "Right_" + sourceType.ToString();
                newRightInputSource.transform.SetParent(transform);
                Inputs.Add(newRightInputSource);

                if (sourceNumber == InputSourceNumber.Two)
                {
                    GameObject newLeftInputSource = Instantiate(leftHand);
                    newLeftInputSource.name = "Left_" + sourceType.ToString();
                    newLeftInputSource.transform.SetParent(transform);
                    Inputs.Add(newLeftInputSource);
                }
                break;

            case InputSourceType.Mouse:
                GameObject newMouseInputSource = Instantiate(mouse);
                newMouseInputSource.transform.SetParent(transform);
                Inputs.Add(newMouseInputSource);

                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
 /// <inheritdoc />
 protected override bool TryRenderControllerModel(System.Type controllerType, InputSourceType inputSourceType)
 {
     if (GetControllerVisualizationProfile() == null ||
         !GetControllerVisualizationProfile().GetUsePlatformModelsOverride(GetType(), ControllerHandedness))
     {
         return(base.TryRenderControllerModel(controllerType, inputSourceType));
     }
     else
     {
         TryRenderControllerModelWithModelProvider();
         return(true);
     }
 }
Example #16
0
        private void Awake()
        {
            bool spawnControllers = false;

#if UNITY_2017_2_OR_NEWER && !UNITY_STANDALONE_WIN
            spawnControllers = !XRDevice.isPresent && XRSettings.enabled && simulateHandsInEditor;
#else
            spawnControllers = simulateHandsInEditor;
#endif

            if (spawnControllers)
            {
                sourceType   = InputSourceType.Hand;
                sourceNumber = InputSourceNumber.Two;
            }

            if (!spawnControllers)
            {
                return;
            }

            switch (sourceType)
            {
            case InputSourceType.Hand:
                GameObject newRightInputSource = Instantiate(rightHand);

                newRightInputSource.name = "Right_" + sourceType.ToString();
                newRightInputSource.transform.SetParent(transform);
                Inputs.Add(newRightInputSource);

                if (sourceNumber == InputSourceNumber.Two)
                {
                    GameObject newLeftInputSource = Instantiate(leftHand);
                    newLeftInputSource.name = "Left_" + sourceType.ToString();
                    newLeftInputSource.transform.SetParent(transform);
                    Inputs.Add(newLeftInputSource);
                }
                break;

            case InputSourceType.Mouse:
                GameObject newMouseInputSource = Instantiate(mouse);
                newMouseInputSource.transform.SetParent(transform);
                Inputs.Add(newMouseInputSource);

                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Example #17
0
 /// <summary>
 /// Tries to get the end point of a pointer by source type and handedness.
 /// If no pointer of given handedness is found, returns false and sets result to zero.
 /// </summary>
 /// <typeparam name="T">Type of pointer to query</typeparam>
 /// <param name="handedness">Handedness of pointer</param>
 /// <param name="inputType">Input type of pointer</param>
 /// <param name="endPoint">Output point position</param>
 /// <returns>True if pointer found, false otherwise. If not found, endPoint is set to zero</returns>
 public static bool TryGetPointerEndpoint <T>(Handedness handedness, InputSourceType inputType, out Vector3 endPoint) where T : IMixedRealityPointer
 {
     foreach (var pointer in GetPointers <IMixedRealityPointer>(handedness, inputType))
     {
         FocusDetails?details = pointer?.Result?.Details;
         if (details.HasValue)
         {
             endPoint = details.Value.Point;
             return(true);
         }
     }
     endPoint = Vector3.zero;
     return(false);
 }
Example #18
0
        private AudioConfig GetAudioConfig(InputSourceType inputSource, string wavFilename)
        {
            switch (inputSource)
            {
            case InputSourceType.Microphone:
                return(AudioConfig.FromDefaultMicrophoneInput());

            case InputSourceType.WavFile:
                return(AudioConfig.FromWavFileInput(wavFilename));

            default:
                throw new ArgumentException($"Unhandled InputSourceType: {inputSource}");
            }
        }
Example #19
0
 public void DisableMaps(InputSourceType i_Type, string i_Category, string i_Layout)
 {
     if (_RewiredPlayer != null)
     {
         Player.ControllerHelper controllers = _RewiredPlayer.controllers;
         if (controllers != null)
         {
             Player.ControllerHelper.MapHelper maps = controllers.maps;
             if (maps != null)
             {
                 maps.SetMapsEnabled(false, RewiredUtils.Types.GetControllerType(i_Type), i_Category, i_Layout);
             }
         }
     }
 }
Example #20
0
        /// <summary>
        /// Toggles a pointer's "enabled" behavior. If a pointer's <see cref="Microsoft.MixedReality.Toolkit.Input.PointerBehavior"/> is Default or AlwaysOn,
        /// set it to AlwaysOff. Otherwise, set the pointer's behavior to Default.
        /// Will set this state for all matching pointers.
        /// </summary>
        /// <typeparam name="T">Type of pointer to set</typeparam>
        /// <param name="inputType">Input type of pointer to set</param>
        public void TogglePointerEnabled <T>(InputSourceType inputType) where T : class, IMixedRealityPointer
        {
            PointerBehavior oldBehavior = PointerUtils.GetPointerBehavior <T>(Handedness.Any, inputType);
            PointerBehavior newBehavior;

            if (oldBehavior == PointerBehavior.AlwaysOff)
            {
                newBehavior = PointerBehavior.Default;
            }
            else
            {
                newBehavior = PointerBehavior.AlwaysOff;
            }
            PointerUtils.SetPointerBehavior <T>(newBehavior, inputType);
        }
Example #21
0
 public void EnableMaps(InputSourceType i_Type, int i_Category)
 {
     if (_RewiredPlayer != null)
     {
         Player.ControllerHelper controllers = _RewiredPlayer.controllers;
         if (controllers != null)
         {
             Player.ControllerHelper.MapHelper maps = controllers.maps;
             if (maps != null)
             {
                 maps.SetMapsEnabled(true, RewiredUtils.Types.GetControllerType(i_Type), i_Category);
             }
         }
     }
 }
Example #22
0
 public void DisableAllMapsFor(InputSourceType i_Type)
 {
     if (_RewiredPlayer != null)
     {
         Player.ControllerHelper controllers = _RewiredPlayer.controllers;
         if (controllers != null)
         {
             Player.ControllerHelper.MapHelper maps = controllers.maps;
             if (maps != null)
             {
                 maps.SetAllMapsEnabled(false, RewiredUtils.Types.GetControllerType(i_Type));
             }
         }
     }
 }
        protected override bool TryRenderControllerModel(Type controllerType, InputSourceType inputSourceType)
        {
            // Intercept this call if we are using the default driver provided models.
            // Note: Obtaining models from the driver will require access to the InteractionSource.
            // It's unclear whether the interaction source will be available during setup, so we attempt to create
            // the controller model on an input update
            if (failedToObtainControllerModel ||
                GetControllerVisualizationProfile() == null ||
                !GetControllerVisualizationProfile().GetUseDefaultModelsOverride(GetType(), ControllerHandedness))
            {
                controllerModelInitialized = true;
                return(base.TryRenderControllerModel(controllerType, inputSourceType));
            }

            return(false);
        }
        /// <summary>
        /// Gets the <seealso cref="IMixedRealityController"/> instance matching the specified source type and hand.
        /// </summary>
        /// <param name="sourceType">Type type of the input source</param>
        /// <param name="hand">The handedness of the controller</param>
        /// <param name="controller">The <seealso cref="IMixedRealityController"/> instance being returned</param>
        /// <returns>
        /// True if the controller instance is beeing returned, false otherwise.
        /// </returns>
        private static bool TryGetControllerInstance(InputSourceType sourceType, Handedness hand, out IMixedRealityController controller)
        {
            controller = null;

            foreach (IMixedRealityController c in CoreServices.InputSystem.DetectedControllers)
            {
                if ((c.InputSource?.SourceType == sourceType) &&
                    (c.ControllerHandedness == hand))
                {
                    controller = c;
                    return(true);
                }
            }

            return(false);
        }
Example #25
0
 /// <summary>
 /// Queries input system for the behavior of a given pointer type. See <seealso cref="Microsoft.MixedReality.Toolkit.Input.PointerBehavior"/>.
 /// </summary>
 /// <typeparam name="T">Type of pointer to query</typeparam>
 /// <param name="handedness">Handedness to query</param>
 /// <returns><seealso cref="Microsoft.MixedReality.Toolkit.Input.PointerBehavior"/> for the given pointer type and handedness</returns>
 public static PointerBehavior GetPointerBehavior <T>(Handedness handedness, InputSourceType inputSourceType) where T : class, IMixedRealityPointer
 {
     if (CoreServices.InputSystem.FocusProvider is IPointerPreferences preferences)
     {
         if (typeof(T) == typeof(GGVPointer))
         {
             return(preferences.GazePointerBehavior);
         }
         return(preferences.GetPointerBehavior <T>(handedness, inputSourceType));
     }
     else
     {
         WarnAboutSettingCustomPointerBehaviors();
         return(PointerBehavior.Default);
     }
 }
        public override bool Initialize(GameHost host)
        {
            if (!base.Initialize(host))
            {
                return(false);
            }

            // compute the bitmask for later use.
            foreach (var eventSource in HandledEventSources)
            {
                // ReSharper disable once BitwiseOperatorOnEnumWithoutFlags
                // (InputSourceType is a flags enum, but is not properly marked as such)
                eventSourceBitmask |= eventSource;
            }

            return(true);
        }
Example #27
0
        private void Awake()
        {
            bool spawnControllers = false;

            spawnControllers = Application.isEditor && simulateHandsInEditor;

            if (spawnControllers)
            {
                sourceType   = InputSourceType.Hand;
                sourceNumber = InputSourceNumber.Two;
            }

            if (!spawnControllers)
            {
                return;
            }

            switch (sourceType)
            {
            case InputSourceType.Hand:
                GameObject newRightInputSource = Instantiate(rightHand);

                newRightInputSource.name = "Right_" + sourceType.ToString();
                newRightInputSource.transform.SetParent(transform);
                Inputs.Add(newRightInputSource);

                if (sourceNumber == InputSourceNumber.Two)
                {
                    GameObject newLeftInputSource = Instantiate(leftHand);
                    newLeftInputSource.name = "Left_" + sourceType.ToString();
                    newLeftInputSource.transform.SetParent(transform);
                    Inputs.Add(newLeftInputSource);
                }
                break;

            case InputSourceType.Mouse:
                GameObject newMouseInputSource = Instantiate(mouse);
                newMouseInputSource.transform.SetParent(transform);
                Inputs.Add(newMouseInputSource);

                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
        /*--------------------------------------------------------------------------------------------*/
        private float GetInputSourceProgress(InputSourceType pInputSourceType,
                                             HoverInputOculusTouch.ControlState pState, float pDefault)
        {
            switch (pInputSourceType)
            {
            case InputSourceType.IndexTrigger:
                return(Mathf.InverseLerp(0, IndexTriggerMax, pState.IndexTrigger));

            case InputSourceType.HandTrigger:
                return(Mathf.InverseLerp(0, HandTriggerMax, pState.HandTrigger));

            case InputSourceType.Button1Press:
                return(pState.Button1Press ? 1 : 0);

            case InputSourceType.Button2Press:
                return(pState.Button2Press ? 1 : 0);

            case InputSourceType.StartPress:
                return(pState.StartPress ? 1 : 0);

            case InputSourceType.ThumbstickPress:
                return(pState.ThumbstickPress ? 1 : 0);

            case InputSourceType.ThumbstickY:
                return(Mathf.InverseLerp(-ThumbstickMax, ThumbstickMax, pState.ThumbstickAxis.y));

            case InputSourceType.ThumbstickUp:
                return(Mathf.InverseLerp(0, ThumbstickMax, pState.ThumbstickAxis.y));

            case InputSourceType.ThumbstickDown:
                return(Mathf.InverseLerp(0, -ThumbstickMax, pState.ThumbstickAxis.y));

            case InputSourceType.ThumbstickX:
                return(Mathf.InverseLerp(-ThumbstickMax, ThumbstickMax, pState.ThumbstickAxis.x));

            case InputSourceType.ThumbstickLeft:
                return(Mathf.InverseLerp(0, -ThumbstickMax, pState.ThumbstickAxis.x));

            case InputSourceType.ThumbstickRight:
                return(Mathf.InverseLerp(0, ThumbstickMax, pState.ThumbstickAxis.x));
            }

            return(pDefault);
        }
        /// <summary>
        /// Constructor.
        /// </summary>
        public BaseGenericInputSource(string name, IMixedRealityPointer[] pointers = null, InputSourceType sourceType = InputSourceType.Other)
        {
            SourceId   = CoreServices.InputSystem?.GenerateNewSourceId() ?? 0;
            SourceName = name;
            if (pointers != null)
            {
                Pointers = pointers;
            }
            else if (!CoreServices.InputSystem.IsNull() && !CoreServices.InputSystem.GazeProvider.IsNull() && CoreServices.InputSystem.GazeProvider.GazePointer is IMixedRealityPointer gazePointer)
            {
                Pointers = new[] { gazePointer };
            }
            else
            {
                Pointers = new IMixedRealityPointer[] { };
            }

            SourceType = sourceType;
        }
Example #30
0
        /*--------------------------------------------------------------------------------------------*/
        private float GetInputSourceProgress(InputSourceType pInputSourceType,
                                             HoverInputVive.ControlState pState, float pDefault)
        {
            switch (pInputSourceType)
            {
            case InputSourceType.Trigger:
                return(Mathf.InverseLerp(0, IndexTriggerMax, pState.TriggerAxis.x));

            case InputSourceType.TouchpadY:
                return(Mathf.InverseLerp(-TouchpadMax, TouchpadMax, pState.TouchpadAxis.y));

            case InputSourceType.TouchpadUp:
                return(Mathf.InverseLerp(0, TouchpadMax, pState.TouchpadAxis.y));

            case InputSourceType.TouchpadDown:
                return(Mathf.InverseLerp(0, -TouchpadMax, pState.TouchpadAxis.y));

            case InputSourceType.TouchpadX:
                return(Mathf.InverseLerp(-TouchpadMax, TouchpadMax, pState.TouchpadAxis.x));

            case InputSourceType.TouchpadLeft:
                return(Mathf.InverseLerp(0, -TouchpadMax, pState.TouchpadAxis.x));

            case InputSourceType.TouchpadRight:
                return(Mathf.InverseLerp(0, TouchpadMax, pState.TouchpadAxis.x));

            case InputSourceType.TouchpadTouch:
                return(pState.TouchpadTouch ? 1 : 0);

            case InputSourceType.TouchpadPress:
                return(pState.TouchpadPress ? 1 : 0);

            case InputSourceType.GripPress:
                return(pState.GripPress ? 1 : 0);

            case InputSourceType.MenuPress:
                return(pState.MenuPress ? 1 : 0);
            }

            return(pDefault);
        }