public bool TryInitializeWithDevices(IEnumerable <InputDevice> availableDevices) { int bestScheme = -1; List <InputDevice> bestFoundDevices = null; float mostRecentTime = -1; List <InputDevice> foundDevices = new List <InputDevice>(); for (int scheme = 0; scheme < actionMap.controlSchemes.Count; scheme++) { float timeForScheme = -1; foundDevices.Clear(); var types = actionMap.controlSchemes[scheme].deviceTypes; bool matchesAll = true; foreach (var type in types) { InputDevice foundDevice = null; float foundDeviceTime = -1; foreach (var device in availableDevices) { if (type.IsInstanceOfType(device) && device.lastEventTime > foundDeviceTime) { foundDevice = device; foundDeviceTime = device.lastEventTime; } } if (foundDevice != null) { foundDevices.Add(foundDevice); timeForScheme = Mathf.Max(timeForScheme, foundDeviceTime); } else { matchesAll = false; break; } } if (!matchesAll) { continue; } // If we reach this point we know that control scheme both matches required and matches all. if (timeForScheme > mostRecentTime) { bestScheme = scheme; bestFoundDevices = new List <InputDevice>(foundDevices); mostRecentTime = timeForScheme; } } if (bestScheme == -1) { return(false); } ControlScheme matchingControlScheme = actionMap.controlSchemes[bestScheme]; Assign(matchingControlScheme, bestFoundDevices); return(true); }
void AssignDeviceProfile(InputDevice device) { device.profile = FindDeviceProfile(device); }
public void RegisterDevice(InputDevice device) { AssignDeviceProfile(device); RegisterDeviceInternal(device.GetType(), device); HandleDeviceConnectDisconnect(device, true); }