diff --git a/assets/lcc-ui-sorting-group/engine-extend.meta b/assets/lcc-ui-sorting-group/engine-extend.meta new file mode 100644 index 0000000..f22c5a2 --- /dev/null +++ b/assets/lcc-ui-sorting-group/engine-extend.meta @@ -0,0 +1,12 @@ +{ + "ver": "1.1.0", + "importer": "directory", + "imported": true, + "uuid": "e9f90997-b8f8-43b8-8afc-26a0d75357f6", + "files": [], + "subMetas": {}, + "userData": { + "compressionType": {}, + "isRemoteBundle": {} + } +} diff --git a/assets/lcc-ui-sorting-group/engine-extend/render-entity.ts b/assets/lcc-ui-sorting-group/engine-extend/render-entity.ts new file mode 100644 index 0000000..aa4565f --- /dev/null +++ b/assets/lcc-ui-sorting-group/engine-extend/render-entity.ts @@ -0,0 +1,140 @@ + +/** + * 由于RenderEntity未暴露,所以修改就只有另辟蹊径 + */ + +import { Graphics } from "cc"; +import { UIRenderer } from "cc"; +import { TiledLayer } from "cc"; +import { UIMeshRenderer } from "cc"; +import { __private,dragonBones,sp } from "cc"; +import { JSB } from "cc/env"; +import { DEFAULT_SORTING_PRIORITY } from "../sorting-define"; + +export enum RenderEntityFloatSharedBufferView { + localOpacity, + sortingPriority, + count, +} + +export enum RenderEntityUInt8SharedBufferView { + colorR, + colorG, + colorB, + colorA, + maskMode, + count, +} + +export enum RenderEntityBoolSharedBufferView { + colorDirty, + enabled, + useLocal, + count, +} + +/** + * RenderEntity类 + */ +let RenderEntityClass:typeof __private._cocos_2d_renderer_render_entity__RenderEntity = null; + +/** + * 更新RenderEntity实体 + */ +export function UpdateRenderEntity(renderEntity:__private._cocos_2d_renderer_render_entity__RenderEntity){ + if(renderEntity && !RenderEntityClass){ + RenderEntityClass = renderEntity.constructor as typeof __private._cocos_2d_renderer_render_entity__RenderEntity; + + // @ts-ignore + RenderEntityClass.prototype.initSharedBuffer = function(){ + this._sortingPriority = DEFAULT_SORTING_PRIORITY; + if (JSB) { + //this._sharedBuffer = new Float32Array(RenderEntitySharedBufferView.count); + const buffer = this._nativeObj.getEntitySharedBufferForJS(); + let offset = 0; + this._floatSharedBuffer = new Float32Array(buffer, offset, RenderEntityFloatSharedBufferView.count); + offset += RenderEntityFloatSharedBufferView.count * 4; + this._uint8SharedBuffer = new Uint8Array(buffer, offset, RenderEntityUInt8SharedBufferView.count); + offset += RenderEntityUInt8SharedBufferView.count * 1; + this._boolSharedBuffer = new Uint8Array(buffer, offset, RenderEntityBoolSharedBufferView.count); + } + }; + + if(!('sortingPriority' in RenderEntityClass.prototype)){ + Object.defineProperty(RenderEntityClass.prototype, 'sortingPriority', { + get: function() { + return this._sortingPriority; + }, + set: function(value) { + this._sortingPriority = value; + if (JSB) { + this._floatSharedBuffer[RenderEntityFloatSharedBufferView.sortingPriority] = value; + } + }, + enumerable: true + }); + } + + // @ts-ignore + renderEntity.initSharedBuffer(); + + console.log('Update RenderEntity Class'); + } +} + +// @ts-ignore +const Graphics_createRenderEntity = Graphics.prototype.createRenderEntity; +// @ts-ignore +Graphics.prototype.createRenderEntity = function(){ + let entity = Graphics_createRenderEntity.call(this); + UpdateRenderEntity(entity); + return entity; +} + +const UIMeshRenderer_onLoad = UIMeshRenderer.prototype.onLoad; +UIMeshRenderer.prototype.onLoad = function(){ + UpdateRenderEntity(this._renderEntity); + return UIMeshRenderer_onLoad.call(this); +} + +// @ts-ignore +const UIRenderer_createRenderEntity = UIRenderer.prototype.createRenderEntity; +// @ts-ignore +UIRenderer.prototype.createRenderEntity = function(){ + let entity = UIRenderer_createRenderEntity.call(this); + UpdateRenderEntity(entity); + return entity; +} + +if(dragonBones){ + // @ts-ignore + const ArmatureDisplay_createRenderEntity = dragonBones.ArmatureDisplay.prototype.createRenderEntity; + // @ts-ignore + dragonBones.ArmatureDisplay.prototype.createRenderEntity = function(){ + let entity = ArmatureDisplay_createRenderEntity.call(this); + UpdateRenderEntity(entity); + return entity; + } +} + +if(sp){ + // @ts-ignore + const Skeleton_createRenderEntity = sp.Skeleton.prototype.createRenderEntity; + // @ts-ignore + sp.Skeleton.prototype.createRenderEntity = function(){ + let entity = Skeleton_createRenderEntity.call(this); + UpdateRenderEntity(entity); + return entity; + } +} + +if(TiledLayer){ + // @ts-ignore + const TiledLayer_createRenderEntity = TiledLayer.prototype.createRenderEntity; + // @ts-ignore + TiledLayer.prototype.createRenderEntity = function(){ + let entity = TiledLayer_createRenderEntity.call(this); + UpdateRenderEntity(entity); + return entity; + } +} diff --git a/assets/lcc-ui-sorting-group/engine-extend.ts.meta b/assets/lcc-ui-sorting-group/engine-extend/render-entity.ts.meta similarity index 70% rename from assets/lcc-ui-sorting-group/engine-extend.ts.meta rename to assets/lcc-ui-sorting-group/engine-extend/render-entity.ts.meta index c48fe03..bed1518 100644 --- a/assets/lcc-ui-sorting-group/engine-extend.ts.meta +++ b/assets/lcc-ui-sorting-group/engine-extend/render-entity.ts.meta @@ -2,7 +2,7 @@ "ver": "4.0.23", "importer": "typescript", "imported": true, - "uuid": "eebde562-6799-4fbd-9138-5f4755bdd7d7", + "uuid": "fa9757e8-0812-47bb-b2cd-658d631f676a", "files": [], "subMetas": {}, "userData": {} diff --git a/assets/lcc-ui-sorting-group/engine-extend/ui-renderer.ts b/assets/lcc-ui-sorting-group/engine-extend/ui-renderer.ts new file mode 100644 index 0000000..7f4e7b8 --- /dev/null +++ b/assets/lcc-ui-sorting-group/engine-extend/ui-renderer.ts @@ -0,0 +1,33 @@ +import { UIRenderer } from "cc"; + +declare module 'cc' { + interface UIRenderer { + + /** + * 排序优先级 - private + */ + _sortingPriority:number; + + /** + * 排序优先级 + */ + sortingPriority:number; + + /** + * 排序透明度 + */ + sortingOpacity:number; + } +} + +if(!('sortingPriority' in UIRenderer.prototype)){ + Object.defineProperty(UIRenderer.prototype, 'sortingPriority', { + get: function() { + return this._sortingPriority; + }, + set: function(value) { + this._sortingPriority = value; + }, + enumerable: true + }); +} diff --git a/assets/lcc-ui-sorting-group/engine-extend/ui-renderer.ts.meta b/assets/lcc-ui-sorting-group/engine-extend/ui-renderer.ts.meta new file mode 100644 index 0000000..d746e36 --- /dev/null +++ b/assets/lcc-ui-sorting-group/engine-extend/ui-renderer.ts.meta @@ -0,0 +1,9 @@ +{ + "ver": "4.0.23", + "importer": "typescript", + "imported": true, + "uuid": "1969969e-8406-4e32-a252-fa63557cd43f", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/assets/lcc-ui-sorting-group/engine-extend.ts b/assets/lcc-ui-sorting-group/engine-extend/ui.ts similarity index 92% rename from assets/lcc-ui-sorting-group/engine-extend.ts rename to assets/lcc-ui-sorting-group/engine-extend/ui.ts index ff626cc..1b7b77b 100644 --- a/assets/lcc-ui-sorting-group/engine-extend.ts +++ b/assets/lcc-ui-sorting-group/engine-extend/ui.ts @@ -1,21 +1,8 @@ -import { clamp, gfx,Node,RenderData,UI,StencilManager,UIRenderer } from 'cc'; +import { clamp, gfx,Node,RenderData,UI,StencilManager,UIRenderer, renderer } from 'cc'; import { JSB } from 'cc/env'; -import { DEFAULT_SORTING_PRIORITY } from './sorting-define'; +import { DEFAULT_SORTING_PRIORITY } from '../sorting-define'; declare module 'cc' { - interface UIRenderer { - - /** - * 排序优先级 - */ - sortingPriority:number; - - /** - * 排序透明度 - */ - sortingOpacity:number; - } - interface UI { /** @@ -77,7 +64,7 @@ UI.prototype.flushRendererCache = function(){ const rendererCache = this.rendererCache; if(rendererCache.length > 0){ if(this.rendererOrder){ - rendererCache.sort((a, b)=>{ return a.sortingPriority - b.sortingPriority; }); + rendererCache.sort((a, b)=>{ return a._sortingPriority - b._sortingPriority; }); } for(let render of rendererCache){ render.fillBuffers(this); @@ -178,8 +165,8 @@ UI.prototype.walk = function(node: Node, level = 0){ } }else{ this.rendererCache.push(render); - render.sortingPriority = render.sortingPriority ?? DEFAULT_SORTING_PRIORITY; - if(render.sortingPriority != DEFAULT_SORTING_PRIORITY){ + render._sortingPriority = render._sortingPriority ?? DEFAULT_SORTING_PRIORITY; + if(render._sortingPriority != DEFAULT_SORTING_PRIORITY){ this.rendererOrder = true; } if (this._opacityDirty && render && !render.useVertexOpacity && render.renderData && render.renderData.vertexCount > 0) { diff --git a/assets/lcc-ui-sorting-group/engine-extend/ui.ts.meta b/assets/lcc-ui-sorting-group/engine-extend/ui.ts.meta new file mode 100644 index 0000000..2a5806e --- /dev/null +++ b/assets/lcc-ui-sorting-group/engine-extend/ui.ts.meta @@ -0,0 +1,9 @@ +{ + "ver": "4.0.23", + "importer": "typescript", + "imported": true, + "uuid": "3892765a-558a-4ad4-a128-11b51b68d962", + "files": [], + "subMetas": {}, + "userData": {} +}