编辑器版本2.4.11,
我在一个节点上加了两个相同的组件FairyTest,这个组件可以通过动态设置_states: string[]然后自动动态设置_state的枚举类型,现在遇到的问题是当设置第二个FairyTest以后,调用cc.Class.Attr.setClassAttr(this, ‘state’, ‘enumList’, array);这个去设置枚举类型的时候,他会把另外一个的也改写了,这有办法解决吗,(如下图所示,测试代码也贴在下面了)(下图第一个FairyTest的state期望显示为 “0:顶层”)

const { ccclass, property, executeInEditMode, menu } = cc._decorator;
@ccclass
@executeInEditMode
@menu(“Fairy/FairyTest(ceshi)”)
export class FairyTest extends cc.Component {
@property({serializable: true})
_uid = "";
@property
get uid() {
return this._uid;
}
set uid(val: string) {
this._uid = val;
}
_state = 0;
@property({type: cc.Enum({})})
get state() {
return this._state;
}
set state(val: number) {
this._state = val;
}
@property
_states: string[] = [];
@property([cc.String])
get states() {
return this._states;
}
set states(states: string[]) {
this._states = states;
this._refresh();
}
onLoad () {
this._refresh();
}
update = CC_EDITOR ? ()=> {
if (this.nextUpdateTime && Date.now() > this.nextUpdateTime) {
this.nextUpdateTime = null;
Editor.Utils.refreshSelectedInspector('node', this.node.uuid);
}
} : null;
nextUpdateTime = CC_EDITOR ? 0 : null;
private _refresh() {
if(CC_EDITOR) {
let array = this._states.map((val, i) => {
return {name: `${i}: ${val}` , value: i};
});
//@ts-ignore
cc.Class.Attr.setClassAttr(this, 'state', 'enumList', array);
//@ts-ignore
// Editor.Utils.refreshSelectedInspector('node', this.node.uuid);
// 改为不要那么频繁刷新
this.nextUpdateTime = Date.now() + 5000;
}
}
}