public bool TryGetDevice <D>(out InputDeviceController <T, D> controller) where D : InputDevice { if (_registeredControllers.TryGetValue(typeof(D), out InputDeviceController <T> c)) { if (!(c is InputDeviceController <T, D> definedC)) { throw new System.InvalidOperationException($"Registered InputDeviceController<{typeof(T)}>, at device type '{typeof(D).Name}', isn't of requested type 'InputDeviceController<{typeof(T)}, {typeof(D)}>'.\nIt's type is '{c.GetType()}'."); } controller = definedC; return(true); } controller = null; return(false); }
public InputDeviceController <T, D> RegisterDevice <D>() where D : InputDevice, new() { if (_registeredControllers.ContainsKey(typeof(D))) { throw new System.ArgumentException($"Device '{typeof(D).Name}' is already registered. Duplicated entries isn't allowed."); } InputDeviceController <T, D> controller = new InputDeviceController <T, D>(new D()); controller.OnBackInterfaceAdded += DeviceControllerBackInterfaceAdded; controller.OnBackInterfaceRemoved += DeviceControllerBackInterfaceRemoved; _controllers.Add(controller); _registeredControllers.Add(typeof(D), controller); return(controller); }
public bool BlockDevice <D>() { for (int i = 0; i < _controllers.Count; i++) { InputDeviceController <T> controller = _controllers[i]; if (controller.InputDevice is D) { _blockedControllers.Add(controller); _controllers.RemoveAt(i); controller.Disable(); return(true); } } return(false); }