Creator 2.2.2 版本,按钮的过渡状态设置为Button.Transition.SCALE,设置enableAutoGrayEffect为true的情况下,修改按钮是交互interactable为false,按钮不会灰掉,查了引擎代码发现 :_updateDisabledState 函数里面的this._sprite对象为null导致后面的置灰未生效,不知道这算不算bug,还是说我用法有问题?将interactable属性的notify里面先调用this._resetState();然后再this._updateState();可以确保this._sprite不为null也就正常了,不知道官方是出于什么考虑这样做?
interactable: {
default: true,
tooltip: CC_DEV && ‘i18n:COMPONENT.button.interactable’,
notify () {
this._updateState();
if (!this.interactable) {
this._resetState();
}
},
animatable: false
},
_updateDisabledState () {
if (this._sprite) {
let useGrayMaterial = false;
if (this.enableAutoGrayEffect) {
if (!(this.transition === Transition.SPRITE && this.disabledSprite)) {
if (!this.interactable) {
useGrayMaterial = true;
}
}
}
this._switchGrayMaterial(useGrayMaterial, this._sprite);
}
}