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;
|
|
|
|
}
|
|
|
|
}
|