mirror of
https://gitee.com/ccc_28/level-render
synced 2024-12-24 10:48:34 +00:00
修复层级渲染内子节点通过动画修改透明度没生效问题
This commit is contained in:
parent
bdaac75764
commit
02dfcbbd73
@ -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";
|
import { EPSILON, Node, RenderData, StencilManager, UIRenderer, approx, cclegacy, clamp, gfx, log } from "cc";
|
||||||
enum Stage {
|
enum Stage {
|
||||||
// Stencil disabled
|
// Stencil disabled
|
||||||
@ -19,6 +21,7 @@ enum Stage {
|
|||||||
export default class CCCExtension {
|
export default class CCCExtension {
|
||||||
static init() {
|
static init() {
|
||||||
this._extendRender3_x();
|
this._extendRender3_x();
|
||||||
|
this._extendEditBoxTemp();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static _extendRender3_x() {
|
private static _extendRender3_x() {
|
||||||
@ -53,21 +56,21 @@ export default class CCCExtension {
|
|||||||
const uiProps = node._uiProps;
|
const uiProps = node._uiProps;
|
||||||
const render = uiProps.uiComp as UIRenderer;
|
const render = uiProps.uiComp as UIRenderer;
|
||||||
// Save opacity
|
// Save opacity
|
||||||
let parentOpacity = 1;
|
let parentOpacity = this._pOpacity === undefined ? 1 : this._pOpacity;
|
||||||
if (node.parent) {
|
if (node.parent) {
|
||||||
parentOpacity = node.parent._uiProps.opacity;
|
parentOpacity = node.parent._uiProps.opacity;
|
||||||
}
|
}
|
||||||
let opacity = parentOpacity;
|
let opacity = parentOpacity;
|
||||||
// TODO Always cascade ui property's local opacity before remove it
|
// TODO Always cascade ui property's local opacity before remove it
|
||||||
const selfOpacity = render && render.color ? render.color.a / 255 : 1;
|
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
|
// TODO Set opacity to ui property's opacity before remove it
|
||||||
|
|
||||||
if (uiProps[`setOpacity`]) {
|
if (uiProps[`setOpacity`]) {
|
||||||
uiProps[`setOpacity`](opacity);
|
uiProps[`setOpacity`](opacity);
|
||||||
} else {
|
|
||||||
uiProps[`_opacity`] = opacity;
|
|
||||||
}
|
}
|
||||||
|
uiProps[`_opacity`] = opacity;
|
||||||
if (!approx(opacity, 0, EPSILON)) {
|
if (!approx(opacity, 0, EPSILON)) {
|
||||||
if (uiProps.colorDirty) {
|
if (uiProps.colorDirty) {
|
||||||
// Cascade color dirty state
|
// Cascade color dirty state
|
||||||
@ -94,6 +97,8 @@ export default class CCCExtension {
|
|||||||
__renderQueue = [];
|
__renderQueue = [];
|
||||||
for (let i = 0; i < children.length; ++i) {
|
for (let i = 0; i < children.length; ++i) {
|
||||||
const child = children[i];
|
const child = children[i];
|
||||||
|
if (node.parent)
|
||||||
|
child._uiProps.colorDirty = child._uiProps.colorDirty || node.parent._uiProps.colorDirty;
|
||||||
const enableLevelRender = node[`__enableLevelRender`];
|
const enableLevelRender = node[`__enableLevelRender`];
|
||||||
if (!enableLevelRender) {
|
if (!enableLevelRender) {
|
||||||
this.walk(child, level);
|
this.walk(child, level);
|
||||||
@ -101,15 +106,14 @@ export default class CCCExtension {
|
|||||||
levelSplit(child, 0, i);
|
levelSplit(child, 0, i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (__renderQueue.length > 0) {
|
for (let i = 0; i < __renderQueue.length; ++i) {
|
||||||
const list = __renderQueue.shift();
|
const list = __renderQueue[i];
|
||||||
if (list.length > 0) {
|
for (let j = 0; j < list.length; ++j) {
|
||||||
while (list.length > 0) {
|
const n = list[j];
|
||||||
const n = list.shift();
|
this.walk(n, level);
|
||||||
this.walk(n, level);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
__renderQueue = [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,7 +125,7 @@ export default class CCCExtension {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Restore opacity
|
// Restore opacity
|
||||||
// this._pOpacity = parentOpacity;
|
this._pOpacity = parentOpacity;
|
||||||
|
|
||||||
// Post render assembler update logic
|
// Post render assembler update logic
|
||||||
// ATTENTION: Will also reset colorDirty inside postUpdateAssembler
|
// 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) {
|
export function updateOpacity(renderData: RenderData, opacity: number) {
|
||||||
|
Loading…
Reference in New Issue
Block a user