setSiblingIndex 作用有限 不够灵活!
看看引擎中setSiblingIndex的源码,真的不知道说什么了!!!!!
/**
* @en Set the sibling index of the current node in its parent’s children array.
* @zh 设置当前节点在父节点的 children 数组中的位置。
*/
public setSiblingIndex (index: number) {
if (!this._parent) {
return;
}
if (this._parent._objFlags & Deactivating) {
errorID(3821);
return;
}
const siblings = this._parent._children;
index = index !== -1 ? index : siblings.length - 1;
const oldIndex = siblings.indexOf(this);
if (index !== oldIndex) {
siblings.splice(oldIndex, 1);
if (index < siblings.length) {
siblings.splice(index, 0, this);
} else {
siblings.push(this);
}
this._parent._updateSiblingIndex();
if (this._onSiblingIndexChanged) {
this._onSiblingIndexChanged(index);
}
this._eventProcessor.onUpdatingSiblingIndex();
}
}
/**
* @deprecated since v3.5.0, this is an engine private interface that will be removed in the future.
*/
public _updateSiblingIndex () {
for (let i = 0; i < this._children.length; ++i) {
this._children[i]._siblingIndex = i;
}
this.emit(NodeEventType.SIBLING_ORDER_CHANGED);
}
如果我想让某一对象永远置顶,只能希望后面不再添加新的节点! 这是什么逻辑?
我试了下,在3.73的版本里面 我所有的节点都是动态生成的 无论怎么设置或者改变节点添加的顺序,排序就是达不到想要的样子(正确的顺序)。 是不是还有什么骚操作没有执行!