40 lines
1.1 KiB
TypeScript
Raw Normal View History

2023-02-05 20:31:26 +08:00
import { _decorator, Component, Node, ccenum, CCInteger, CCFloat, Enum, director, UI, UIRenderer } from 'cc';
2023-02-05 22:15:34 +08:00
import { DEFAULT_SORTING_PRIORITY, ORDER_IN_LAYER_MAX, SortingLayer } from './sorting-define';
2023-02-06 09:40:30 +08:00
const { ccclass, property, type, disallowMultiple, requireComponent, executeInEditMode } = _decorator;
2023-02-05 20:31:26 +08:00
@ccclass('lcc-ui/SortingGroup')
@requireComponent(UIRenderer)
2023-02-06 09:40:30 +08:00
@disallowMultiple(true)
@executeInEditMode(true)
2023-02-05 20:31:26 +08:00
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(){
2023-02-05 22:15:34 +08:00
this._uiRenderer.sortingPriority = DEFAULT_SORTING_PRIORITY;
2023-02-05 20:31:26 +08:00
}
}