public void _reparent(FocusNode child) { D.assert(child != null); D.assert(child != this, () => "Tried to make a child into a parent of itself."); if (child._parent == this) { D.assert(_children.Contains(child), () => "Found a node that says it's a child, but doesn't appear in the child list."); // The child is already a child of this parent. return; } D.assert(_manager == null || child != _manager.rootScope, () => "Reparenting the root node isn't allowed."); D.assert(!ancestors.Contains(child), () => "The supplied child is already an ancestor of this node. Loops are not allowed."); FocusScopeNode oldScope = child.enclosingScope; bool hadFocus = child.hasFocus; child._parent?._removeChild(child, removeScopeFocus: oldScope != nearestScope); _children.Add(child); child._parent = this; child._ancestors = null; child._updateManager(_manager); foreach (FocusNode ancestor in child.ancestors) { ancestor._descendants = null; } if (hadFocus) { _manager?.primaryFocus?._setAsFocusedChildForScope(); } if (oldScope != null && child.context != null && child.enclosingScope != oldScope) { //UnityEngine.Debug.Log("FocusTraversalGroup.of(child.context, nullOk: true)?.changedScope(node: child, oldScope: oldScope);"); FocusTraversalGroup.of(child.context, nullOk: true)?.changedScope(node: child, oldScope: oldScope); } if (child._requestFocusWhenReparented) { child._doRequestFocus(findFirstFocus: true); child._requestFocusWhenReparented = false; } }
public void requestFocus(FocusNode node = null) { if (node != null) { if (node._parent == null) { _reparent(node); } D.assert(node.ancestors.Contains(this), () => "Focus was requested for a node that is not a descendant of the scope from which it was requested."); node._doRequestFocus(findFirstFocus: true); return; } _doRequestFocus(findFirstFocus: true); }