[engine] 优化 cc.Button 性能,interactable 未改变时不进行材质切换,减少 update 时需执行的逻辑

This commit is contained in:
SmallMain 2024-11-21 18:21:04 +08:00
parent f853ea7da3
commit a14c457602
No known key found for this signature in database

View File

@ -184,12 +184,14 @@ let Button = cc.Class({
interactable: {
default: true,
tooltip: CC_DEV && 'i18n:COMPONENT.button.interactable',
notify () {
notify (oldValue) {
if (oldValue !== this.interactable) {
this._updateState();
if (!this.interactable) {
this._resetState();
}
}
},
animatable: false
},
@ -581,7 +583,6 @@ let Button = cc.Class({
},
update (dt) {
let target = this._getTarget();
if (this._transitionFinished) return;
if (this.transition !== Transition.COLOR && this.transition !== Transition.SCALE) return;
@ -602,6 +603,7 @@ let Button = cc.Class({
}
// Skip if _originalScale is invalid
else if (this.transition === Transition.SCALE && this._originalScale) {
let target = this._getTarget();
target.scale = this._fromScale.lerp(this._toScale, ratio);
}