mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-21 08:02:39 +08:00
node event TRS remove (#5750)
* node event TRS remove * transformBit rename & deprecated * notice update
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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',
|
||||
},
|
||||
]);
|
||||
@@ -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
|
||||
|
||||
@@ -33,4 +33,6 @@ export * from './input-manager';
|
||||
export * from './system-event';
|
||||
export * from './events';
|
||||
export * from './touch';
|
||||
export * from './event-enum';
|
||||
export * from './event-enum';
|
||||
|
||||
import './deprecated';
|
||||
|
||||
@@ -36,4 +36,4 @@ export { find } from './find';
|
||||
export { PrivateNode } from './private-node';
|
||||
export { default as NodeActivator } from './node-activator';
|
||||
|
||||
import './deprecated';
|
||||
import './deprecated';
|
||||
@@ -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,
|
||||
}
|
||||
|
||||
@@ -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>) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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<TransformDirtyBit>;
|
||||
hasChangedFlags: Readonly<TransformBit>;
|
||||
|
||||
/**
|
||||
* @zh
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user