2023-02-05 12:31:26 +00:00
|
|
|
|
2023-02-07 16:33:52 +00:00
|
|
|
import { _decorator, Component, Node, ccenum, CCInteger, CCFloat, Enum, director, UI, UIRenderer, UITransform } from 'cc';
|
|
|
|
import { ORDER_IN_LAYER_MAX, SortingLayer } from './sorting-define';
|
2023-02-06 01:40:30 +00:00
|
|
|
const { ccclass, property, type, disallowMultiple, requireComponent, executeInEditMode } = _decorator;
|
2023-02-05 12:31:26 +00:00
|
|
|
|
|
|
|
@ccclass('lcc-ui/SortingGroup')
|
2023-02-07 16:33:52 +00:00
|
|
|
@requireComponent(UITransform)
|
2023-02-06 01:40:30 +00:00
|
|
|
@disallowMultiple(true)
|
|
|
|
@executeInEditMode(true)
|
2023-02-05 12:31:26 +00: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;
|
|
|
|
|
2023-02-07 16:33:52 +00:00
|
|
|
private _uiTransform:UITransform = null;
|
2023-02-05 12:31:26 +00:00
|
|
|
|
|
|
|
onLoad(){
|
2023-02-07 16:33:52 +00:00
|
|
|
this._uiTransform = this.getComponent(UITransform);
|
2023-02-05 12:31:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
onEnable(){
|
2023-02-07 16:33:52 +00:00
|
|
|
this._uiTransform.sortingPriority = Math.sign(this.sortingLayer) * (Math.abs(this.sortingLayer) * ORDER_IN_LAYER_MAX + this.orderInLayer);
|
|
|
|
this._uiTransform.sortingEnabled = true;
|
2023-02-05 12:31:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
onDisable(){
|
2023-02-07 16:33:52 +00:00
|
|
|
this._uiTransform.sortingPriority = 0;
|
|
|
|
this._uiTransform.sortingEnabled = false;
|
2023-02-05 12:31:26 +00:00
|
|
|
}
|
|
|
|
}
|