private ControlSchemeSyntax AndAssignDevicesInternal(bool addMissingOnly) { var matchResult = new InputControlScheme.MatchResult(); try { return(AndAssignDevicesInternal(out matchResult, addMissingOnly: addMissingOnly)); } finally { matchResult.Dispose(); } }
private ControlSchemeSyntax AndAssignDevicesInternal(out InputControlScheme.MatchResult matchResult, bool addMissingOnly) { matchResult = new InputControlScheme.MatchResult(); // If we are currently assigned devices and we're supposed to assign devices from scratch, // unassign what we have first. var needToNotifyAboutChangedDevices = false; if (!addMissingOnly && s_AllUserData[m_UserIndex].deviceCount > 0) { ClearAssignedInputDevicesInternal(m_UserIndex); needToNotifyAboutChangedDevices = true; } // Nothing to do if we don't have a control scheme. if (!s_AllUserData[m_UserIndex].controlScheme.HasValue) { return(this); } // Look for matching devices now which aren't used by any other user. // Only go through the matching process if we actually have device requirements. var scheme = s_AllUserData[m_UserIndex].controlScheme.Value; if (scheme.deviceRequirements.Count > 0) { // Grab all unused devices and then select a set of devices matching the scheme's // requirements. using (var availableDevices = GetUnassignedInputDevices()) { // If we're only supposed to add missing devices, we need to take the devices already // already assigned to the user into account when picking devices. Add them to the beginning // of the list so that they get matched first. if (addMissingOnly) { availableDevices.AddSlice(s_AllUsers[m_UserIndex].GetAssignedInputDevices(), destinationIndex: 0); } matchResult = scheme.PickDevicesFrom(availableDevices); if (matchResult.isSuccessfulMatch) { // Control scheme is satisfied with the devices we have available. // Assign selected devices to user. foreach (var device in matchResult.devices) { if (AssignDeviceInternal(m_UserIndex, device)) { needToNotifyAboutChangedDevices = true; } } } else { // Control scheme isn't satisfied with the devices we got. m_Failure = true; } } } if (needToNotifyAboutChangedDevices) { Notify(s_AllUsers[m_UserIndex], InputUserChange.DevicesChanged); } return(this); }
public ControlSchemeSyntax AndAssignMissingDevices(out InputControlScheme.MatchResult matchResult) { return(AndAssignDevicesInternal(out matchResult, addMissingOnly: true)); }