lcc-ui-sorting-group-demo/assets/lcc-ui-sorting-group/sorting-group.ts

39 lines
1.1 KiB
TypeScript
Raw Normal View History

2023-02-05 12:31:26 +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')
@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;
private _uiTransform:UITransform = null;
2023-02-05 12:31:26 +00:00
onLoad(){
this._uiTransform = this.getComponent(UITransform);
2023-02-05 12:31:26 +00:00
}
onEnable(){
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(){
this._uiTransform.sortingPriority = 0;
this._uiTransform.sortingEnabled = false;
2023-02-05 12:31:26 +00:00
}
}