lcc-ui-sorting-group-demo/assets/lcc-ui-sorting-group/sorting-group.ts
2023-02-05 20:31:26 +08:00

39 lines
1.1 KiB
TypeScript

import { _decorator, Component, Node, ccenum, CCInteger, CCFloat, Enum, director, UI, UIRenderer } from 'cc';
import { ORDER_IN_LAYER_MAX, SortingLayer } from './sorting-define';
const { ccclass, property, type, disallowMultiple, requireComponent } = _decorator;
@ccclass('lcc-ui/SortingGroup')
@requireComponent(UIRenderer)
@disallowMultiple
export class SortingGroup extends Component {
/**
* 排序层
*/
@type(Enum(SortingLayer))
sortingLayer:SortingLayer = SortingLayer.DEFAULT;
/**
* 排序值
*/
@property({ type:CCFloat, min: 0, max : ORDER_IN_LAYER_MAX })
orderInLayer:number = 0;
/**
* UI渲染器
*/
private _uiRenderer:UIRenderer = null;
onLoad(){
this._uiRenderer = this.getComponent(UIRenderer);
}
onEnable(){
this._uiRenderer.sortingPriority = Math.sign(this.sortingLayer) * (Math.abs(this.sortingLayer) * ORDER_IN_LAYER_MAX + this.orderInLayer);
}
onDisable(){
this._uiRenderer.sortingPriority = SortingLayer.DEFAULT * ORDER_IN_LAYER_MAX;
}
}