fix mask event through bug (#8293)

This commit is contained in:
ChiaNing
2021-02-26 14:31:00 +08:00
committed by GitHub
parent 0ae529eb0e
commit 15a4041aa5
3 changed files with 17 additions and 3 deletions
+16 -1
View File
@@ -32,7 +32,7 @@
import { ccclass, help, executionOrder, menu, tooltip, displayOrder, type, visible, override, serializable, range, slide } from 'cc.decorator';
import { InstanceMaterialType, Renderable2D } from '../framework/renderable-2d';
import { clamp, Color, Mat4, Vec2, Vec3 } from '../../core/math';
import { warnID } from '../../core/platform';
import { SystemEventType, warnID } from '../../core/platform';
import { Batcher2D } from '../renderer/batcher-2d';
import { ccenum } from '../../core/value-types/enum';
import { Graphics } from './graphics';
@@ -373,6 +373,8 @@ export class Mask extends Renderable2D {
super.onEnable();
this._updateGraphics();
this._broadcastToNode(this.node);
this.node.on(SystemEventType.CHILD_ADDED, this._addChild, this);
this.node.on(SystemEventType.CHILD_REMOVED, this._removeChild, this);
}
/**
@@ -387,6 +389,8 @@ export class Mask extends Renderable2D {
public onDisable () {
super.onDisable();
this._disableGraphics();
this.node.off(SystemEventType.CHILD_ADDED, this._addChild, this);
this.node.off(SystemEventType.CHILD_REMOVED, this._removeChild, this);
}
public onDestroy () {
@@ -617,6 +621,17 @@ export class Mask extends Renderable2D {
this._broadcastToNode(children[i]);
}
}
// add node.eventProcessor.listener.mask when add to mask
protected _addChild (child) {
this._broadcastToNode(child);
child.walk(() => { child.eventProcessor.reattach(); });
}
// clean node.eventProcessor.listener.mask when remove from mask
protected _removeChild (node) {
node.walk(() => { node.eventProcessor.registerComponentHitList(null); node.eventProcessor.reattach(); });
}
}
legacyCC.Mask = Mask;
@@ -360,7 +360,6 @@ export class NodeEventProcessor {
}
public reattach (): void {
if (!this._comp) return;
if (this.touchListener) {
const mask = this.touchListener.mask = _searchComponentsInParent(this._node as Node, this._comp);
if (this.mouseListener) {
+1 -1
View File
@@ -73,7 +73,7 @@ enum EventType {
@ccclass('cc.EditBox')
@help('i18n:cc.EditBox')
@executionOrder(100)
@executionOrder(110)
@menu('UI/EditBox')
@requireComponent(UITransform)
@executeInEditMode