diff --git a/cocos/2d/assembler/label/bmfontUtils.ts b/cocos/2d/assembler/label/bmfontUtils.ts index 1ac59fde138..c5a4ddb9357 100644 --- a/cocos/2d/assembler/label/bmfontUtils.ts +++ b/cocos/2d/assembler/label/bmfontUtils.ts @@ -102,7 +102,7 @@ export const bmfontUtils = { if (comp.renderData.vertDirty) { _comp = comp; - _uiTrans = _comp.node._uiProps.uiTransformComp!; + _uiTrans = _comp.node._getUITransformComp()!; const renderData = comp.renderData; const processing = TextProcessing.instance; diff --git a/cocos/2d/assembler/label/ttf.ts b/cocos/2d/assembler/label/ttf.ts index 54e3a7e95bc..f5657842fb6 100644 --- a/cocos/2d/assembler/label/ttf.ts +++ b/cocos/2d/assembler/label/ttf.ts @@ -123,7 +123,7 @@ export const ttf: IAssembler = { if (!renderData) { return; } - const uiTrans = comp.node._uiProps.uiTransformComp!; + const uiTrans = comp.node._getUITransformComp()!; const width = uiTrans.width; const height = uiTrans.height; const appX = uiTrans.anchorX * width; diff --git a/cocos/2d/assembler/label/ttfUtils.ts b/cocos/2d/assembler/label/ttfUtils.ts index be89965aae2..660cc747910 100644 --- a/cocos/2d/assembler/label/ttfUtils.ts +++ b/cocos/2d/assembler/label/ttfUtils.ts @@ -116,7 +116,7 @@ export const ttfUtils = { if (!comp.renderData) { return; } if (comp.renderData.vertDirty) { - const trans = comp.node._uiProps.uiTransformComp!; + const trans = comp.node._getUITransformComp()!; const processing = TextProcessing.instance; const style = comp.textStyle; const layout = comp.textLayout; diff --git a/cocos/2d/assembler/sprite/bar-filled.ts b/cocos/2d/assembler/sprite/bar-filled.ts index ce5a20a3d72..6b77bae53a7 100644 --- a/cocos/2d/assembler/sprite/bar-filled.ts +++ b/cocos/2d/assembler/sprite/bar-filled.ts @@ -156,7 +156,7 @@ export const barFilled: IAssembler = { updateVertexData (sprite: Sprite, fillStart: number, fillEnd: number) { const renderData: RenderData | null = sprite.renderData; const dataList: IRenderData[] = renderData!.data; - const uiTrans = sprite.node._uiProps.uiTransformComp!; + const uiTrans = sprite.node._getUITransformComp()!; const width = uiTrans.width; const height = uiTrans.height; const appX = uiTrans.anchorX * width; diff --git a/cocos/2d/assembler/sprite/radial-filled.ts b/cocos/2d/assembler/sprite/radial-filled.ts index b632d2dd05b..486c93484e4 100644 --- a/cocos/2d/assembler/sprite/radial-filled.ts +++ b/cocos/2d/assembler/sprite/radial-filled.ts @@ -94,7 +94,7 @@ function _calcIntersectedPoints ( } function _calculateVertices (sprite: Sprite): void { - const uiTrans = sprite.node._uiProps.uiTransformComp!; + const uiTrans = sprite.node._getUITransformComp()!; const width = uiTrans.width; const height = uiTrans.height; const appX = uiTrans.anchorX * width; diff --git a/cocos/2d/assembler/sprite/simple.ts b/cocos/2d/assembler/sprite/simple.ts index 857900fe82d..fa7ebb92106 100644 --- a/cocos/2d/assembler/sprite/simple.ts +++ b/cocos/2d/assembler/sprite/simple.ts @@ -41,7 +41,7 @@ const QUAD_INDICES = Uint16Array.from([0, 1, 2, 1, 3, 2]); * 可通过 `UI.simple` 获取该组装器。 */ export const simple: IAssembler = { - createData(sprite: Sprite) { + createData (sprite: Sprite) { const renderData = sprite.requestRenderData(); renderData.dataLength = 4; renderData.resize(4, 6); @@ -49,7 +49,7 @@ export const simple: IAssembler = { return renderData; }, - updateRenderData(sprite: Sprite) { + updateRenderData (sprite: Sprite) { const frame = sprite.spriteFrame; dynamicAtlasManager.packToDynamicAtlas(sprite, frame); @@ -95,7 +95,7 @@ export const simple: IAssembler = { } }, - fillBuffers(sprite: Sprite, renderer: IBatcher) { + fillBuffers (sprite: Sprite, renderer: IBatcher) { if (sprite === null) { return; } @@ -138,13 +138,13 @@ export const simple: IAssembler = { // renderer.switchBufferAccessor().appendIndices(chunk); }, - updateVertexData(sprite: Sprite) { + updateVertexData (sprite: Sprite) { const renderData: RenderData | null = sprite.renderData; if (!renderData) { return; } - const uiTrans = sprite.node._uiProps.uiTransformComp!; + const uiTrans = sprite.node._getUITransformComp()!; const dataList: IRenderData[] = renderData.data; const cw = uiTrans.width; const ch = uiTrans.height; diff --git a/cocos/2d/assembler/sprite/sliced.ts b/cocos/2d/assembler/sprite/sliced.ts index 80898bf7979..c6b2142d695 100644 --- a/cocos/2d/assembler/sprite/sliced.ts +++ b/cocos/2d/assembler/sprite/sliced.ts @@ -108,7 +108,7 @@ export const sliced: IAssembler = { const renderData = sprite.renderData; if (!renderData) return; const dataList: IRenderData[] = renderData.data; - const uiTrans = sprite.node._uiProps.uiTransformComp!; + const uiTrans = sprite.node._getUITransformComp()!; const width = uiTrans.width; const height = uiTrans.height; const appX = uiTrans.anchorX * width; diff --git a/cocos/2d/assembler/sprite/tiled.ts b/cocos/2d/assembler/sprite/tiled.ts index d410fd23046..91a67b8bac0 100644 --- a/cocos/2d/assembler/sprite/tiled.ts +++ b/cocos/2d/assembler/sprite/tiled.ts @@ -74,7 +74,7 @@ export const tiled: IAssembler = { return; } - const uiTrans = sprite.node._uiProps.uiTransformComp!; + const uiTrans = sprite.node._getUITransformComp()!; const contentWidth = Math.abs(uiTrans.width); const contentHeight = Math.abs(uiTrans.height); @@ -226,7 +226,7 @@ export const tiled: IAssembler = { }, updateVerts (sprite: Sprite, sizableWidth: number, sizableHeight: number, row: number, col: number) { - const uiTrans = sprite.node._uiProps.uiTransformComp!; + const uiTrans = sprite.node._getUITransformComp()!; const renderData = sprite.renderData; if (!renderData) return; const dataList: IRenderData[] = renderData.data; diff --git a/cocos/2d/components/mask.ts b/cocos/2d/components/mask.ts index 4e20d958a1c..29b0049c1ce 100644 --- a/cocos/2d/components/mask.ts +++ b/cocos/2d/components/mask.ts @@ -336,7 +336,7 @@ export class Mask extends Component { * @param worldPt @en point in World Space. @zh 世界空间中的点击点。 */ public isHit (worldPt: Vec2): boolean { - const uiTrans = this.node._uiProps.uiTransformComp!; + const uiTrans = this.node._getUITransformComp()!; const size = uiTrans.contentSize; const w = size.width; const h = size.height; @@ -412,7 +412,7 @@ export class Mask extends Component { return; } - const uiTrans = this.node._uiProps.uiTransformComp!; + const uiTrans = this.node._getUITransformComp()!; const graphics = this._graphics; // Share render data with graphics content graphics.clear(); diff --git a/cocos/2d/components/rich-text.ts b/cocos/2d/components/rich-text.ts index 9ae3da0685b..42ff5682d76 100644 --- a/cocos/2d/components/rich-text.ts +++ b/cocos/2d/components/rich-text.ts @@ -118,7 +118,7 @@ function getSegmentByPool (type: string, content: string | SpriteFrame): ISegmen seg.comp.underlineHeight = 2; } node.setPosition(0, 0, 0); - const trans = node._uiProps.uiTransformComp!; + const trans = node._getUITransformComp()!; trans.setAnchorPoint(0.5, 0.5); seg.node = node; @@ -758,7 +758,7 @@ export class RichText extends Component { } label.styleIndex = styleIndex; this._applyTextAttribute(label); - const size = label.node._uiProps.uiTransformComp!.contentSize; + const size = label.node._getUITransformComp()!.contentSize; Vec2.set(out, size.x, size.y); return out; } @@ -855,7 +855,7 @@ export class RichText extends Component { labelSegment.styleIndex = styleIndex; labelSegment.lineCount = this._lineCount; - labelSegment.node._uiProps.uiTransformComp!.setAnchorPoint(0, 0); + labelSegment.node._getUITransformComp()!.setAnchorPoint(0, 0); labelSegment.node.layer = this.node.layer; this.node.insertChild(labelSegment.node, this._labelChildrenNum++); this._applyTextAttribute(labelSegment); @@ -901,7 +901,7 @@ this._measureText(styleIndex) as unknown as (s: string) => number, for (let k = 0; k < fragments.length; ++k) { const splitString = fragments[k]; labelSegment = this._addLabelSegment(splitString, styleIndex); - const labelSize = labelSegment.node._uiProps.uiTransformComp!.contentSize; + const labelSize = labelSegment.node._getUITransformComp()!.contentSize; this._lineOffsetX += labelSize.width; if (fragments.length > 1 && k < fragments.length - 1) { this._updateLineInfo(); @@ -984,13 +984,13 @@ this._measureText(styleIndex) as unknown as (s: string) => number, const sprite = segment.comp; switch (style.imageAlign) { case 'top': - segment.node._uiProps.uiTransformComp!.setAnchorPoint(0, 1); + segment.node._getUITransformComp()!.setAnchorPoint(0, 1); break; case 'center': - segment.node._uiProps.uiTransformComp!.setAnchorPoint(0, 0.5); + segment.node._getUITransformComp()!.setAnchorPoint(0, 0.5); break; default: - segment.node._uiProps.uiTransformComp!.setAnchorPoint(0, 0); + segment.node._getUITransformComp()!.setAnchorPoint(0, 0); break; } @@ -1033,7 +1033,7 @@ this._measureText(styleIndex) as unknown as (s: string) => number, this._labelWidth = this._lineOffsetX; } } - segment.node._uiProps.uiTransformComp!.setContentSize(spriteWidth, spriteHeight); + segment.node._getUITransformComp()!.setContentSize(spriteWidth, spriteHeight); segment.lineCount = this._lineCount; segment.clickHandler = ''; @@ -1126,7 +1126,7 @@ this._measureText(styleIndex) as unknown as (s: string) => number, } else { label = this._addLabelSegment(labelString, i); - this._lineOffsetX += label.node._uiProps.uiTransformComp!.width; + this._lineOffsetX += label.node._getUITransformComp()!.width; if (this._lineOffsetX > this._labelWidth) { this._labelWidth = this._lineOffsetX; } @@ -1147,7 +1147,7 @@ this._measureText(styleIndex) as unknown as (s: string) => number, this._labelHeight = (this._lineCount + BASELINE_RATIO) * this._lineHeight; // trigger "size-changed" event - this.node._uiProps.uiTransformComp!.setContentSize(this._labelWidth, this._labelHeight); + this.node._getUITransformComp()!.setContentSize(this._labelWidth, this._labelHeight); this._updateRichTextPosition(); this._layoutDirty = false; @@ -1176,7 +1176,7 @@ this._measureText(styleIndex) as unknown as (s: string) => number, let nextTokenX = 0; let nextLineIndex = 1; const totalLineCount = this._lineCount; - const trans = this.node._uiProps.uiTransformComp!; + const trans = this.node._getUITransformComp()!; const anchorX = trans.anchorX; const anchorY = trans.anchorY; for (let i = 0; i < this._segments.length; ++i) { @@ -1209,7 +1209,7 @@ this._measureText(styleIndex) as unknown as (s: string) => number, ); if (lineCount === nextLineIndex) { - nextTokenX += segment.node._uiProps.uiTransformComp!.width; + nextTokenX += segment.node._getUITransformComp()!.width; } const sprite = segment.node.getComponent(Sprite); @@ -1218,7 +1218,7 @@ this._measureText(styleIndex) as unknown as (s: string) => number, // adjust img align (from ) const lineHeightSet = this._lineHeight; const lineHeightReal = this._lineHeight * (1 + BASELINE_RATIO); // single line node height - switch (segment.node._uiProps.uiTransformComp!.anchorY) { + switch (segment.node._getUITransformComp()!.anchorY) { case 1: position.y += (lineHeightSet + ((lineHeightReal - lineHeightSet) / 2)); break; diff --git a/cocos/2d/components/sprite.ts b/cocos/2d/components/sprite.ts index 18ee41be4df..47f56b694d0 100644 --- a/cocos/2d/components/sprite.ts +++ b/cocos/2d/components/sprite.ts @@ -648,7 +648,7 @@ export class Sprite extends UIRenderer { } if (this._spriteFrame) { - const actualSize = this.node._uiProps.uiTransformComp!.contentSize; + const actualSize = this.node._getUITransformComp()!.contentSize; let expectedW = actualSize.width; let expectedH = actualSize.height; if (this._sizeMode === SizeMode.RAW) { diff --git a/cocos/2d/components/ui-mesh-renderer.ts b/cocos/2d/components/ui-mesh-renderer.ts index ca40e0bc92d..c25665bf2ed 100644 --- a/cocos/2d/components/ui-mesh-renderer.ts +++ b/cocos/2d/components/ui-mesh-renderer.ts @@ -95,7 +95,7 @@ export class UIMeshRenderer extends Component { } public onLoad (): void { - if (!this.node._uiProps.uiTransformComp) { + if (!this.node._getUITransformComp()) { this.node.addComponent('cc.UITransform'); } diff --git a/cocos/2d/event/pointer-event-dispatcher.ts b/cocos/2d/event/pointer-event-dispatcher.ts index d9e6b0c3126..6c9d1139a2a 100644 --- a/cocos/2d/event/pointer-event-dispatcher.ts +++ b/cocos/2d/event/pointer-event-dispatcher.ts @@ -216,7 +216,7 @@ class PointerEventDispatcher implements IEventDispatcher { const pointerEventProcessor = pointerEventProcessorList[i]; const node = pointerEventProcessor.node; if (node._uiProps) { - const trans = node._uiProps.uiTransformComp; + const trans = node._getUITransformComp(); pointerEventProcessor.cachedCameraPriority = trans!.cameraPriority; } } @@ -227,9 +227,9 @@ class PointerEventDispatcher implements IEventDispatcher { private _sortByPriority (p1: NodeEventProcessor, p2: NodeEventProcessor): number { const node1: Node = p1.node; const node2: Node = p2.node; - if (!p2 || !node2 || !node2.activeInHierarchy || !node2._uiProps.uiTransformComp) { + if (!p2 || !node2 || !node2.activeInHierarchy || !node2._getUITransformComp()) { return -1; - } else if (!p1 || !node1 || !node1.activeInHierarchy || !node1._uiProps.uiTransformComp) { + } else if (!p1 || !node1 || !node1.activeInHierarchy || !node1._getUITransformComp()) { return 1; } diff --git a/cocos/2d/framework/canvas.ts b/cocos/2d/framework/canvas.ts index 1d0390335d8..194caa7ce7b 100644 --- a/cocos/2d/framework/canvas.ts +++ b/cocos/2d/framework/canvas.ts @@ -137,7 +137,7 @@ export class Canvas extends RenderRoot2D { // TODO: support paddings of locked widget this.node.getPosition(this._pos); const nodeSize = view.getDesignResolutionSize(); - const trans = this.node._uiProps.uiTransformComp!; + const trans = this.node._getUITransformComp()!; let scaleX = this.node.scale.x; let anchorX = trans.anchorX; diff --git a/cocos/2d/framework/ui-transform.ts b/cocos/2d/framework/ui-transform.ts index 97217c6ba94..746de448321 100644 --- a/cocos/2d/framework/ui-transform.ts +++ b/cocos/2d/framework/ui-transform.ts @@ -777,12 +777,12 @@ export class UITransform extends Component { } } - private static _sortChildrenSibling (node): void { + private static _sortChildrenSibling (node: Node): void { const siblings = node.children; if (siblings) { siblings.sort((a: Node, b: Node): number => { - const aComp = a._uiProps.uiTransformComp; - const bComp = b._uiProps.uiTransformComp; + const aComp = a._getUITransformComp(); + const bComp = b._getUITransformComp(); const ca = aComp ? aComp._priority : 0; const cb = bComp ? bComp._priority : 0; const diff = ca - cb; diff --git a/cocos/dragon-bones/ArmatureDisplay.ts b/cocos/dragon-bones/ArmatureDisplay.ts index c7f638dfbf5..83d67d923fa 100644 --- a/cocos/dragon-bones/ArmatureDisplay.ts +++ b/cocos/dragon-bones/ArmatureDisplay.ts @@ -1089,7 +1089,7 @@ export class ArmatureDisplay extends UIRenderer { if (this._armature) { const armatureData = this._armature.armatureData; const aabb = armatureData.aabb; - this.node._uiProps.uiTransformComp!.setContentSize(aabb.width, aabb.height); + this.node._getUITransformComp()!.setContentSize(aabb.width, aabb.height); } this.attachUtil.init(this); diff --git a/cocos/dragon-bones/CCArmatureDisplay.ts b/cocos/dragon-bones/CCArmatureDisplay.ts index 4d9918f91ff..630fa83a4b2 100644 --- a/cocos/dragon-bones/CCArmatureDisplay.ts +++ b/cocos/dragon-bones/CCArmatureDisplay.ts @@ -142,7 +142,7 @@ export class CCArmatureDisplay extends DisplayData implements IEventDispatcher { convertToWorldSpace (point: Vec3): Vec3 | undefined { const newPos = this.convertToRootSpace(point); const ccNode = this.getRootNode(); - return ccNode?._uiProps.uiTransformComp?.convertToWorldSpaceAR(newPos); + return ccNode?._getUITransformComp()?.convertToWorldSpaceAR(newPos); } /** * @en Get the node of root ArmatureDisplay component in. @@ -185,7 +185,7 @@ export class CCArmatureDisplay extends DisplayData implements IEventDispatcher { this.shouldAdvanced = !!on; } - hasDBEventListener (type): boolean { + hasDBEventListener (type: string): boolean { return this._eventTarget.hasEventListener(type); } diff --git a/cocos/scene-graph/deprecated.ts b/cocos/scene-graph/deprecated.ts index 072166d3851..cc20fb0f056 100644 --- a/cocos/scene-graph/deprecated.ts +++ b/cocos/scene-graph/deprecated.ts @@ -53,40 +53,40 @@ replaceProperty(Node.prototype, 'Node', [ name: 'width', targetName: 'node.getComponent(UITransform)', customGetter (this: Node): number { - return this._uiProps.uiTransformComp!.width; + return this._getUITransformComp()!.width; }, customSetter (this: Node, value: number): void { - this._uiProps.uiTransformComp!.width = value; + this._getUITransformComp()!.width = value; }, }, { name: 'height', targetName: 'node.getComponent(UITransform)', customGetter (this: Node): number { - return this._uiProps.uiTransformComp!.height; + return this._getUITransformComp()!.height; }, customSetter (this: Node, value: number): void { - this._uiProps.uiTransformComp!.height = value; + this._getUITransformComp()!.height = value; }, }, { name: 'anchorX', targetName: 'node.getComponent(UITransform)', customGetter (this: Node): number { - return this._uiProps.uiTransformComp!.anchorX; + return this._getUITransformComp()!.anchorX; }, customSetter (this: Node, value: number): void { - this._uiProps.uiTransformComp!.anchorX = value; + this._getUITransformComp()!.anchorX = value; }, }, { name: 'anchorY', targetName: 'node.getComponent(UITransform)', customGetter (this: Node): number { - return this._uiProps.uiTransformComp!.anchorY; + return this._getUITransformComp()!.anchorY; }, customSetter (this: Node, value: number): void { - this._uiProps.uiTransformComp!.anchorY = value; + this._getUITransformComp()!.anchorY = value; }, }, { @@ -96,7 +96,7 @@ replaceProperty(Node.prototype, 'Node', [ if (!out) { out = new Vec2(); } - out.set(this._uiProps.uiTransformComp!.anchorPoint); + out.set(this._getUITransformComp()!.anchorPoint); return out; }, }, @@ -104,7 +104,7 @@ replaceProperty(Node.prototype, 'Node', [ name: 'setAnchorPoint', targetName: 'node.getComponent(UITransform)', customFunction (this: Node, point: Vec2 | number, y?: number): void { - this._uiProps.uiTransformComp!.setAnchorPoint(point, y); + this._getUITransformComp()!.setAnchorPoint(point, y); }, }, { @@ -115,7 +115,7 @@ replaceProperty(Node.prototype, 'Node', [ out = new Size(); } - out.set(this._uiProps.uiTransformComp!.contentSize); + out.set(this._getUITransformComp()!.contentSize); return out; }, }, @@ -124,9 +124,9 @@ replaceProperty(Node.prototype, 'Node', [ targetName: 'node.getComponent(UITransform)', customFunction (this: Node, size: Size | number, height?: number): void { if (typeof size === 'number') { - this._uiProps.uiTransformComp!.setContentSize(size, height!); + this._getUITransformComp()!.setContentSize(size, height!); } else { - this._uiProps.uiTransformComp!.setContentSize(size); + this._getUITransformComp()!.setContentSize(size); } }, }, diff --git a/cocos/scene-graph/node-event-processor.ts b/cocos/scene-graph/node-event-processor.ts index e347b4cdc1b..c9920a19b3e 100644 --- a/cocos/scene-graph/node-event-processor.ts +++ b/cocos/scene-graph/node-event-processor.ts @@ -497,7 +497,7 @@ export class NodeEventProcessor { private _handleMouseDown (event: EventMouse): boolean { const node = this._node; - const uiTransformComp = node._uiProps.uiTransformComp; + const uiTransformComp = node._getUITransformComp(); if (!node || !uiTransformComp) { return false; } @@ -516,7 +516,7 @@ export class NodeEventProcessor { private _handleMouseMove (event: EventMouse): boolean { const node = this._node; - const uiTransformComp = node._uiProps.uiTransformComp; + const uiTransformComp = node._getUITransformComp(); if (!node || !uiTransformComp || this._isMouseLeaveWindow) { return false; } @@ -553,7 +553,7 @@ export class NodeEventProcessor { private _handleMouseUp (event: EventMouse): boolean { const node = this._node; - const uiTransformComp = node._uiProps.uiTransformComp; + const uiTransformComp = node._getUITransformComp(); if (!node || !uiTransformComp) { return false; } @@ -572,7 +572,7 @@ export class NodeEventProcessor { private _handleMouseWheel (event: EventMouse): boolean { const node = this._node; - const uiTransformComp = node._uiProps.uiTransformComp; + const uiTransformComp = node._getUITransformComp(); if (!node || !uiTransformComp) { return false; } @@ -635,7 +635,7 @@ export class NodeEventProcessor { private _handleTouchStart (event: EventTouch): boolean { const node = this.node; - const uiTransformComp = node._uiProps.uiTransformComp; + const uiTransformComp = node._getUITransformComp(); if (!node || !uiTransformComp) { return false; } @@ -655,7 +655,7 @@ export class NodeEventProcessor { private _handleTouchMove (event: EventTouch): boolean { const node = this.node; - if (!node || !node._uiProps.uiTransformComp) { + if (!node || !node._getUITransformComp()) { return false; } @@ -668,7 +668,7 @@ export class NodeEventProcessor { private _handleTouchEnd (event: EventTouch): void { const node = this.node; - const uiTransformComp = node._uiProps.uiTransformComp; + const uiTransformComp = node._getUITransformComp(); if (!node || !uiTransformComp) { return; } @@ -687,7 +687,7 @@ export class NodeEventProcessor { private _handleTouchCancel (event: EventTouch): void { const node = this.node; - if (!node || !node._uiProps.uiTransformComp) { + if (!node || !node._getUITransformComp()) { return; } diff --git a/cocos/scene-graph/node.ts b/cocos/scene-graph/node.ts index b81d3cb536d..99db8dd020f 100644 --- a/cocos/scene-graph/node.ts +++ b/cocos/scene-graph/node.ts @@ -44,6 +44,7 @@ import { DispatcherEventType, NodeEventProcessor } from './node-event-processor' import type { Scene } from './scene'; import type { Director } from '../game/director'; import type { Game } from '../game/game'; +import type { UITransform } from '../2d/framework/ui-transform'; const Destroying = CCObject.Flags.Destroying; const DontDestroy = CCObject.Flags.DontDestroy; @@ -2714,6 +2715,14 @@ export class Node extends CCObject implements ISchedulable, CustomSerializable { return result; } + + /** + * @mangle + * @engineInternal + */ + _getUITransformComp (): UITransform | null { + return this._uiProps.uiTransformComp; + } } nodePolyfill(Node); diff --git a/cocos/spine/skeleton.ts b/cocos/spine/skeleton.ts index c1ca0f6595d..95091b81696 100644 --- a/cocos/spine/skeleton.ts +++ b/cocos/spine/skeleton.ts @@ -1641,7 +1641,7 @@ export class Skeleton extends UIRenderer { } private _updateUITransform (): void { - const uiTrans = this.node._uiProps.uiTransformComp!; + const uiTrans = this.node._getUITransformComp()!; const skeletonData = this._runtimeData; if (!skeletonData) { uiTrans.setContentSize(100, 100); diff --git a/cocos/tiledmap/tiled-layer.ts b/cocos/tiledmap/tiled-layer.ts index a7266900982..2549a123b2f 100644 --- a/cocos/tiledmap/tiled-layer.ts +++ b/cocos/tiledmap/tiled-layer.ts @@ -328,7 +328,7 @@ export class TiledLayer extends UIRenderer { } protected _updateCullingOffsetByUserNode (node_: Node): void { - const node = node_._uiProps.uiTransformComp!.contentSize; + const node = node_._getUITransformComp()!.contentSize; if (this._topOffset < node.height) { this._topOffset = node.height; } @@ -468,7 +468,7 @@ export class TiledLayer extends UIRenderer { protected _syncAnchorPoint (): void { const node = this.node; - const trans = node._uiProps.uiTransformComp!; + const trans = node._getUITransformComp()!; const scale = node.getScale(); this._leftDownToCenterX = trans.width * trans.anchorX * scale.x; this._leftDownToCenterY = trans.height * trans.anchorY * scale.y; @@ -1402,12 +1402,12 @@ export class TiledLayer extends UIRenderer { width = (tileWidth * layerW) + tileWidth / 2; height = (this._diffY1 + this._hexSideLength) * layerH + this._diffY1; } - this.node._uiProps.uiTransformComp!.setContentSize(width, height); + this.node._getUITransformComp()!.setContentSize(width, height); } else if (this._layerOrientation === Orientation.ISO) { const wh = layerW + layerH; - this.node._uiProps.uiTransformComp!.setContentSize(maptw * 0.5 * wh, mapth * 0.5 * wh); + this.node._getUITransformComp()!.setContentSize(maptw * 0.5 * wh, mapth * 0.5 * wh); } else { - this.node._uiProps.uiTransformComp!.setContentSize(layerW * maptw, layerH * mapth); + this.node._getUITransformComp()!.setContentSize(layerW * maptw, layerH * mapth); } // offset (after layer orientation is set); diff --git a/cocos/tiledmap/tiled-map.ts b/cocos/tiledmap/tiled-map.ts index 1ce8dadb8fe..80b8445aa4c 100644 --- a/cocos/tiledmap/tiled-map.ts +++ b/cocos/tiledmap/tiled-map.ts @@ -402,9 +402,9 @@ export class TiledMap extends Component { } _syncAnchorPoint (): void { - const anchor = this.node._uiProps.uiTransformComp!.anchorPoint; - const leftTopX = this.node._uiProps.uiTransformComp!.width * anchor.x; - const leftTopY = this.node._uiProps.uiTransformComp!.height * (1 - anchor.y); + const anchor = this.node._getUITransformComp()!.anchorPoint; + const leftTopX = this.node._getUITransformComp()!.width * anchor.x; + const leftTopY = this.node._getUITransformComp()!.height * (1 - anchor.y); let i: number; let l: number; for (i = 0, l = this._layers.length; i < l; i++) { @@ -412,12 +412,12 @@ export class TiledMap extends Component { const layerNode = layerInfo.node; // Tiled layer sync anchor to map because it's old behavior, // do not change the behavior avoid influence user's existed logic. - layerNode._uiProps.uiTransformComp!.setAnchorPoint(anchor); + layerNode._getUITransformComp()!.setAnchorPoint(anchor); } for (i = 0, l = this._groups.length; i < l; i++) { const groupInfo = this._groups[i]; - const groupNode = groupInfo.node._uiProps.uiTransformComp!; + const groupNode = groupInfo.node._getUITransformComp()!; // Group layer not sync anchor to map because it's old behavior, // do not change the behavior avoid influence user's existing logic. groupNode.anchorX = 0.5; @@ -428,7 +428,7 @@ export class TiledMap extends Component { } for (i = 0, l = this._images.length; i < l; i++) { - const image = this._images[i]._uiProps.uiTransformComp!; + const image = this._images[i]._getUITransformComp()!; image.anchorX = 0.5; image.anchorY = 0.5; const x = this._images[i]._offset.x - leftTopX + image.width * image.anchorX; @@ -550,12 +550,12 @@ export class TiledMap extends Component { height = spriteFrame!.originalSize.height; } - child._uiProps.uiTransformComp!.setContentSize(width, height); + child._getUITransformComp()!.setContentSize(width, height); images.push(child); } - maxWidth = Math.max(maxWidth, child._uiProps.uiTransformComp!.width); - maxHeight = Math.max(maxHeight, child._uiProps.uiTransformComp!.height); + maxWidth = Math.max(maxWidth, child._getUITransformComp()!.width); + maxHeight = Math.max(maxHeight, child._getUITransformComp()!.height); } } @@ -567,7 +567,7 @@ export class TiledMap extends Component { } } - this.node._uiProps.uiTransformComp!.setContentSize(maxWidth, maxHeight); + this.node._getUITransformComp()!.setContentSize(maxWidth, maxHeight); this._syncAnchorPoint(); } diff --git a/cocos/tiledmap/tiled-object-group.ts b/cocos/tiledmap/tiled-object-group.ts index 77c69ac093b..79cf555a12c 100644 --- a/cocos/tiledmap/tiled-object-group.ts +++ b/cocos/tiledmap/tiled-object-group.ts @@ -207,7 +207,7 @@ export class TiledObjectGroup extends Component { height = mapSize.height * tileSize.height; } - const transComp = this.node._uiProps.uiTransformComp!; + const transComp = this.node._getUITransformComp()!; transComp.setContentSize(width, height); const leftTopX = width * transComp.anchorX; @@ -257,7 +257,7 @@ export class TiledObjectGroup extends Component { label = textNode.addComponent(Label); } - const textTransComp = textNode._uiProps.uiTransformComp!; + const textTransComp = textNode._getUITransformComp()!; textNode.active = object.visible; textTransComp.anchorX = 0; textTransComp.anchorY = 1; @@ -328,7 +328,7 @@ export class TiledObjectGroup extends Component { sprite = imgNode.addComponent(Sprite); } - const imgTrans = imgNode._uiProps.uiTransformComp!; + const imgTrans = imgNode._getUITransformComp()!; if (iso) { imgTrans.anchorX = 0.5 + tileOffsetX / object.width; imgTrans.anchorY = tileOffsetY / object.height; @@ -414,7 +414,7 @@ export class TiledObjectGroup extends Component { const tileOffsetX = tileset.tileOffset.x; const tileOffsetY = tileset.tileOffset.y; - const imgTrans = imgNode._uiProps.uiTransformComp!; + const imgTrans = imgNode._getUITransformComp()!; if (iso) { imgTrans.anchorX = 0.5 + tileOffsetX / object.width; imgTrans.anchorY = tileOffsetY / object.height; diff --git a/cocos/ui/button.ts b/cocos/ui/button.ts index be888dc1dce..ee13063d322 100644 --- a/cocos/ui/button.ts +++ b/cocos/ui/button.ts @@ -673,9 +673,9 @@ export class Button extends Component { if (!this.target) { return; } - const targetTrans = this.target._uiProps.uiTransformComp; + const targetTrans = this.target._getUITransformComp(); if (EDITOR && targetTrans) { - this.node._uiProps.uiTransformComp!.setContentSize(targetTrans.contentSize); + this.node._getUITransformComp()!.setContentSize(targetTrans.contentSize); } } @@ -849,7 +849,7 @@ export class Button extends Component { return; } - const hit = this.node._uiProps.uiTransformComp!.hitTest(touch.getLocation(), event.windowId); + const hit = this.node._getUITransformComp()!.hitTest(touch.getLocation(), event.windowId); if (this._transition === Transition.SCALE && this.target && this._originalScale) { if (hit) { diff --git a/cocos/ui/editbox/edit-box-impl.ts b/cocos/ui/editbox/edit-box-impl.ts index 9b976c137b1..78d712a4c81 100644 --- a/cocos/ui/editbox/edit-box-impl.ts +++ b/cocos/ui/editbox/edit-box-impl.ts @@ -331,13 +331,13 @@ export class EditBoxImpl extends EditBoxImplBase { const dpr = screenAdapter.devicePixelRatio; node.getWorldMatrix(_matrix); - const transform = node._uiProps.uiTransformComp; + const transform = node._getUITransformComp(); if (transform) { Vec3.set(_vec3, -transform.anchorX * transform.width, -transform.anchorY * transform.height, _vec3.z); Mat4.transform(_matrix, _matrix, _vec3); } - if (!node._uiProps.uiTransformComp) { + if (!node._getUITransformComp()) { return; } diff --git a/cocos/ui/editbox/edit-box.ts b/cocos/ui/editbox/edit-box.ts index 23f686c4918..45883be588f 100644 --- a/cocos/ui/editbox/edit-box.ts +++ b/cocos/ui/editbox/edit-box.ts @@ -651,11 +651,11 @@ export class EditBox extends Component { } protected _syncSize (): void { - const trans = this.node._uiProps.uiTransformComp!; + const trans = this.node._getUITransformComp()!; const size = trans.contentSize; if (this._background) { - const bgTrans = this._background.node._uiProps.uiTransformComp!; + const bgTrans = this._background.node._getUITransformComp()!; bgTrans.anchorPoint = trans.anchorPoint; bgTrans.setContentSize(size); } @@ -749,14 +749,14 @@ export class EditBox extends Component { } protected _updateLabelPosition (size: Size): void { - const trans = this.node._uiProps.uiTransformComp!; + const trans = this.node._getUITransformComp()!; const offX = -trans.anchorX * trans.width; const offY = -trans.anchorY * trans.height; const placeholderLabel = this._placeholderLabel; const textLabel = this._textLabel; if (textLabel) { - textLabel.node._uiProps.uiTransformComp!.setContentSize(size.width - LEFT_PADDING, size.height); + textLabel.node._getUITransformComp()!.setContentSize(size.width - LEFT_PADDING, size.height); textLabel.node.setPosition(offX + LEFT_PADDING, offY + size.height, textLabel.node.position.z); if (this._inputMode === InputMode.ANY) { textLabel.verticalAlign = VerticalTextAlignment.TOP; @@ -765,27 +765,27 @@ export class EditBox extends Component { } if (placeholderLabel) { - placeholderLabel.node._uiProps.uiTransformComp!.setContentSize(size.width - LEFT_PADDING, size.height); + placeholderLabel.node._getUITransformComp()!.setContentSize(size.width - LEFT_PADDING, size.height); placeholderLabel.node.setPosition(offX + LEFT_PADDING, offY + size.height, placeholderLabel.node.position.z); placeholderLabel.enableWrapText = this._inputMode === InputMode.ANY; } } protected _resizeChildNodes (): void { - const trans = this.node._uiProps.uiTransformComp!; + const trans = this.node._getUITransformComp()!; const textLabelNode = this._textLabel && this._textLabel.node; if (textLabelNode) { textLabelNode.setPosition(-trans.width / 2, trans.height / 2, textLabelNode.position.z); - textLabelNode._uiProps.uiTransformComp!.setContentSize(trans.contentSize); + textLabelNode._getUITransformComp()!.setContentSize(trans.contentSize); } const placeholderLabelNode = this._placeholderLabel && this._placeholderLabel.node; if (placeholderLabelNode) { placeholderLabelNode.setPosition(-trans.width / 2, trans.height / 2, placeholderLabelNode.position.z); - placeholderLabelNode._uiProps.uiTransformComp!.setContentSize(trans.contentSize); + placeholderLabelNode._getUITransformComp()!.setContentSize(trans.contentSize); } const backgroundNode = this._background && this._background.node; if (backgroundNode) { - backgroundNode._uiProps.uiTransformComp!.setContentSize(trans.contentSize); + backgroundNode._getUITransformComp()!.setContentSize(trans.contentSize); } this._syncSize(); diff --git a/cocos/ui/layout.ts b/cocos/ui/layout.ts index d6970626534..57e6c98669e 100644 --- a/cocos/ui/layout.ts +++ b/cocos/ui/layout.ts @@ -709,7 +709,7 @@ export class Layout extends Component { protected onEnable (): void { this._addEventListeners(); - const trans = this.node._uiProps.uiTransformComp!; + const trans = this.node._getUITransformComp()!; if (trans.contentSize.equals(Size.ZERO)) { trans.setContentSize(this._layoutSize); } @@ -727,7 +727,7 @@ export class Layout extends Component { const children = this.node.children; for (let i = 0; i < children.length; ++i) { const child = children[i]; - const uiTrans = child._uiProps.uiTransformComp; + const uiTrans = child._getUITransformComp(); if (child.activeInHierarchy && uiTrans) { this._usefulLayoutObj.push(uiTrans); } @@ -795,12 +795,12 @@ export class Layout extends Component { } protected _resized (): void { - this._layoutSize.set(this.node._uiProps.uiTransformComp!.contentSize); + this._layoutSize.set(this.node._getUITransformComp()!.contentSize); this._doLayoutDirty(); } protected _doLayoutHorizontally (baseWidth: number, rowBreak: boolean, fnPositionY: (...args: any[]) => number, applyChildren: boolean): number { - const trans = this.node._uiProps.uiTransformComp!; + const trans = this.node._getUITransformComp()!; const layoutAnchor = trans.anchorPoint; const limit = this._getFixedBreakingNum(); @@ -894,7 +894,7 @@ export class Layout extends Component { } protected _doLayoutVertically (baseHeight: number, columnBreak: boolean, fnPositionX: (...args: any[]) => number, applyChildren: boolean): number { - const trans = this.node._uiProps.uiTransformComp!; + const trans = this.node._getUITransformComp()!; const layoutAnchor = trans.anchorPoint; const limit = this._getFixedBreakingNum(); @@ -1018,7 +1018,7 @@ export class Layout extends Component { this._doLayoutHorizontally(baseWidth, true, fnPositionY, true); if (this._resizeMode === LayoutResizeMode.CONTAINER) { - this.node._uiProps.uiTransformComp!.setContentSize(baseWidth, newHeight); + this.node._getUITransformComp()!.setContentSize(baseWidth, newHeight); } } @@ -1051,12 +1051,12 @@ export class Layout extends Component { this._doLayoutVertically(baseHeight, true, fnPositionX, true); if (this._resizeMode === LayoutResizeMode.CONTAINER) { - this.node._uiProps.uiTransformComp!.setContentSize(newWidth, baseHeight); + this.node._getUITransformComp()!.setContentSize(newWidth, baseHeight); } } protected _doLayoutGrid (): void { - const trans = this.node._uiProps.uiTransformComp!; + const trans = this.node._getUITransformComp()!; const layoutAnchor = trans.anchorPoint; const layoutSize = trans.contentSize; @@ -1081,7 +1081,7 @@ export class Layout extends Component { baseSize += (activeChildCount - 1) * this._spacingX + this._getPaddingH(); } else { - baseSize = this.node._uiProps.uiTransformComp!.width; + baseSize = this.node._getUITransformComp()!.width; } return baseSize; @@ -1101,7 +1101,7 @@ export class Layout extends Component { baseSize += (activeChildCount - 1) * this._spacingY + this._getPaddingV(); } else { - baseSize = this.node._uiProps.uiTransformComp!.height; + baseSize = this.node._getUITransformComp()!.height; } return baseSize; @@ -1123,7 +1123,7 @@ export class Layout extends Component { }; this._doLayoutHorizontally(newWidth, false, fnPositionY, true); - this.node._uiProps.uiTransformComp!.width = newWidth; + this.node._getUITransformComp()!.width = newWidth; } else if (this._layoutType === LayoutType.VERTICAL) { const newHeight = this._getVerticalBaseHeight(); @@ -1133,7 +1133,7 @@ export class Layout extends Component { }; this._doLayoutVertically(newHeight, false, fnPositionX, true); - this.node._uiProps.uiTransformComp!.height = newHeight; + this.node._getUITransformComp()!.height = newHeight; } else if (this._layoutType === LayoutType.GRID) { this._doLayoutGrid(); } diff --git a/cocos/ui/page-view-indicator.ts b/cocos/ui/page-view-indicator.ts index 61192ebabed..65753d4a46d 100644 --- a/cocos/ui/page-view-indicator.ts +++ b/cocos/ui/page-view-indicator.ts @@ -214,7 +214,7 @@ export class PageViewIndicator extends Component { sprite.spriteFrame = this.spriteFrame; sprite.sizeMode = Sprite.SizeMode.CUSTOM; node.parent = this.node; - node._uiProps.uiTransformComp!.setContentSize(this._cellSize); + node._getUITransformComp()!.setContentSize(this._cellSize); return node; } diff --git a/cocos/ui/page-view.ts b/cocos/ui/page-view.ts index 8fc20d24b57..c2150c7d5ca 100644 --- a/cocos/ui/page-view.ts +++ b/cocos/ui/page-view.ts @@ -446,7 +446,7 @@ export class PageView extends ScrollView { if (!page || this._pages.indexOf(page) !== -1 || !this.content) { return; } - if (!page._uiProps.uiTransformComp) { + if (!page._getUITransformComp()) { logID(4301); return; } @@ -473,7 +473,7 @@ export class PageView extends ScrollView { if (index >= pageCount) { this.addPage(page); } else { - if (!page._uiProps.uiTransformComp) { + if (!page._getUITransformComp()) { logID(4301); return; } @@ -613,7 +613,7 @@ export class PageView extends ScrollView { const locPages = EDITOR_NOT_IN_PREVIEW ? this.content.children : this._pages; const selfSize = viewTrans.contentSize; for (let i = 0, len = locPages.length; i < len; i++) { - locPages[i]._uiProps.uiTransformComp!.setContentSize(selfSize); + locPages[i]._getUITransformComp()!.setContentSize(selfSize); } } @@ -662,8 +662,8 @@ export class PageView extends ScrollView { const layout = this.content.getComponent(Layout); if (layout) { if (this._sizeMode === SizeMode.Free && this._pages.length > 0) { - const firstPageTrans = this._pages[0]._uiProps.uiTransformComp!; - const lastPageTrans = this._pages[this._pages.length - 1]._uiProps.uiTransformComp!; + const firstPageTrans = this._pages[0]._getUITransformComp()!; + const lastPageTrans = this._pages[this._pages.length - 1]._getUITransformComp()!; if (this.direction === PageViewDirection.HORIZONTAL) { layout.paddingLeft = (viewTrans.width - firstPageTrans.width) / 2; layout.paddingRight = (viewTrans.width - lastPageTrans.width) / 2; diff --git a/cocos/ui/progress-bar.ts b/cocos/ui/progress-bar.ts index 7ed266ff011..8d9fa821f28 100644 --- a/cocos/ui/progress-bar.ts +++ b/cocos/ui/progress-bar.ts @@ -149,7 +149,7 @@ export class ProgressBar extends Component { const entity = this._barSprite.node; if (!entity) { return; } - const entitySize = entity._uiProps.uiTransformComp!.contentSize; + const entitySize = entity._getUITransformComp()!.contentSize; if (this._mode === Mode.HORIZONTAL) { this.totalLength = entitySize.width; } else if (this._mode === Mode.VERTICAL) { @@ -253,11 +253,11 @@ export class ProgressBar extends Component { const entity = this._barSprite.node; if (!entity) { return; } - const trans = this.node._uiProps.uiTransformComp!; + const trans = this.node._getUITransformComp()!; const nodeSize = trans.contentSize; const nodeAnchor = trans.anchorPoint; - const barSpriteSize = entity._uiProps.uiTransformComp!.contentSize; + const barSpriteSize = entity._getUITransformComp()!.contentSize; // if (entity.parent === this.node) { // this.node.setContentSize(barSpriteSize); @@ -288,7 +288,7 @@ export class ProgressBar extends Component { if (!entity) { return; } - const entTrans = entity._uiProps.uiTransformComp!; + const entTrans = entity._getUITransformComp()!; const entityAnchorPoint = entTrans.anchorPoint; const entitySize = entTrans.contentSize; diff --git a/cocos/ui/scroll-bar.ts b/cocos/ui/scroll-bar.ts index acf6c0fed0c..07d8a94aaa4 100644 --- a/cocos/ui/scroll-bar.ts +++ b/cocos/ui/scroll-bar.ts @@ -241,9 +241,9 @@ export class ScrollBar extends Component { return; } - const contentSize = content._uiProps.uiTransformComp!.contentSize; - const scrollViewSize = this._scrollView.node._uiProps.uiTransformComp!.contentSize; - const barSize = this.node._uiProps.uiTransformComp!.contentSize; + const contentSize = content._getUITransformComp()!.contentSize; + const scrollViewSize = this._scrollView.node._getUITransformComp()!.contentSize; + const barSize = this.node._getUITransformComp()!.contentSize; if (this._conditionalDisableScrollBar(contentSize, scrollViewSize)) { return; @@ -322,8 +322,8 @@ export class ScrollBar extends Component { if (this._scrollView) { const content = this._scrollView.content; if (content) { - const contentSize = content._uiProps.uiTransformComp!.contentSize; - const scrollViewSize = this._scrollView.node._uiProps.uiTransformComp!.contentSize; + const contentSize = content._getUITransformComp()!.contentSize; + const scrollViewSize = this._scrollView.node._getUITransformComp()!.contentSize; if (this._conditionalDisableScrollBar(contentSize, scrollViewSize)) { return; } @@ -351,8 +351,8 @@ export class ScrollBar extends Component { } protected _convertToScrollViewSpace (out: Vec2, content: Node): void { - const scrollTrans = this._scrollView && this._scrollView.node._uiProps.uiTransformComp; - const contentTrans = content._uiProps.uiTransformComp; + const scrollTrans = this._scrollView && this._scrollView.node._getUITransformComp(); + const contentTrans = content._getUITransformComp(); if (!scrollTrans || !contentTrans) { out.set(Vec2.ZERO); } else { @@ -394,18 +394,18 @@ export class ScrollBar extends Component { } protected _fixupHandlerPosition (out: Vec3): void { - const uiTrans = this.node._uiProps.uiTransformComp!; + const uiTrans = this.node._getUITransformComp()!; const barSize = uiTrans.contentSize; const barAnchor = uiTrans.anchorPoint; - const handleSize = this.handle!.node._uiProps.uiTransformComp!.contentSize; + const handleSize = this.handle!.node._getUITransformComp()!.contentSize; const handleParent = this.handle!.node.parent!; Vec3.set(_tempPos_1, -barSize.width * barAnchor.x, -barSize.height * barAnchor.y, 0); - const leftBottomWorldPosition = this.node._uiProps.uiTransformComp!.convertToWorldSpaceAR(_tempPos_1, _tempPos_2); + const leftBottomWorldPosition = this.node._getUITransformComp()!.convertToWorldSpaceAR(_tempPos_1, _tempPos_2); const fixupPosition = out; fixupPosition.set(0, 0, 0); - handleParent._uiProps.uiTransformComp!.convertToNodeSpaceAR(leftBottomWorldPosition, fixupPosition); + handleParent._getUITransformComp()!.convertToNodeSpaceAR(leftBottomWorldPosition, fixupPosition); if (this.direction === ScrollBarDirection.HORIZONTAL) { fixupPosition.set(fixupPosition.x, fixupPosition.y + (barSize.height - handleSize.height) / 2, fixupPosition.z); @@ -468,7 +468,7 @@ export class ScrollBar extends Component { protected _updateLength (length: number): void { if (this._handle) { const handleNode = this._handle.node; - const handleTrans = handleNode._uiProps.uiTransformComp!; + const handleTrans = handleNode._getUITransformComp()!; const handleNodeSize = handleTrans.contentSize; const anchor = handleTrans.anchorPoint; if (anchor.x !== defaultAnchor.x || anchor.y !== defaultAnchor.y) { diff --git a/cocos/ui/scroll-view.ts b/cocos/ui/scroll-view.ts index 1e3428b1c3b..af9aa960fb5 100644 --- a/cocos/ui/scroll-view.ts +++ b/cocos/ui/scroll-view.ts @@ -304,7 +304,7 @@ export class ScrollView extends ViewGroup { if (this._content === value) { return; } - const viewTrans = value && value.parent && value.parent._uiProps.uiTransformComp; + const viewTrans = value && value.parent && value.parent._getUITransformComp(); if (value && (!value || !viewTrans)) { logID(4302); return; @@ -435,7 +435,7 @@ export class ScrollView extends ViewGroup { if (!parent) { return null; } - return parent._uiProps.uiTransformComp; + return parent._getUITransformComp(); } protected _autoScrolling = false; @@ -712,7 +712,7 @@ export class ScrollView extends ViewGroup { if (!this._content || !this.view) { return Vec2.ZERO; } - const contentSize = this._content._uiProps.uiTransformComp!.contentSize; + const contentSize = this._content._getUITransformComp()!.contentSize; let horizontalMaximizeOffset = contentSize.width - this.view.width; let verticalMaximizeOffset = contentSize.height - this.view.height; horizontalMaximizeOffset = horizontalMaximizeOffset >= 0 ? horizontalMaximizeOffset : 0; @@ -1199,7 +1199,7 @@ export class ScrollView extends ViewGroup { const targetDelta = deltaMove.clone(); targetDelta.normalize(); if (this._content && this.view) { - const contentSize = this._content._uiProps.uiTransformComp!.contentSize; + const contentSize = this._content._getUITransformComp()!.contentSize; const scrollViewSize = this.view.contentSize; const totalMoveWidth = contentSize.width - scrollViewSize.width; @@ -1316,7 +1316,7 @@ export class ScrollView extends ViewGroup { return -1; } const contentPos = this._getContentPosition(); - const uiTrans = this._content._uiProps.uiTransformComp!; + const uiTrans = this._content._getUITransformComp()!; return contentPos.x - uiTrans.anchorX * uiTrans.width; } @@ -1324,7 +1324,7 @@ export class ScrollView extends ViewGroup { if (!this._content) { return -1; } - const uiTrans = this._content._uiProps.uiTransformComp!; + const uiTrans = this._content._getUITransformComp()!; return this._getContentLeftBoundary() + uiTrans.width; } @@ -1332,7 +1332,7 @@ export class ScrollView extends ViewGroup { if (!this._content) { return -1; } - const uiTrans = this._content._uiProps.uiTransformComp!; + const uiTrans = this._content._getUITransformComp()!; return this._getContentBottomBoundary() + uiTrans.height; } @@ -1341,7 +1341,7 @@ export class ScrollView extends ViewGroup { return -1; } const contentPos = this._getContentPosition(); - const uiTrans = this._content._uiProps.uiTransformComp!; + const uiTrans = this._content._getUITransformComp()!; return contentPos.y - uiTrans.anchorY * uiTrans.height; } @@ -1465,7 +1465,7 @@ export class ScrollView extends ViewGroup { return; } const viewTrans = self.view; - const uiTrans = self._content._uiProps.uiTransformComp!; + const uiTrans = self._content._getUITransformComp()!; const verticalScrollBar = self._verticalScrollBar; if (verticalScrollBar && verticalScrollBar.isValid) { @@ -1520,7 +1520,7 @@ export class ScrollView extends ViewGroup { } protected _getLocalAxisAlignDelta (out: Vec3, touch: Touch): void { - const uiTransformComp = this.node._uiProps.uiTransformComp; + const uiTransformComp = this.node._getUITransformComp(); if (uiTransformComp) { touch.getUILocation(_tempVec2); @@ -1555,7 +1555,7 @@ export class ScrollView extends ViewGroup { let verticalScrollEventType: ScrollViewEventType = ScrollViewEventType.NONE; let horizontalScrollEventType: ScrollViewEventType = ScrollViewEventType.NONE; if (self._content) { - const { anchorX, anchorY, width, height } = self._content._uiProps.uiTransformComp!; + const { anchorX, anchorY, width, height } = self._content._getUITransformComp()!; const pos = self._content.position || Vec3.ZERO; if (self.vertical) { @@ -1628,7 +1628,7 @@ export class ScrollView extends ViewGroup { protected _clampDelta (out: Vec3): void { if (this._content && this.view) { const scrollViewSize = this.view.contentSize; - const uiTrans = this._content._uiProps.uiTransformComp!; + const uiTrans = this._content._getUITransformComp()!; if (uiTrans.width < scrollViewSize.width) { out.x = 0; } @@ -1848,7 +1848,7 @@ export class ScrollView extends ViewGroup { const moveDelta = new Vec3(); if (self._content && self.view) { let totalScrollDelta = 0; - const uiTrans = self._content._uiProps.uiTransformComp!; + const uiTrans = self._content._getUITransformComp()!; const contentSize = uiTrans.contentSize; const scrollSize = self.view.contentSize; if (applyToHorizontal) { @@ -1878,7 +1878,7 @@ export class ScrollView extends ViewGroup { // 是否限制在上视区上边 if (self._content) { - const uiTrans = self._content._uiProps.uiTransformComp!; + const uiTrans = self._content._getUITransformComp()!; const contentSize = uiTrans.contentSize; if (contentSize.height < scrollViewSize.height) { totalScrollDelta = contentSize.height - scrollViewSize.height; diff --git a/cocos/ui/slider.ts b/cocos/ui/slider.ts index 6238f233eac..4db8eed4275 100644 --- a/cocos/ui/slider.ts +++ b/cocos/ui/slider.ts @@ -218,7 +218,7 @@ export class Slider extends Component { } protected _onHandleDragStart (event?: EventTouch): void { - if (!event || !this._handle || !this._handle.node._uiProps.uiTransformComp) { + if (!event || !this._handle || !this._handle.node._getUITransformComp()) { return; } @@ -226,7 +226,7 @@ export class Slider extends Component { this._touchHandle = true; const touhPos = event.touch!.getUILocation(); Vec3.set(this._touchPos, touhPos.x, touhPos.y, 0); - this._handle.node._uiProps.uiTransformComp.convertToNodeSpaceAR(this._touchPos, this._offset); + this._handle.node._getUITransformComp()!.convertToNodeSpaceAR(this._touchPos, this._offset); event.propagationStopped = true; } @@ -287,7 +287,7 @@ export class Slider extends Component { const touchPos = touch.getUILocation(); Vec3.set(this._touchPos, touchPos.x, touchPos.y, 0); - const uiTrans = this.node._uiProps.uiTransformComp!; + const uiTrans = this.node._getUITransformComp()!; const localTouchPos = uiTrans.convertToNodeSpaceAR(this._touchPos, _tempPos); if (this.direction === Direction.Horizontal as number) { this.progress = clamp01(0.5 + (localTouchPos.x - this._offset.x) / uiTrans.width); @@ -301,7 +301,7 @@ export class Slider extends Component { return; } this._handleLocalPos.set(this._handle.node.position); - const uiTrans = this.node._uiProps.uiTransformComp!; + const uiTrans = this.node._getUITransformComp()!; if (this._direction === Direction.Horizontal) { this._handleLocalPos.x = -uiTrans.width * uiTrans.anchorX + this.progress * uiTrans.width; } else { @@ -312,7 +312,7 @@ export class Slider extends Component { } private _changeLayout (): void { - const uiTrans = this.node._uiProps.uiTransformComp!; + const uiTrans = this.node._getUITransformComp()!; const contentSize = uiTrans.contentSize; uiTrans.setContentSize(contentSize.height, contentSize.width); if (this._handle) { @@ -329,7 +329,7 @@ export class Slider extends Component { protected _xrHandleProgress (point: Vec3): void { if (!this._touchHandle) { - const uiTrans = this.node._uiProps.uiTransformComp!; + const uiTrans = this.node._getUITransformComp()!; uiTrans.convertToNodeSpaceAR(point, _tempPos); if (this.direction === Direction.Horizontal as number) { this.progress = clamp01(0.5 + (_tempPos.x - this.node.position.x) / uiTrans.width); diff --git a/cocos/ui/widget-manager.ts b/cocos/ui/widget-manager.ts index 9eb65063a9b..cb4085f5974 100644 --- a/cocos/ui/widget-manager.ts +++ b/cocos/ui/widget-manager.ts @@ -66,7 +66,7 @@ function align (node: Node, widget: Widget): void { const isRoot = useGlobal; node.getPosition(_tempPos); - const uiTrans = node._uiProps.uiTransformComp!; + const uiTrans = node._getUITransformComp()!; let x = _tempPos.x; let y = _tempPos.y; const anchor = uiTrans.anchorPoint; @@ -343,9 +343,9 @@ export const widgetManager = cclegacy._widgetManager = { return; } - const parentTrans = widgetParent._uiProps && widgetParent._uiProps.uiTransformComp; + const parentTrans = widgetParent._uiProps && widgetParent._getUITransformComp(); const parentAP = parentTrans ? parentTrans.anchorPoint : _defaultAnchor; - const trans = widgetNode._uiProps.uiTransformComp!; + const trans = widgetNode._getUITransformComp()!; const matchSize = getReadonlyNodeSize(widgetParent); const myAP = trans.anchorPoint; const pos = widgetNode.position; diff --git a/cocos/ui/widget.ts b/cocos/ui/widget.ts index 20fce31f1f0..15c4147e294 100644 --- a/cocos/ui/widget.ts +++ b/cocos/ui/widget.ts @@ -51,6 +51,7 @@ export function getReadonlyNodeSize (parent: Node | Scene): { height: number; init(visibleRect_: Rect): void; } | Readonly { + const parentUITransform = parent._getUITransformComp(); if (parent instanceof Scene) { if (EDITOR) { // const canvasComp = parent.getComponentInChildren(Canvas); @@ -62,8 +63,8 @@ export function getReadonlyNodeSize (parent: Node | Scene): { } return visibleRect; - } else if (parent._uiProps.uiTransformComp) { - return parent._uiProps.uiTransformComp.contentSize; + } else if (parentUITransform) { + return parentUITransform.contentSize; } else { return Size.ZERO; } @@ -837,7 +838,7 @@ export class Widget extends Component { public onEnable (): void { this.node.getPosition(this._lastPos); - this._lastSize.set(this.node._uiProps.uiTransformComp!.contentSize); + this._lastSize.set(this.node._getUITransformComp()!.contentSize); cclegacy._widgetManager.add(this); this._hadAlignOnce = false; this._registerEvent(); @@ -975,7 +976,7 @@ export class Widget extends Component { return; } const isHorizontal = (flag & LEFT_RIGHT) > 0; - const trans = this.node._uiProps.uiTransformComp!; + const trans = this.node._getUITransformComp()!; if (isAlign) { this._alignFlags |= flag;