修复层级渲染内子节点通过动画修改透明度没生效问题

This commit is contained in:
spe 2024-05-28 19:07:09 +08:00
parent bdaac75764
commit 02dfcbbd73

View File

@ -1,3 +1,5 @@
import { View } from "cc";
import { EditBox } from "cc";
import { EPSILON, Node, RenderData, StencilManager, UIRenderer, approx, cclegacy, clamp, gfx, log } from "cc";
enum Stage {
// Stencil disabled
@ -19,6 +21,7 @@ enum Stage {
export default class CCCExtension {
static init() {
this._extendRender3_x();
this._extendEditBoxTemp();
}
private static _extendRender3_x() {
@ -53,21 +56,21 @@ export default class CCCExtension {
const uiProps = node._uiProps;
const render = uiProps.uiComp as UIRenderer;
// Save opacity
let parentOpacity = 1;
let parentOpacity = this._pOpacity === undefined ? 1 : this._pOpacity;
if (node.parent) {
parentOpacity = node.parent._uiProps.opacity;
}
let opacity = parentOpacity;
// TODO Always cascade ui property's local opacity before remove it
const selfOpacity = render && render.color ? render.color.a / 255 : 1;
this._pOpacity = opacity = opacity * selfOpacity * uiProps.localOpacity;
opacity *= selfOpacity * uiProps.localOpacity;
// TODO Set opacity to ui property's opacity before remove it
if (uiProps[`setOpacity`]) {
uiProps[`setOpacity`](opacity);
} else {
uiProps[`_opacity`] = opacity;
}
uiProps[`_opacity`] = opacity;
if (!approx(opacity, 0, EPSILON)) {
if (uiProps.colorDirty) {
// Cascade color dirty state
@ -94,6 +97,8 @@ export default class CCCExtension {
__renderQueue = [];
for (let i = 0; i < children.length; ++i) {
const child = children[i];
if (node.parent)
child._uiProps.colorDirty = child._uiProps.colorDirty || node.parent._uiProps.colorDirty;
const enableLevelRender = node[`__enableLevelRender`];
if (!enableLevelRender) {
this.walk(child, level);
@ -101,15 +106,14 @@ export default class CCCExtension {
levelSplit(child, 0, i);
}
}
while (__renderQueue.length > 0) {
const list = __renderQueue.shift();
if (list.length > 0) {
while (list.length > 0) {
const n = list.shift();
for (let i = 0; i < __renderQueue.length; ++i) {
const list = __renderQueue[i];
for (let j = 0; j < list.length; ++j) {
const n = list[j];
this.walk(n, level);
}
}
}
__renderQueue = [];
}
}
@ -121,7 +125,7 @@ export default class CCCExtension {
}
}
// Restore opacity
// this._pOpacity = parentOpacity;
this._pOpacity = parentOpacity;
// Post render assembler update logic
// ATTENTION: Will also reset colorDirty inside postUpdateAssembler
@ -138,6 +142,15 @@ export default class CCCExtension {
}
});
}
private static _extendEditBoxTemp() {
EditBox.prototype.onDestroy = function () {
if (this._impl) {
View.instance.targetOff(this._impl);
this._impl.clear();
}
}
}
}
export function updateOpacity(renderData: RenderData, opacity: number) {