fix _getDependComponent (#13968)

This commit is contained in:
江战
2022-12-30 09:48:14 +08:00
committed by GitHub
parent 141189efab
commit 0f3802bfbc
+29 -29
View File
@@ -33,7 +33,7 @@ const Destroying = CCObject.Flags.Destroying;
const IS_PREVIEW = !!legacyCC.GAME_VIEW;
export function nodePolyfill (Node) {
if ((EDITOR && !IS_PREVIEW) || TEST) {
if (EDITOR || TEST) {
Node.prototype._checkMultipleComp = function (ctor) {
const existing = this.getComponent(ctor._disallowMultiple);
if (existing) {
@@ -45,7 +45,34 @@ export function nodePolyfill (Node) {
}
return true;
};
/**
* @method _getDependComponent
* @param {Component} depended
* @return {Component[]}
*/
Node.prototype._getDependComponent = function (depended) {
const dependant: Component[] = [];
for (let i = 0; i < this._components.length; i++) {
const comp = this._components[i];
if (comp !== depended && comp.isValid && !legacyCC.Object._willDestroy(comp)) {
const reqComps = comp.constructor._requireComponent;
if (reqComps) {
if (Array.isArray(reqComps)) {
for (let i = 0; i < reqComps.length; i++) {
if (depended instanceof reqComps[i]) {
dependant.push(comp);
}
}
} else if (depended instanceof reqComps) {
dependant.push(comp);
}
}
}
}
return dependant;
};
}
if ((EDITOR && !IS_PREVIEW) || TEST) {
/**
* This api should only used by undo system
* @method _addComponentAt
@@ -99,33 +126,6 @@ export function nodePolyfill (Node) {
return undefined;
};
/**
* @method _getDependComponent
* @param {Component} depended
* @return {Component[]}
*/
Node.prototype._getDependComponent = function (depended) {
const dependant: Component[] = [];
for (let i = 0; i < this._components.length; i++) {
const comp = this._components[i];
if (comp !== depended && comp.isValid && !legacyCC.Object._willDestroy(comp)) {
const reqComps = comp.constructor._requireComponent;
if (reqComps) {
if (Array.isArray(reqComps)) {
for (let i = 0; i < reqComps.length; i++) {
if (depended instanceof reqComps[i]) {
dependant.push(comp);
}
}
} else if (depended instanceof reqComps) {
dependant.push(comp);
}
}
}
}
return dependant;
};
Node.prototype.onRestore = function () {
// check activity state
const shouldActiveNow = this._active && !!(this._parent && this._parent._activeInHierarchy);