// 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); }
public InputControl TryGetChildControl(string path) { if (string.IsNullOrEmpty(path)) { throw new ArgumentNullException("path"); } return(InputControlPath.TryFindChild(this, path)); }
/// <summary> /// Fetch a control from the control's hierarchy by name. /// </summary> /// <remarks> /// Note that path matching is case-insensitive. /// </remarks> /// <example> /// <code> /// gamepad["leftStick"] // Returns Gamepad.leftStick /// gamepad["leftStick/x"] // Returns Gamepad.leftStick.x /// gamepad["{PrimaryAction}"] // Returns the control with PrimaryAction usage, i.e. Gamepad.aButton /// </code> /// </example> /// <exception cref="IndexOutOfRangeException"><paramref name="path"/> cannot be found.</exception> /// <seealso cref="InputControlPath"/> /// <seealso cref="path"/> /// <seealso cref="TryGetChildControl"/> public InputControl this[string path] { get { var control = InputControlPath.TryFindChild(this, path); if (control == null) { throw new IndexOutOfRangeException( string.Format("Cannot find control '{0}' as child of '{1}'", path, this)); } return(control); } }
private InputControl InsertChildControl(InputControlLayout layout, InternedString variant, InputControl parent, ref bool haveChildrenUsingStateFromOtherControls, ref InputControlLayout.ControlItem controlItem) { var path = controlItem.name.ToString(); // First we need to find the immediate parent from the given path. var indexOfSlash = path.LastIndexOf('/'); if (indexOfSlash == -1) { throw new ArgumentException("InsertChildControl has to be called with a slash-separated path", "path"); } Debug.Assert(indexOfSlash != 0); var immediateParentPath = path.Substring(0, indexOfSlash); var immediateParent = InputControlPath.TryFindChild(parent, immediateParentPath); if (immediateParent == null) { throw new Exception( string.Format("Cannot find parent '{0}' of control '{1}' in layout '{2}'", immediateParentPath, controlItem.name, layout.name)); } var controlName = path.Substring(indexOfSlash + 1); if (controlName.Length == 0) { throw new Exception( string.Format("Path cannot end in '/' (control '{0}' in layout '{1}')", controlItem.name, layout.name)); } // Make room in the device's child array. var childStartIndex = immediateParent.m_ChildrenReadOnly.m_StartIndex; var childIndex = childStartIndex + immediateParent.m_ChildrenReadOnly.m_Length; ArrayHelpers.InsertAt(ref m_Device.m_ChildrenForEachControl, childIndex, null); ++immediateParent.m_ChildrenReadOnly.m_Length; // Insert the child. var control = AddChildControl(layout, variant, immediateParent, null, ref haveChildrenUsingStateFromOtherControls, ref controlItem, ref childIndex, controlName); // Adjust indices of control's that have been shifted around by our insertion. ShiftChildIndicesInHierarchyOneUp(parent, childIndex); return(control); }
public InputControl this[string path] { get { return(InputControlPath.TryFindChild(this, path)); } }