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

56 lines
1.6 KiB
TypeScript
Raw Normal View History

2023-02-09 09:25:08 +00:00
import { ORDER_IN_LAYER_MAX, SortingLayer } from './sorting-define';
const { ccclass, property, disallowMultiple, executeInEditMode } = cc._decorator;
@ccclass('lcc-ui/SortingGroup')
@disallowMultiple()
@executeInEditMode()
export class SortingGroup extends cc.Component {
/**
*
*/
@property({type: cc.Enum(SortingLayer)})
private _sortingLayer:SortingLayer = SortingLayer.DEFAULT;
/**
*
*/
@property({type: cc.Enum(SortingLayer)})
get sortingLayer(){
return this._sortingLayer;
}
set sortingLayer(value:SortingLayer){
this._sortingLayer = value;
2023-03-21 15:04:26 +00:00
this.node.sortingPriority = Math.sign(this._sortingLayer) * (Math.abs(this._sortingLayer) * ORDER_IN_LAYER_MAX + this._orderInLayer);
2023-02-09 09:25:08 +00:00
}
/**
*
*/
@property({ type:cc.Float, min: 0, max : ORDER_IN_LAYER_MAX })
private _orderInLayer:number = 0;
/**
*
*/
@property({ type:cc.Float, min: 0, max : ORDER_IN_LAYER_MAX })
get orderInLayer(){
return this._orderInLayer;
}
set orderInLayer(value:number){
this._orderInLayer = value;
2023-03-21 15:04:26 +00:00
this.node.sortingPriority = Math.sign(this._sortingLayer) * (Math.abs(this._sortingLayer) * ORDER_IN_LAYER_MAX + this._orderInLayer);
2023-02-09 09:25:08 +00:00
}
onEnable(){
this.node.sortingPriority = Math.sign(this._sortingLayer) * (Math.abs(this._sortingLayer) * ORDER_IN_LAYER_MAX + this._orderInLayer);
this.node.sortingEnabled = true;
}
onDisable(){
this.node.sortingPriority = 0;
this.node.sortingEnabled = false;
}
}