diff --git a/cocos/core/3d/framework/model-component.ts b/cocos/core/3d/framework/model-component.ts index 000d880839..5014652bd4 100644 --- a/cocos/core/3d/framework/model-component.ts +++ b/cocos/core/3d/framework/model-component.ts @@ -30,7 +30,7 @@ import { Material, Mesh } from '../../assets'; import { ccclass, executeInEditMode, executionOrder, menu, property } from '../../data/class-decorator'; import { Model } from '../../renderer/scene/model'; -import { TransformDirtyBit } from '../../scene-graph/node-enum'; +import { TransformBit } from '../../scene-graph/node-enum'; import { Enum } from '../../value-types'; import { builtinResMgr } from '../builtin'; import { RenderableComponent } from './renderable-component'; @@ -249,7 +249,7 @@ export class ModelComponent extends RenderableComponent { if (!this._mesh || !this._model) { return; } - this.node.hasChangedFlags = this._model.transform.hasChangedFlags = TransformDirtyBit.POSITION; + this.node.hasChangedFlags = this._model.transform.hasChangedFlags = TransformBit.POSITION; this._model.isDynamicBatching = this._enableDynamicBatching; // should pass this in before create PSO const meshCount = this._mesh ? this._mesh.subMeshCount : 0; for (let i = 0; i < meshCount; ++i) { diff --git a/cocos/core/components/ui-base/ui-render-component.ts b/cocos/core/components/ui-base/ui-render-component.ts index 3b643e20b1..0c430bf900 100644 --- a/cocos/core/components/ui-base/ui-render-component.ts +++ b/cocos/core/components/ui-base/ui-render-component.ts @@ -45,6 +45,7 @@ import { RenderableComponent } from '../../../core/3d/framework/renderable-compo import { IAssembler, IAssemblerManager } from '../../renderer/ui/base'; import { UIComponent } from './ui-component'; import { UITransformComponent } from './ui-transfrom-component'; +import { TransformBit } from '../../scene-graph/node-enum'; // hack ccenum(GFXBlendFactor); @@ -387,7 +388,7 @@ export class UIRenderComponent extends UIComponent { } // pos, rot, scale changed - protected _nodeStateChange (type: SystemEventType){ + protected _nodeStateChange (type: TransformBit){ if (this._renderData) { this.markForUpdateRenderData(); } diff --git a/cocos/core/platform/SubContextView.ts b/cocos/core/platform/SubContextView.ts index 83b17658f6..8286767c3e 100644 --- a/cocos/core/platform/SubContextView.ts +++ b/cocos/core/platform/SubContextView.ts @@ -207,13 +207,11 @@ export class SubContextView extends Component { private _registerNodeEvent () { this.node.on(Node.EventType.TRANSFORM_CHANGED, this.updateSubContextViewport, this); - this.node.on(Node.EventType.SCALE_PART, this.updateSubContextViewport, this); this.node.on(Node.EventType.SIZE_CHANGED, this.updateSubContextViewport, this); } private _unregisterNodeEvent () { this.node.off(Node.EventType.TRANSFORM_CHANGED, this.updateSubContextViewport, this); - this.node.off(Node.EventType.SCALE_PART, this.updateSubContextViewport, this); this.node.off(Node.EventType.SIZE_CHANGED, this.updateSubContextViewport, this); } diff --git a/cocos/core/platform/event-manager/deprecated.ts b/cocos/core/platform/event-manager/deprecated.ts new file mode 100644 index 0000000000..fda34c3ce9 --- /dev/null +++ b/cocos/core/platform/event-manager/deprecated.ts @@ -0,0 +1,17 @@ +import { replaceProperty } from '../../utils'; +import { SystemEventType } from './event-enum'; + +replaceProperty(SystemEventType, 'Node.EventType', [ + { + name: 'POSITION_PART', + newName: 'TRANSFORM_CHANGED', + }, + { + name: 'ROTATION_PART', + newName: 'TRANSFORM_CHANGED', + }, + { + name: 'SCALE_PART', + newName: 'TRANSFORM_CHANGED', + }, +]); diff --git a/cocos/core/platform/event-manager/event-enum.ts b/cocos/core/platform/event-manager/event-enum.ts index 696fa97956..858b8c1308 100644 --- a/cocos/core/platform/event-manager/event-enum.ts +++ b/cocos/core/platform/event-manager/event-enum.ts @@ -120,37 +120,21 @@ export enum SystemEventType { /** * @en - * The event type for position, rotation, scale changed. + * The event type for position, rotation, scale changed.Use the type parameter as [[Node.TransformBit]] to check which part is changed * * @zh - * 节点改变位置、旋转或缩放事件. + * 节点改变位置、旋转或缩放事件。如果具体需要判断是哪一个事件,可通过判断回调的第一个参数类型是 [[Node.TransformBit]] 中的哪一个来获取 + * @example + * ``` + * this.node.on(Node.EventType.TRANSFORM_CHANGED, (type)=>{ + * if (type & Node.TransformBit.POSITION) { + * //... + * } + * }, this); + * ``` */ TRANSFORM_CHANGED = 'transform-changed', - /** - * @en - * The event type for position changed. - * - * @zh - * 节点位置改变事件 - */ - POSITION_PART = 'position-part', - - /** - * @en - * The event type for rotation changed. - * - * @zh - * 节点旋转事件 - */ - ROTATION_PART = 'rotation-part', - - /** - * @en The event type for scale changed. - * @zh 节点缩放事件 - */ - SCALE_PART = 'scale-part', - /** * @en The event type for press the devicemotion event, you can use its value directly: 'devicemotion'. * @zh diff --git a/cocos/core/platform/event-manager/index.ts b/cocos/core/platform/event-manager/index.ts index 5b15441d6f..4b51b4bef9 100644 --- a/cocos/core/platform/event-manager/index.ts +++ b/cocos/core/platform/event-manager/index.ts @@ -33,4 +33,6 @@ export * from './input-manager'; export * from './system-event'; export * from './events'; export * from './touch'; -export * from './event-enum'; \ No newline at end of file +export * from './event-enum'; + +import './deprecated'; diff --git a/cocos/core/scene-graph/index.ts b/cocos/core/scene-graph/index.ts index b62179a5b8..08e1be2929 100644 --- a/cocos/core/scene-graph/index.ts +++ b/cocos/core/scene-graph/index.ts @@ -36,4 +36,4 @@ export { find } from './find'; export { PrivateNode } from './private-node'; export { default as NodeActivator } from './node-activator'; -import './deprecated'; \ No newline at end of file +import './deprecated'; \ No newline at end of file diff --git a/cocos/core/scene-graph/node-enum.ts b/cocos/core/scene-graph/node-enum.ts index ee11f1dcba..2287dbc4f9 100644 --- a/cocos/core/scene-graph/node-enum.ts +++ b/cocos/core/scene-graph/node-enum.ts @@ -27,17 +27,43 @@ * @category scene-graph */ +import { ccenum } from '../value-types/enum'; + export enum NodeSpace { LOCAL, WORLD, } -export enum TransformDirtyBit { +export enum TransformBit { + /** + * @zh + * 无改变 + */ NONE = 0, + /** + * @zh + * 节点位置改变 + */ POSITION = (1 << 0), + /** + * @zh + * 节点旋转 + */ ROTATION = (1 << 1), + /** + * @zh + * 节点缩放 + */ SCALE = (1 << 2), - RS = TransformDirtyBit.ROTATION | TransformDirtyBit.SCALE, - TRS = TransformDirtyBit.POSITION | TransformDirtyBit.ROTATION | TransformDirtyBit.SCALE, - TRS_MASK = ~TransformDirtyBit.TRS, + /** + * @zh + * 节点旋转及缩放 + */ + RS = TransformBit.ROTATION | TransformBit.SCALE, + /** + * @zh + * 节点平移,旋转及缩放 + */ + TRS = TransformBit.POSITION | TransformBit.ROTATION | TransformBit.SCALE, + TRS_MASK = ~TransformBit.TRS, } diff --git a/cocos/core/scene-graph/node.ts b/cocos/core/scene-graph/node.ts index 4cd580d3ea..8a27cab3ee 100644 --- a/cocos/core/scene-graph/node.ts +++ b/cocos/core/scene-graph/node.ts @@ -35,7 +35,7 @@ import { eventManager } from '../platform/event-manager/event-manager'; import { INode } from '../utils/interfaces'; import { BaseNode, TRANFORM_ON } from './base-node'; import { Layers } from './layers'; -import { NodeSpace, TransformDirtyBit } from './node-enum'; +import { NodeSpace, TransformBit } from './node-enum'; const v3_a = new Vec3(); const q_a = new Quat(); @@ -70,9 +70,15 @@ export class Node extends BaseNode implements INode { public static NodeSpace = NodeSpace; /** * @zh - * 节点变换脏更新的具体部分 + * 节点变换更新的具体部分 + * @deprecated 请使用 [Node.TransformBit] */ - public static TransformDirtyBit = TransformDirtyBit; + public static TransformDirtyBit = TransformBit; + /** + * @zh + * 节点变换更新的具体部分,可用于判断 TRANSFORM_CHANGED 事件的具体类型 + */ + public static TransformBit = TransformBit; // UI 部分的脏数据 public _uiTransfromComp: UITransformComponent | null = null; @@ -99,7 +105,7 @@ export class Node extends BaseNode implements INode { @property protected _euler = new Vec3(); - protected _dirtyFlags = TransformDirtyBit.NONE; // does the world transform need to update? + protected _dirtyFlags = TransformBit.NONE; // does the world transform need to update? protected _eulerDirty = false; /** @@ -208,12 +214,10 @@ export class Node extends BaseNode implements INode { */ public set matrix (val: Readonly) { Mat4.toRTS(val, this._lrot, this._lpos, this._lscale); - this.invalidateChildren(TransformDirtyBit.TRS); + this.invalidateChildren(TransformBit.TRS); this._eulerDirty = true; if (this._eventMask & TRANFORM_ON) { - this.emit(SystemEventType.TRANSFORM_CHANGED, SystemEventType.POSITION_PART); - this.emit(SystemEventType.TRANSFORM_CHANGED, SystemEventType.ROTATION_PART); - this.emit(SystemEventType.TRANSFORM_CHANGED, SystemEventType.SCALE_PART); + this.emit(SystemEventType.TRANSFORM_CHANGED, TransformBit.TRS); } } @@ -339,13 +343,13 @@ export class Node extends BaseNode implements INode { this._eulerDirty = true; } - this.invalidateChildren(TransformDirtyBit.TRS); + this.invalidateChildren(TransformBit.TRS); } public _onBatchCreated () { super._onBatchCreated(); - bookOfChange.set(this._id, TransformDirtyBit.TRS); - this._dirtyFlags = TransformDirtyBit.TRS; + bookOfChange.set(this._id, TransformBit.TRS); + this._dirtyFlags = TransformBit.TRS; const len = this._children.length; for (let i = 0; i < len; ++i) { this._children[i]._onBatchCreated(); @@ -393,9 +397,9 @@ export class Node extends BaseNode implements INode { } } - this.invalidateChildren(TransformDirtyBit.POSITION); + this.invalidateChildren(TransformBit.POSITION); if (this._eventMask & TRANFORM_ON) { - this.emit(SystemEventType.TRANSFORM_CHANGED, SystemEventType.POSITION_PART); + this.emit(SystemEventType.TRANSFORM_CHANGED, TransformBit.POSITION); } } @@ -420,9 +424,9 @@ export class Node extends BaseNode implements INode { } this._eulerDirty = true; - this.invalidateChildren(TransformDirtyBit.ROTATION); + this.invalidateChildren(TransformBit.ROTATION); if (this._eventMask & TRANFORM_ON) { - this.emit(SystemEventType.TRANSFORM_CHANGED, SystemEventType.ROTATION_PART); + this.emit(SystemEventType.TRANSFORM_CHANGED, TransformBit.ROTATION); } } @@ -451,11 +455,11 @@ export class Node extends BaseNode implements INode { * @zh * 递归标记节点世界变换为 dirty */ - public invalidateChildren (dirtyBit: TransformDirtyBit) { + public invalidateChildren (dirtyBit: TransformBit) { if ((this._dirtyFlags & this.hasChangedFlags & dirtyBit) === dirtyBit) { return; } this._dirtyFlags |= dirtyBit; bookOfChange.set(this._id, this.hasChangedFlags | dirtyBit); - dirtyBit |= TransformDirtyBit.POSITION; + dirtyBit |= TransformBit.POSITION; const len = this._children.length; for (let i = 0; i < len; ++i) { this._children[i].invalidateChildren(dirtyBit); @@ -482,16 +486,16 @@ export class Node extends BaseNode implements INode { child = array_a[--i]; dirtyBits |= child._dirtyFlags; if (cur) { - if (dirtyBits & TransformDirtyBit.POSITION) { + if (dirtyBits & TransformBit.POSITION) { Vec3.transformMat4(child._pos, child._lpos, cur._mat); child._mat.m12 = child._pos.x; child._mat.m13 = child._pos.y; child._mat.m14 = child._pos.z; } - if (dirtyBits & TransformDirtyBit.RS) { + if (dirtyBits & TransformBit.RS) { Mat4.fromRTS(child._mat, child._lrot, child._lpos, child._lscale); Mat4.multiply(child._mat, cur._mat, child._mat); - if (dirtyBits & TransformDirtyBit.ROTATION) { + if (dirtyBits & TransformBit.ROTATION) { Quat.multiply(child._rot, cur._rot, child._lrot); } Mat3.fromQuat(m3_1, Quat.conjugate(qt_1, child._rot)); @@ -501,14 +505,14 @@ export class Node extends BaseNode implements INode { child._scale.z = m3_1.m08; } } else { - if (dirtyBits & TransformDirtyBit.POSITION) { + if (dirtyBits & TransformBit.POSITION) { Vec3.copy(child._pos, child._lpos); child._mat.m12 = child._pos.x; child._mat.m13 = child._pos.y; child._mat.m14 = child._pos.z; } - if (dirtyBits & TransformDirtyBit.RS) { - if (dirtyBits & TransformDirtyBit.ROTATION) { + if (dirtyBits & TransformBit.RS) { + if (dirtyBits & TransformBit.ROTATION) { Quat.copy(child._rot, child._lrot); } else { Vec3.copy(child._scale, child._lscale); @@ -516,7 +520,7 @@ export class Node extends BaseNode implements INode { Mat4.fromRTS(child._mat, child._rot, child._pos, child._scale); } } - child._dirtyFlags = TransformDirtyBit.NONE; + child._dirtyFlags = TransformBit.NONE; cur = child; } } @@ -549,9 +553,9 @@ export class Node extends BaseNode implements INode { Vec3.set(this._lpos, val as number, y, z); } - this.invalidateChildren(TransformDirtyBit.POSITION); + this.invalidateChildren(TransformBit.POSITION); if (this._eventMask & TRANFORM_ON) { - this.emit(SystemEventType.TRANSFORM_CHANGED, SystemEventType.POSITION_PART); + this.emit(SystemEventType.TRANSFORM_CHANGED, TransformBit.POSITION); } } @@ -593,9 +597,9 @@ export class Node extends BaseNode implements INode { } this._eulerDirty = true; - this.invalidateChildren(TransformDirtyBit.ROTATION); + this.invalidateChildren(TransformBit.ROTATION); if (this._eventMask & TRANFORM_ON) { - this.emit(SystemEventType.TRANSFORM_CHANGED, SystemEventType.ROTATION_PART); + this.emit(SystemEventType.TRANSFORM_CHANGED, TransformBit.ROTATION); } } @@ -611,9 +615,9 @@ export class Node extends BaseNode implements INode { Quat.fromEuler(this._lrot, x, y, z); this._eulerDirty = false; - this.invalidateChildren(TransformDirtyBit.ROTATION); + this.invalidateChildren(TransformBit.ROTATION); if (this._eventMask & TRANFORM_ON) { - this.emit(SystemEventType.TRANSFORM_CHANGED, SystemEventType.ROTATION_PART); + this.emit(SystemEventType.TRANSFORM_CHANGED, TransformBit.ROTATION); } } @@ -653,9 +657,9 @@ export class Node extends BaseNode implements INode { Vec3.set(this._lscale, val as number, y, z); } - this.invalidateChildren(TransformDirtyBit.SCALE); + this.invalidateChildren(TransformBit.SCALE); if (this._eventMask & TRANFORM_ON) { - this.emit(SystemEventType.TRANSFORM_CHANGED, SystemEventType.SCALE_PART); + this.emit(SystemEventType.TRANSFORM_CHANGED, TransformBit.SCALE); } } @@ -723,9 +727,9 @@ export class Node extends BaseNode implements INode { Vec3.copy(local, this._pos); } - this.invalidateChildren(TransformDirtyBit.POSITION); + this.invalidateChildren(TransformBit.POSITION); if (this._eventMask & TRANFORM_ON) { - this.emit(SystemEventType.TRANSFORM_CHANGED, SystemEventType.POSITION_PART); + this.emit(SystemEventType.TRANSFORM_CHANGED, TransformBit.POSITION); } } @@ -774,9 +778,9 @@ export class Node extends BaseNode implements INode { } this._eulerDirty = true; - this.invalidateChildren(TransformDirtyBit.ROTATION); + this.invalidateChildren(TransformBit.ROTATION); if (this._eventMask & TRANFORM_ON) { - this.emit(SystemEventType.TRANSFORM_CHANGED, SystemEventType.ROTATION_PART); + this.emit(SystemEventType.TRANSFORM_CHANGED, TransformBit.ROTATION); } } @@ -797,9 +801,9 @@ export class Node extends BaseNode implements INode { } this._eulerDirty = true; - this.invalidateChildren(TransformDirtyBit.ROTATION); + this.invalidateChildren(TransformBit.ROTATION); if (this._eventMask & TRANFORM_ON) { - this.emit(SystemEventType.TRANSFORM_CHANGED, SystemEventType.ROTATION_PART); + this.emit(SystemEventType.TRANSFORM_CHANGED, TransformBit.ROTATION); } } @@ -855,9 +859,9 @@ export class Node extends BaseNode implements INode { Vec3.copy(this._lscale, this._scale); } - this.invalidateChildren(TransformDirtyBit.SCALE); + this.invalidateChildren(TransformBit.SCALE); if (this._eventMask & TRANFORM_ON) { - this.emit(SystemEventType.TRANSFORM_CHANGED, SystemEventType.SCALE_PART); + this.emit(SystemEventType.TRANSFORM_CHANGED, TransformBit.SCALE); } } diff --git a/cocos/core/utils/interfaces.ts b/cocos/core/utils/interfaces.ts index a4199cd5e8..1444692ef4 100644 --- a/cocos/core/utils/interfaces.ts +++ b/cocos/core/utils/interfaces.ts @@ -27,7 +27,7 @@ import { Component } from '../components/component'; import { Event } from '../event'; import { Mat4, Quat, Size, Vec2, Vec3 } from '../math'; import { SystemEventType } from '../platform/event-manager/event-enum'; -import { NodeSpace, TransformDirtyBit } from '../scene-graph/node-enum'; +import { NodeSpace, TransformBit } from '../scene-graph/node-enum'; import { NodeEventProcessor } from '../scene-graph/node-event-processor'; import { Scene } from '../scene-graph/scene'; @@ -446,7 +446,7 @@ export interface INode extends IBaseNode { * @zh * 这个节点的空间变换信息在当前帧内是否有变过? */ - hasChangedFlags: Readonly; + hasChangedFlags: Readonly; /** * @zh diff --git a/cocos/physics/components/detail/physics-based-component.ts b/cocos/physics/components/detail/physics-based-component.ts index 4abca0422b..1fe747b562 100644 --- a/cocos/physics/components/detail/physics-based-component.ts +++ b/cocos/physics/components/detail/physics-based-component.ts @@ -11,7 +11,7 @@ import { AfterStepCallback, BeforeStepCallback, PhysicsWorldBase, RigidBodyBase import { createRigidBody } from '../../instance'; import { ERigidBodyType, ETransformSource } from '../../physic-enum'; import { INode } from '../../../core/utils/interfaces'; -import { TransformDirtyBit } from '../../../core/scene-graph/node-enum'; +import { TransformBit } from '../../../core/scene-graph/node-enum'; import { error } from '../../../core/platform/debug'; import { PhysicsSystem } from '../physics-system'; @@ -376,7 +376,7 @@ class SharedRigidBody { // 开始物理计算之前,用户脚本或引擎功能有可能改变节点的Transform,所以需要判断并进行更新 if (this._node.hasChangedFlags) { // scale 进行单独判断,因为目前的物理系统处理后不会改变scale的属性 - if (this._node.hasChangedFlags & TransformDirtyBit.SCALE) { + if (this._node.hasChangedFlags & TransformBit.SCALE) { this._body.scaleAllShapes(this._node.worldScale); } this._syncPhysWithScene(this._node); diff --git a/cocos/ui/components/layout-component.ts b/cocos/ui/components/layout-component.ts index a2ef9d99d9..d7a0ddd9f4 100644 --- a/cocos/ui/components/layout-component.ts +++ b/cocos/ui/components/layout-component.ts @@ -36,6 +36,7 @@ import { UITransformComponent } from '../../core/components/ui-base/ui-transfrom import { SystemEventType } from '../../core/platform/event-manager/event-enum'; import { INode } from '../../core/utils/interfaces'; import { director, Director } from '../../core/director'; +import { TransformBit } from '../../core/scene-graph/node-enum'; const NodeEvent = SystemEventType; /** * @zh @@ -540,7 +541,7 @@ export class LayoutComponent extends Component { private _addChildrenEventListeners () { const children = this.node.children; for (const child of children) { - child.on(NodeEvent.SCALE_PART, this._doScaleDirty, this); + child.on(NodeEvent.TRANSFORM_CHANGED, this._doScaleDirty, this); child.on(NodeEvent.SIZE_CHANGED, this._doLayoutDirty, this); child.on(NodeEvent.TRANSFORM_CHANGED, this._transformDirty, this); child.on(NodeEvent.ANCHOR_CHANGED, this._doLayoutDirty, this); @@ -551,7 +552,7 @@ export class LayoutComponent extends Component { private _removeChildrenEventListeners () { const children = this.node.children; for (const child of children) { - child.off(NodeEvent.SCALE_PART, this._doScaleDirty, this); + child.off(NodeEvent.TRANSFORM_CHANGED, this._doScaleDirty, this); child.off(NodeEvent.SIZE_CHANGED, this._doLayoutDirty, this); child.off(NodeEvent.TRANSFORM_CHANGED, this._transformDirty, this); child.off(NodeEvent.ANCHOR_CHANGED, this._doLayoutDirty, this); @@ -560,7 +561,7 @@ export class LayoutComponent extends Component { } private _childAdded (child: INode) { - child.on(NodeEvent.SCALE_PART, this._doScaleDirty, this); + child.on(NodeEvent.TRANSFORM_CHANGED, this._doScaleDirty, this); child.on(NodeEvent.SIZE_CHANGED, this._doLayoutDirty, this); child.on(NodeEvent.TRANSFORM_CHANGED, this._transformDirty, this); child.on(NodeEvent.ANCHOR_CHANGED, this._doLayoutDirty, this); @@ -570,7 +571,7 @@ export class LayoutComponent extends Component { } private _childRemoved (child: INode) { - child.off(NodeEvent.SCALE_PART, this._doScaleDirty, this); + child.off(NodeEvent.TRANSFORM_CHANGED, this._doScaleDirty, this); child.off(NodeEvent.SIZE_CHANGED, this._doLayoutDirty, this); child.off(NodeEvent.TRANSFORM_CHANGED, this._transformDirty, this); child.off(NodeEvent.ANCHOR_CHANGED, this._doLayoutDirty, this); @@ -1085,8 +1086,8 @@ export class LayoutComponent extends Component { return this._affectedByScale ? Math.abs(value) : 1; } - private _transformDirty(type: SystemEventType){ - if(type !== SystemEventType.POSITION_PART){ + private _transformDirty (type: TransformBit) { + if (!(type & TransformBit.POSITION)){ return; } @@ -1097,8 +1098,10 @@ export class LayoutComponent extends Component { this._layoutDirty = true; } - private _doScaleDirty () { - this._layoutDirty = this._layoutDirty || this._affectedByScale; + private _doScaleDirty (type: TransformBit) { + if (type & TransformBit.SCALE){ + this._layoutDirty = this._layoutDirty || this._affectedByScale; + } } } diff --git a/cocos/ui/components/mask-component.ts b/cocos/ui/components/mask-component.ts index eaf5ec268e..9649eaf7ff 100644 --- a/cocos/ui/components/mask-component.ts +++ b/cocos/ui/components/mask-component.ts @@ -39,6 +39,7 @@ import { UI } from '../../core/renderer/ui/ui'; import { Node } from '../../core/scene-graph'; import { ccenum } from '../../core/value-types/enum'; import { GraphicsComponent } from './graphics-component'; +import { TransformBit } from '../../core/scene-graph/node-enum'; const _worldMatrix = new Mat4(); const _vec2_temp = new Vec2(); @@ -392,8 +393,8 @@ export class MaskComponent extends UIRenderComponent { render.commitComp(this, null, this._postAssembler!); } - protected _nodeStateChange (type: SystemEventType) { - if (type === SystemEventType.POSITION_PART) { + protected _nodeStateChange (type: TransformBit) { + if (type & TransformBit.POSITION) { return; } diff --git a/cocos/ui/components/scroll-view-component.ts b/cocos/ui/components/scroll-view-component.ts index d3b290fef6..d8ec9f9a54 100644 --- a/cocos/ui/components/scroll-view-component.ts +++ b/cocos/ui/components/scroll-view-component.ts @@ -787,10 +787,9 @@ export class ScrollViewComponent extends ViewGroupComponent { this._registerEvent(); if (this.content) { this.content.on(Node.EventType.SIZE_CHANGED, this._calculateBoundary, this); - this.content.on(Node.EventType.SCALE_PART, this._calculateBoundary, this); + this.content.on(Node.EventType.TRANSFORM_CHANGED, this._calculateBoundary, this); if (this.view!) { - this.view!.on(Node.EventType.POSITION_PART, this._calculateBoundary, this); - this.view!.on(Node.EventType.SCALE_PART, this._calculateBoundary, this); + this.view!.on(Node.EventType.TRANSFORM_CHANGED, this._calculateBoundary, this); this.view!.on(Node.EventType.SIZE_CHANGED, this._calculateBoundary, this); } } @@ -809,10 +808,9 @@ export class ScrollViewComponent extends ViewGroupComponent { this._unregisterEvent(); if (this.content) { this.content.off(Node.EventType.SIZE_CHANGED, this._calculateBoundary, this); - this.content.off(Node.EventType.SCALE_PART, this._calculateBoundary, this); + this.content.off(Node.EventType.TRANSFORM_CHANGED, this._calculateBoundary, this); if (this.view!) { - this.view!.off(Node.EventType.POSITION_PART, this._calculateBoundary, this); - this.view!.off(Node.EventType.SCALE_PART, this._calculateBoundary, this); + this.view!.off(Node.EventType.TRANSFORM_CHANGED, this._calculateBoundary, this); this.view!.off(Node.EventType.SIZE_CHANGED, this._calculateBoundary, this); } } diff --git a/cocos/ui/components/widget-component.ts b/cocos/ui/components/widget-component.ts index 05925ccd75..80d1f5f95c 100644 --- a/cocos/ui/components/widget-component.ts +++ b/cocos/ui/components/widget-component.ts @@ -40,6 +40,7 @@ import { Scene } from '../../core/scene-graph'; import { Node } from '../../core/scene-graph/node'; import { INode } from '../../core/utils/interfaces'; import { ccenum } from '../../core/value-types/enum'; +import { TransformBit } from '../../core/scene-graph/node-enum'; const _zeroVec3 = new Vec3(); @@ -727,8 +728,8 @@ export class WidgetComponent extends Component { this._removeParentEvent(); } - public _adjustWidgetToAllowMovingInEditor (eventType: SystemEventType) { - if (/*!CC_EDITOR ||*/ eventType !== SystemEventType.POSITION_PART) { + public _adjustWidgetToAllowMovingInEditor (eventType: TransformBit) { + if (/*!CC_EDITOR ||*/ !(eventType & TransformBit.POSITION)) { return; }