63 lines
1.9 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, UITransform } from 'cc';
import { 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(UITransform)
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))
2023-02-08 10:43:36 +08:00
private _sortingLayer:SortingLayer = SortingLayer.DEFAULT;
2023-02-05 20:31:26 +08:00
2023-02-08 10:43:36 +08:00
/**
*
*/
@type(Enum(SortingLayer))
get sortingLayer(){
return this._sortingLayer;
}
set sortingLayer(value:SortingLayer){
this._sortingLayer = value;
this._uiTransform.sortingPriority = Math.sign(this._sortingLayer) * (Math.abs(this._sortingLayer) * ORDER_IN_LAYER_MAX + this._orderInLayer);
}
2023-02-05 20:31:26 +08:00
/**
*
*/
@property({ type:CCFloat, min: 0, max : ORDER_IN_LAYER_MAX })
2023-02-08 10:43:36 +08:00
private _orderInLayer:number = 0;
/**
*
*/
@property({ type:CCFloat, min: 0, max : ORDER_IN_LAYER_MAX })
get orderInLayer(){
return this._orderInLayer;
}
set orderInLayer(value:number){
this._orderInLayer = value;
this._uiTransform.sortingPriority = Math.sign(this._sortingLayer) * (Math.abs(this._sortingLayer) * ORDER_IN_LAYER_MAX + this._orderInLayer);
}
2023-02-05 20:31:26 +08:00
private _uiTransform:UITransform = null;
2023-02-05 20:31:26 +08:00
onLoad(){
this._uiTransform = this.getComponent(UITransform);
2023-02-05 20:31:26 +08:00
}
onEnable(){
2023-02-08 10:43:36 +08: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 20:31:26 +08:00
}
onDisable(){
this._uiTransform.sortingPriority = 0;
this._uiTransform.sortingEnabled = false;
2023-02-05 20:31:26 +08:00
}
}