/// <inheritdoc /> protected override GenericJoystickController GetOrAddController(string joystickName) { Debug.Assert(!string.IsNullOrEmpty(joystickName), "Joystick name is invalid!"); // If a device is already registered with the ID provided, just return it. if (ActiveGenericControllers.ContainsKey(joystickName)) { var controller = ActiveGenericControllers[joystickName]; Debug.Assert(controller != null); return(controller); } Handedness handedness; if (joystickName.Contains("Left")) { handedness = Handedness.Left; } else if (joystickName.Contains("Right")) { handedness = Handedness.Right; } else { handedness = Handedness.None; } var controllerType = GetCurrentControllerType(joystickName); GenericOpenVRController detectedController; try { detectedController = Activator.CreateInstance(controllerType, this, TrackingState.NotTracked, handedness, GetControllerMappingProfile(controllerType, handedness)) as GenericOpenVRController; } catch (Exception e) { Debug.LogError(e); return(null); } if (detectedController == null) { Debug.LogError($"Failed to create {controllerType.Name}"); return(null); } detectedController.TryRenderControllerModel(); ActiveGenericControllers.Add(joystickName, detectedController); AddController(detectedController); return(detectedController); }
/// <inheritdoc /> protected override GenericJoystickController GetOrAddController(string joystickName) { // If a device is already registered with the ID provided, just return it. if (ActiveGenericControllers.ContainsKey(joystickName)) { var controller = ActiveGenericControllers[joystickName]; Debug.Assert(controller != null); return(controller); } Handedness controllingHand; if (joystickName.Contains("Left")) { controllingHand = Handedness.Left; } else if (joystickName.Contains("Right")) { controllingHand = Handedness.Right; } else { controllingHand = Handedness.None; } var currentControllerType = GetCurrentControllerType(joystickName); Type controllerType; switch (currentControllerType) { case SupportedControllerType.GenericOpenVR: controllerType = typeof(GenericOpenVRController); break; case SupportedControllerType.ViveWand: controllerType = typeof(ViveWandOpenVRController); break; case SupportedControllerType.ViveKnuckles: controllerType = typeof(ViveKnucklesOpenVRController); break; case SupportedControllerType.OculusTouch: controllerType = typeof(OculusTouchOpenVRController); break; case SupportedControllerType.OculusRemote: controllerType = typeof(OculusRemoteOpenVRController); break; case SupportedControllerType.OculusGo: controllerType = typeof(OculusGoOpenVRController); break; case SupportedControllerType.WindowsMixedReality: controllerType = typeof(WindowsMixedRealityOpenVRMotionController); break; default: return(null); } var pointers = RequestPointers(controllerType, controllingHand); var inputSource = MixedRealityToolkit.InputSystem?.RequestNewGenericInputSource($"{currentControllerType} Controller {controllingHand}", pointers); var detectedController = Activator.CreateInstance(controllerType, TrackingState.NotTracked, controllingHand, inputSource, null) as GenericOpenVRController; if (detectedController == null) { Debug.LogError($"Failed to create {controllerType.Name} controller"); return(null); } if (!detectedController.SetupConfiguration(controllerType)) { // Controller failed to be setup correctly. // Return null so we don't raise the source detected. Debug.LogError($"Failed to Setup {controllerType.Name} controller"); return(null); } for (int i = 0; i < detectedController.InputSource?.Pointers?.Length; i++) { detectedController.InputSource.Pointers[i].Controller = detectedController; } detectedController.TryRenderControllerModel(controllerType); ActiveGenericControllers.Add(joystickName, detectedController); AddController(detectedController); return(detectedController); }