Files
cocos4/cocos/ui/components/ui-opacity-component.ts
T
JoneLau 7fc9bdefc0 add file of additional properties and transparency downward (#5948)
* add file of additional properties and transparency downward

* remove unless function
2019-12-23 23:46:59 +08:00

38 lines
974 B
TypeScript

import { Component } from '../../core/components/component';
import { ccclass, executeInEditMode, executionOrder, menu, property } from '../../core/data/class-decorator';
/**
* @zh UI 透明度设置组件。可以通过该组件设置透明度来影响后续的渲染节点。已经带有渲染组件的节点可以直接修改 color 的 alpha 通道。
*/
@ccclass('cc.UIOpacityComponent')
@executionOrder(110)
@menu('UI/UIOpacity')
@executeInEditMode
export class UIOpacityComponent extends Component {
@property
get opacity () {
return this._opacity;
}
set opacity (value) {
if (this._opacity === value) {
return;
}
this._opacity = value;
this.node._uiProps.opacity = value / 255;
}
@property
protected _opacity = 255;
public onEnable () {
this.node._uiProps.opacity = this._opacity / 255;
}
public onDisable (){
this.node._uiProps.opacity = 1;
}
}