我有个预制体叫LongButton,上面挂载了CustomButton的组件,可以支持在编辑器里通过下拉菜单切换按钮的风格。但是实际运行时并没有切换,还是用的预制体的原生配色。
可以看到图1设置了2个蓝色,其中上面的是预制体,下面的取消了预制体。进入游戏之后,上面的恢复了预制体默认的颜色,下面用的是正确的颜色。
@property({ type: Enum({ Custom: 1, Default: 2, Main: 3, Warning: 4, Light: 5, Hint: 6 }), tooltip: '按钮样式' })
public buttonStyle: number = 1;
update() {
// @ts-ignore
if (!CC_EDITOR){
return;
}
const currentButtonStyle = this.numberToButtonStyle(this.buttonStyle);
if (this._buttonStyle !== currentButtonStyle) {
this._buttonStyle = currentButtonStyle;
this.setButtonStyle(currentButtonStyle);
}
}
