private void RefreshDevices() { Profiler.BeginSample("[MRTK] UnityJoystickManager.RefreshDevices"); IMixedRealityInputSystem inputSystem = Service as IMixedRealityInputSystem; var joystickNames = UInput.GetJoystickNames(); if (joystickNames.Length <= 0) { Profiler.EndSample(); // RefreshDevices - no devices return; } if (lastDeviceList != null && joystickNames.Length == lastDeviceList.Length) { for (int i = 0; i < lastDeviceList.Length; i++) { if (joystickNames[i].Equals(lastDeviceList[i])) { continue; } if (ActiveControllers.ContainsKey(lastDeviceList[i])) { var controller = GetOrAddController(lastDeviceList[i]); if (controller != null) { inputSystem?.RaiseSourceLost(controller.InputSource, controller); } RemoveController(lastDeviceList[i]); } } } for (var i = 0; i < joystickNames.Length; i++) { if (string.IsNullOrEmpty(joystickNames[i])) { continue; } if (!ActiveControllers.ContainsKey(joystickNames[i])) { var controller = GetOrAddController(joystickNames[i]); if (controller != null) { inputSystem?.RaiseSourceDetected(controller.InputSource, controller); } } } lastDeviceList = joystickNames; Profiler.EndSample(); // RefreshDevices }
private void RefreshDevices() { IMixedRealityInputSystem inputSystem = Service as IMixedRealityInputSystem; var joystickNames = UInput.GetJoystickNames(); if (joystickNames.Length <= 0) { return; } if (lastDeviceList != null && joystickNames.Length == lastDeviceList.Length) { for (int i = 0; i < lastDeviceList.Length; i++) { if (joystickNames[i].Equals(lastDeviceList[i])) { continue; } if (ActiveControllers.ContainsKey(lastDeviceList[i])) { var controller = GetOrAddController(lastDeviceList[i]); if (controller != null) { inputSystem?.RaiseSourceLost(controller.InputSource, controller); } ActiveControllers.Remove(lastDeviceList[i]); } else { Debug.Log("Controller does not contains kye"); } } } for (var i = 0; i < joystickNames.Length; i++) { if (string.IsNullOrEmpty(joystickNames[i])) { continue; } if (!ActiveControllers.ContainsKey(joystickNames[i])) { var controller = GetOrAddController(joystickNames[i]); if (controller != null) { inputSystem?.RaiseSourceDetected(controller.InputSource, controller); } } } lastDeviceList = joystickNames; }
private void RefreshDevices() { using (RefreshDevicesPerfMarker.Auto()) { var joystickNames = UInput.GetJoystickNames(); if (joystickNames.Length <= 0) { return; } if (lastDeviceList != null && joystickNames.Length == lastDeviceList.Length) { for (int i = 0; i < lastDeviceList.Length; i++) { if (joystickNames[i].Equals(lastDeviceList[i])) { continue; } if (ActiveControllers.ContainsKey(lastDeviceList[i])) { var controller = GetOrAddController(lastDeviceList[i]); if (controller != null) { Service?.RaiseSourceLost(controller.InputSource, controller); } RemoveController(lastDeviceList[i]); } } } for (var i = 0; i < joystickNames.Length; i++) { if (string.IsNullOrEmpty(joystickNames[i])) { continue; } if (!ActiveControllers.ContainsKey(joystickNames[i])) { var controller = GetOrAddController(joystickNames[i]); if (controller != null) { Service?.RaiseSourceDetected(controller.InputSource, controller); } } } lastDeviceList = joystickNames; } }
void Awake() { string[] szJoysticks = UInput.GetJoystickNames(); Joysticks = new List <JoystickBinding>(); // get a binding of all the joysticks int nIndex = 0; foreach (string joystick in szJoysticks) { if (joystick != "" && !joystick.ToLower().Contains("vjoy")) { Joysticks.Add(new JoystickBinding(false, nIndex, joystick)); } nIndex++; } }
private void InitializeJoystickInputs() { #if UNITY_EDITOR || USE_JOYSTICK_AS_MAIN_CONTROLLER string[] joystickNames = UInput.GetJoystickNames(); Debug.Log(string.Format("[Controller] detected {0} joysticks", joystickNames.Length)); for (int i = 0; i < joystickNames.Length; ++i) { Debug.Log(i + " " + joystickNames[i]); } for (int i = 0; i < joystickNames.Length && m_inputList.Count < MAX_CONTROLLER; ++i) { JoystickInput input = new JoystickInput(); input.SetInputIndex(i); input.SetJoystickType(joystickNames[i]); m_inputList.Add(input); Debug.Log(m_inputList.Count + " controller added: " + input.ToString()); } #endif }