From 70c4e8da16cb9439efc38fbe2f16cc9aa4b4a291 Mon Sep 17 00:00:00 2001 From: lujun <495904500@qq.com> Date: Wed, 8 Feb 2023 10:43:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8A=A8=E6=80=81=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lcc-ui-sorting-group/engine-extend/ui.ts | 2 +- assets/lcc-ui-sorting-group/sorting-group.ts | 30 ++++++++++++-- .../test/prefabs/ListTestItem-sorting.prefab | 40 +++++++++---------- assets/test/scenes/test-scene-sorting.scene | 12 +++--- 4 files changed, 54 insertions(+), 30 deletions(-) diff --git a/assets/lcc-ui-sorting-group/engine-extend/ui.ts b/assets/lcc-ui-sorting-group/engine-extend/ui.ts index 593a87c..275f25c 100644 --- a/assets/lcc-ui-sorting-group/engine-extend/ui.ts +++ b/assets/lcc-ui-sorting-group/engine-extend/ui.ts @@ -67,7 +67,7 @@ UI.prototype.flushRendererCache = function(){ } // console.log(`flushRendererCache ${rendererCache.length}`); for(let render of rendererCache){ - // console.log(`${render.node.name} render hash ${render.renderData.dataHash}`); + // console.log(`${render.node.name} render hash ${render.renderPriority}`); render.fillBuffers(this); if(render.renderOpacity >= 0){ updateOpacity(render.renderData, render.renderOpacity); diff --git a/assets/lcc-ui-sorting-group/sorting-group.ts b/assets/lcc-ui-sorting-group/sorting-group.ts index 3d2a689..9a2453b 100644 --- a/assets/lcc-ui-sorting-group/sorting-group.ts +++ b/assets/lcc-ui-sorting-group/sorting-group.ts @@ -12,13 +12,37 @@ export class SortingGroup extends Component { * 排序层 */ @type(Enum(SortingLayer)) - sortingLayer:SortingLayer = SortingLayer.DEFAULT; + private _sortingLayer:SortingLayer = SortingLayer.DEFAULT; + + /** + * 排序层 + */ + @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); + } + + /** + * 排序值 + */ + @property({ type:CCFloat, min: 0, max : ORDER_IN_LAYER_MAX }) + private _orderInLayer:number = 0; /** * 排序值 */ @property({ type:CCFloat, min: 0, max : ORDER_IN_LAYER_MAX }) - orderInLayer:number = 0; + 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); + } private _uiTransform:UITransform = null; @@ -27,7 +51,7 @@ export class SortingGroup extends Component { } onEnable(){ - this._uiTransform.sortingPriority = Math.sign(this.sortingLayer) * (Math.abs(this.sortingLayer) * ORDER_IN_LAYER_MAX + this.orderInLayer); + this._uiTransform.sortingPriority = Math.sign(this._sortingLayer) * (Math.abs(this._sortingLayer) * ORDER_IN_LAYER_MAX + this._orderInLayer); this._uiTransform.sortingEnabled = true; } diff --git a/assets/test/prefabs/ListTestItem-sorting.prefab b/assets/test/prefabs/ListTestItem-sorting.prefab index c84112c..df138f7 100644 --- a/assets/test/prefabs/ListTestItem-sorting.prefab +++ b/assets/test/prefabs/ListTestItem-sorting.prefab @@ -268,8 +268,8 @@ "__prefab": { "__id__": 9 }, - "sortingLayer": 1, - "orderInLayer": 6, + "_sortingLayer": 1, + "_orderInLayer": 6, "_id": "" }, { @@ -368,8 +368,8 @@ "__prefab": { "__id__": 16 }, - "sortingLayer": 1, - "orderInLayer": 1, + "_sortingLayer": 1, + "_orderInLayer": 1, "_id": "" }, { @@ -577,8 +577,8 @@ "__prefab": { "__id__": 25 }, - "sortingLayer": 1, - "orderInLayer": 7, + "_sortingLayer": 1, + "_orderInLayer": 7, "_id": "" }, { @@ -677,8 +677,8 @@ "__prefab": { "__id__": 32 }, - "sortingLayer": 1, - "orderInLayer": 2, + "_sortingLayer": 1, + "_orderInLayer": 2, "_id": "" }, { @@ -846,8 +846,8 @@ "__prefab": { "__id__": 42 }, - "sortingLayer": 1, - "orderInLayer": 3, + "_sortingLayer": 1, + "_orderInLayer": 3, "_id": "" }, { @@ -1110,8 +1110,8 @@ "__prefab": { "__id__": 52 }, - "sortingLayer": 1, - "orderInLayer": 5, + "_sortingLayer": 1, + "_orderInLayer": 5, "_id": "" }, { @@ -1234,8 +1234,8 @@ "__prefab": { "__id__": 61 }, - "sortingLayer": 1, - "orderInLayer": 4, + "_sortingLayer": 1, + "_orderInLayer": 4, "_id": "" }, { @@ -1334,8 +1334,8 @@ "__prefab": { "__id__": 68 }, - "sortingLayer": 1, - "orderInLayer": 8, + "_sortingLayer": 1, + "_orderInLayer": 8, "_id": "" }, { @@ -1485,8 +1485,8 @@ "__prefab": { "__id__": 76 }, - "sortingLayer": 1, - "orderInLayer": 9, + "_sortingLayer": 1, + "_orderInLayer": 9, "_id": "" }, { @@ -1585,8 +1585,8 @@ "__prefab": { "__id__": 83 }, - "sortingLayer": 1, - "orderInLayer": 0, + "_sortingLayer": 1, + "_orderInLayer": 0, "_id": "" }, { diff --git a/assets/test/scenes/test-scene-sorting.scene b/assets/test/scenes/test-scene-sorting.scene index a9a582b..26f84fd 100644 --- a/assets/test/scenes/test-scene-sorting.scene +++ b/assets/test/scenes/test-scene-sorting.scene @@ -1032,8 +1032,8 @@ }, "_enabled": true, "__prefab": null, - "sortingLayer": 1, - "orderInLayer": 3, + "_sortingLayer": 0, + "_orderInLayer": 0, "_id": "b7SyZGN8ZByo48B8plzxZd" }, { @@ -1276,8 +1276,8 @@ }, "_enabled": true, "__prefab": null, - "sortingLayer": 1, - "orderInLayer": 2, + "_sortingLayer": 0, + "_orderInLayer": 0, "_id": "0fSX301tNL3ID+MhrxV/d7" }, { @@ -1681,8 +1681,8 @@ }, "_enabled": true, "__prefab": null, - "sortingLayer": 1, - "orderInLayer": 1, + "_sortingLayer": 0, + "_orderInLayer": 0, "_id": "e8pXnnkRRPfo50O0CR7SRu" }, {