// 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); }
private InputControl InsertChildControl(InputTemplate template, InternedString variant, InputControl parent, ref bool haveChildrenUsingStateFromOtherControls, ref InputTemplate.ControlTemplate controlTemplate) { var path = controlTemplate.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 template '{2}'", immediateParentPath, controlTemplate.name, template.name)); } var controlName = path.Substring(indexOfSlash + 1); if (controlName.Length == 0) { throw new Exception( string.Format("Path cannot end in '/' (control '{0}' in template '{1}')", controlTemplate.name, template.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(template, variant, immediateParent, null, ref haveChildrenUsingStateFromOtherControls, ref controlTemplate, 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)); } }