完善native实现ts端

This commit is contained in:
lujun 2023-02-06 12:06:34 +08:00
parent 0e1b6793d5
commit f9c85e9b81
7 changed files with 209 additions and 19 deletions

View File

@ -0,0 +1,12 @@
{
"ver": "1.1.0",
"importer": "directory",
"imported": true,
"uuid": "e9f90997-b8f8-43b8-8afc-26a0d75357f6",
"files": [],
"subMetas": {},
"userData": {
"compressionType": {},
"isRemoteBundle": {}
}
}

View File

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

View File

@ -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": {}

View File

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

View File

@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "1969969e-8406-4e32-a252-fa63557cd43f",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@ -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) {

View File

@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "3892765a-558a-4ad4-a128-11b51b68d962",
"files": [],
"subMetas": {},
"userData": {}
}