// Look up a direct or indirect child control. public InputControl TryGetControl(InputControl parent, string path) { if (string.IsNullOrEmpty(path)) { throw new ArgumentException("path"); } if (m_Device == null) { return(null); } if (parent == null) { parent = m_Device; } var match = InputControlPath.TryFindChild(parent, path); if (match != null) { return(match); } if (ReferenceEquals(parent, m_Device)) { return(InputControlPath.TryFindControl(m_Device, string.Format("{0}/{1}", m_Device.name, path))); } return(null); }
// For all bindings in the given action, if a binding matches a control in the given control // hiearchy, set an override on the binding to refer specifically to that control. // // Returns the number of overrides that have been applied. // // Use case: Say you have a local co-op game and a single action set that represents the // actions of any single player. To end up with action sets that are specific to // a certain player, you could, for example, clone the action set four times, and then // take four gamepad devices and use the methods here to have bindings be overridden // on each set to refer to a specific gamepad instance. // // Another example is having two XRControllers and two action sets can be on either hand. // At runtime you can dynamically override and re-override the bindings on the action sets // to use them with the controllers as desired. public static int ApplyOverridesUsingMatchingControls(this InputAction action, InputControl control) { if (action == null) { throw new ArgumentNullException("action"); } if (control == null) { throw new ArgumentNullException("control"); } var bindings = action.bindings; var bindingsCount = bindings.Count; var numMatchingControls = 0; for (var i = 0; i < bindingsCount; ++i) { var matchingControl = InputControlPath.TryFindControl(control, bindings[i].path); if (matchingControl == null) { continue; } action.ApplyBindingOverride(i, matchingControl.path); ++numMatchingControls; } return(numMatchingControls); }